Error submitting Limit Orders

Jonathan Humphries
14
Jonathan Humphries  

Hi,

  I've been pouring over documentation and trying different order submission methods for a week or two now and haven't been able to figure out what I'm doing wrong.  When I submit a trade I receive error 10016 - Invalid Stops.  I've simplified my code to elminiate potential errors with no change.  As you can see I had some more complicated code that I commented out.  Here is what I'm submitting at the moment yet still getting an error.  Thank you for your response.

 

 MqlTradeRequest Myrequest;
   Myrequest.action = TRADE_ACTION_PENDING;
   Myrequest.type= ORDER_TYPE_SELL_LIMIT;//ordertype;
   Myrequest.symbol = instrument;
   Myrequest.magic = 1;
   Myrequest.price = SymbolInfo.Bid(); //price - (10 * _Point);
   Myrequest.volume = 0.1; //OrderVolume;
   Myrequest.sl = 0;
   Myrequest.tp = 0;
   /*if( ordertype == ORDER_TYPE_SELL_LIMIT)
   { Myrequest.sl = SymbolInfo.NormalizePrice((price + (stoploss * SymbolInfo.Point())));
     Myrequest.tp = SymbolInfo.NormalizePrice((price - (takeprofit * SymbolInfo.Point())));
   }
    else //its a long order
   { Myrequest.sl = SymbolInfo.NormalizePrice((price - (stoploss * SymbolInfo.Point())));
     Myrequest.tp = SymbolInfo.NormalizePrice((price + (takeprofit * SymbolInfo.Point())));
   }*/
   Myrequest.deviation = 50;
   //Myrequest.type_filling = ORDER_FILLING_FOK;
   //Myrequest.type_time = ORDER_TIME_SPECIFIED;
   //Myrequest.expiration = 2 * 60;  //(time in seconds)
   
  MqlTradeResult result;
//--- reset the last error code to zero
   ResetLastError();
//--- send request
   bool success=OrderSend(Myrequest,result);
Andriy Moraru
1098
Andriy Moraru  
It seems that you are trying to set a pending limit order at the current price, which isn't permitted. You have to set your pending orders at some distance from the current price.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
Jonathan Humphries
14
Jonathan Humphries  

Thank you for the comment.  I'll definitly look at the buy price and adjust it; however, the error's i'm getting state a problem with the stop loss not the price...

 

Stephen Njuki
4951
Stephen Njuki  
Jon.Humphries79:

Thank you for the comment.  I'll definitly look at the buy price and adjust it; however, the error's i'm getting state a problem with the stop loss not the price...

 

You need to add the minimum stop distance to the Ask Price