Problem 10016 with futures contract

 
// Input parameters

input int AtrPeriod=14;
input int AdxPeriod=14;
input int MultipleStopLoss=2;
input double MultipleTakeProfit=2.4;
input int MagicNumber=4;

// Global variables

int AtrHandle;
int AdxHandle;
bool FakeoutHigh;
bool FakeoutLow;

int OnInit()
  
   {
      
      // Initialization atr
      
      AtrHandle=iATR(_Symbol,PERIOD_CURRENT,AtrPeriod);
      
      // Initialization adx
      
      AdxHandle=iADX(_Symbol,PERIOD_D1,AdxPeriod);
            
      return(INIT_SUCCEEDED);
   
   }

void TradeSystem()

   {
                  
      // Daily high low level
            
      double High=HighestHigh(_Symbol,PERIOD_D1,1,1);
      double Low=LowestLow(_Symbol,PERIOD_D1,1,1);    
      
      // Atr indicator
      
      double Atr[];
      ArraySetAsSeries(Atr,true);
      CopyBuffer(AtrHandle,NULL,0,10,Atr);
      
      // Adx indicator 
      
      double Adx[];
      ArraySetAsSeries(Adx,true);
      CopyBuffer(AdxHandle,NULL,0,10,Adx);

      // Buy conditions
                           
      if(iHigh(_Symbol,PERIOD_CURRENT,0)>Low&&iClose(_Symbol,PERIOD_CURRENT,1)<Low&&Adx[1]<Adx[2])
     
      {
     
         if(TimeOperative())
         
         {
         
            FakeoutLow=true;
         
         }
     
      }
                                        
      if(FakeoutLow)
      
      {
         
         double StopLoss=Low-Atr[1]*MultipleStopLoss;         
         double TakeProfit=Low+Atr[1]*MultipleTakeProfit;                     
         double PriceCurrent=Low;          
         double Volume=VerifyVolume(_Symbol,0.1);        
         double StopLossDistance=StopLossToPoints(_Symbol,StopLoss,PriceCurrent);
         double MyLotSize=RiskCalculate(_Symbol,Volume,1,StopLossDistance);
         
         if(PositionsTicket(_Symbol)==0&&OneTrade())
         
         {
         
            Request(TRADE_ACTION_DEAL,ORDER_TYPE_BUY,_Symbol,MyLotSize,ORDER_FILLING_FOK||ORDER_FILLING_IOC,PriceCurrent,StopLoss,TakeProfit,20,MagicNumber);
         
         }
         
         FakeoutLow=false;
          
      }
      
      ClosingTime();

Hello everyone and I wish you a merry Christmas. I have a serious problem in my trading system. The problem is error 10016. Premise I assure you that this code, even if it is incomplete (sorry it would be too long) works 100% in CFDs, everything changes with futures.


This EA bases the take profit and stop loss calculation based on the ATR indicator.


My question is why the broker accepts orders on CFDs and while in futures it gives me "stop loss invalid"?


How can I solve the problem (if it can be solved) by using equal calculation of TP and SL with ATR like in CFDs?


Thank you very much whoever wants to answer.

 
         double StopLoss=Low-Atr[1]*MultipleStopLoss;         
         double TakeProfit=Low+Atr[1]*MultipleTakeProfit;      

SL and TP should be related to the open  price not a Low.

The TP is probably below the open price. You should check this before trying to open an order.

 
Keith Watford #:

SL and TP should be related to the open  price not a Low.

The TP is probably below the open price. You should check this before trying to open an order.

I already tried my friend, thanks for your help but still not working, I also tried using SynmbolInfoDouble function to give me the current price but nothing.

This only works if I use the default tp and sl values without ATR calculation...
 
ClaudioCrive #:
I already tried my friend, thanks for your help but still not working, I also tried using SynmbolInfoDouble function to give me the current price but nothing.

This only works if I use the default tp and sl values without ATR calculation...

Show the code that you have tried.

 
double StopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-Atr[1]*MultipleStopLoss;         
double TakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+Atr[1]*MultipleTakeProfit;

// This variant does not work

double StopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-1000*_Point;         
double TakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+1000*_Point;

// If I use the classic value points, it works 

These are the two variants i tried, only the second one works.

I assure you that the first calculation with ATR on CFDs always worked...

This thing makes you laugh because the calculation is right.
The stop level calculates it correctly and it is exactly the level I want.
But he still doesn't accept it.
 
Hi Claudio. Did you get this resolved? I have the same issue. I have an EA with an ATR based stoploss that works beautifully with CFDs. I try it on Futures and get "invalid stops". When I have my EA print the price levels, everything looks good and I can't think of why it won't take the trade. What's more confusing is that sometimes it takes the trade, most of the time it won't.
 
Theo H. #:
Hi Claudio. Did you get this resolved? I have the same issue. I have an EA with an ATR based stoploss that works beautifully with CFDs. I try it on Futures and get "invalid stops". When I have my EA print the price levels, everything looks good and I can't think of why it won't take the trade. What's more confusing is that sometimes it takes the trade, most of the time it won't.

My guess here would be to check the freeze levels of the symbol, as they might get in your way.

Search the mql site for "Checks an EA must pass" and see if you fulfill all requirements. It will most probably guide you to the solution for your problem.