Trying to place a market order, but it fails because of [Invalid stops]. What should I do?

 
I prepared the following simple code:
int OnInit() {
   MqlTradeRequest request;
   request.action = TRADE_ACTION_DEAL;
   request.symbol = Symbol();
   request.volume = 0.01;
   request.type = ORDER_TYPE_BUY;
   request.type_filling = ORDER_FILLING_AON;  
   MqlTradeResult result;
   OrderSend(request,result);
   return(0);
}

But it fails because of:

2011.07.21 20:53:00     Trades  '912850' : failed instant buy 0.01 EURUSD at 0.00000 [Invalid stops]

 The MQL5 documentation clearly states that: 

Market Execution

This is a trade order to open a position in the Market Execution mode. It requires to specify the following 5 fields:

action 
symbol 
volume 
type 
type_filling 
Also it is possible to specify the "magic" and "comment" field values.

 Sorry if it's a novice question, but I really do not understand the logic behind this (again).

 

I have a similar problem when I try to modify SLTP of a position. (Position is opened manually, without setting any SL or TP) Code is:

int OnInit() {
   PositionSelect(Symbol());
   Print(PositionGetDouble(POSITION_PRICE_CURRENT));
   MqlTradeRequest request;
   request.action = TRADE_ACTION_MODIFY;
   request.symbol = Symbol();
   request.sl = NormalizeDouble(PositionGetDouble(POSITION_PRICE_CURRENT)+0.01, 4);
   request.tp = NormalizeDouble(PositionGetDouble(POSITION_PRICE_CURRENT)-0.01, 4);
   MqlTradeResult result;
   OrderSend(request,result);   
   return(0);
}

 Output:

2011.07.21 21:06:07     xyz (EURUSD,M1) 1.43822
2011.07.21 21:06:07     Trades  '912850' : failed modify order #0 buy 0.00 EURUSD at 0.00000 sl: 0.00000 tp: 0.00000 -> 0.00000, sl: 1.44820 tp: 1.42820 [Invalid request]

 Documentation says:

SL & TP Modification

Trade order to modify the StopLoss and/or TakeProfit price levels. It requires to specify the following 5 fields:

action 
symbol 
sl 
tp

...but what is the 5th field?

 

If I add the following two lines then it magically works:

   request.price = 1.5;
   request.deviation = 10000;

Howver in the documentation, it is said that it's not needed:

Price, reaching which the order must be executed. Market orders of symbols, whose execution type is "Market Execution" (SYMBOL_TRADE_EXECUTION_MARKET), of TRADE_ACTION_DEAL type, do not require specification of price.

 

 

 

 

 

 

I realized that instead of

request.action = TRADE_ACTION_MODIFY; 

the value

request.action=TRADE_ACTION_SLTP;

should be used. And the SL and TP prices were swapped.

But I still can't get the market execution working in the way it is stated in the documentation. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 

Are you able to send market order for this symbol manually (look at list of values in combo Type of new order form)?

Are you connected to MetaQuotes-Demo? 

 

Are you able to send market order for this symbol manually (look at list of values in combo Type of new order form)?

 Yes.

Are you connected to MetaQuotes-Demo? 

Yes, of course!
 
balazs321:

Are you connected to MetaQuotes-Demo? 

Yes, of course!

Are you sure?


 
Ahh, I see. Okay, that was the problem. Many thanks and sorry for being lame!
 

Hello,

I also have problem with market execution and it looks to be connected with what is explained above. However, I could not actually understand what is going on. I do use MetaQuates-Demo and I succeed in submitting order of type Instant Execution. Here are the screenshots from the terminal and afterwards is the code that I use to send order from MQL5. The OrderSend method results with code 10016 and message "Invalid stops".

 

 There is the source code:

void OnInit()
{
   MqlTradeRequest request;
   request.action = TRADE_ACTION_DEAL;
   request.symbol = _Symbol;
   request.volume = 0.1;
   request.type = ORDER_TYPE_BUY;
   request.type_filling = ORDER_FILLING_FOK; 
   MqlTradeResult result;
   OrderSend(request, result);
}

Could you please explain me what happens and what I can do to execute market orders from my EAs with the demo account? Thank you in advance!

Kind Regards,

Petrov

Reason: