May I set a deviation of 0 when requesting a market trade with my EA?

To add comments, please log in or register
pdenoeud
1767
pdenoeud  

I have a mql5  EA which sends market orders with the command
OrderSend(request,result)

The MqlTradeRequest request object has the following attributes:
request.action = TRADE_ACTION_DEAL; (market execution)
request.deviation=0; (I prefer not executing the trade rather than executing it with any deviation, I am doing arbitrage and any point counts)

In the facts, orders do execute with deviation (or slippage, I guess it is the same) : between 1 and 2 points, which ruins my trading.

My questions are:
- is that possible to set request.deviation to 0 in theory, or a 0 value is interpreted as no max deviation specified?
- if that is not possible, is there any minimum value (0.1 would be ok?)
- is it mandatory for the broker to respect the max deviation specified, or is he allowed to forget it? I think I read somewhere that ECN brokers do not respect it, and market makers have to respect it...

Thanks for your help!

Pierre 

Alain Verleyen
36075
Alain Verleyen  

You have to understand how it works.

0 is 0 but deviation is not used on Market execution.

How to avoid the bad slippage?
How to avoid the bad slippage?
  • 2014.04.10
  • www.mql5.com
I wish there is a method/function to tell us what is the broker's slippage going to be if I trade...
pdenoeud
1767
pdenoeud  
Alain Verleyen:

You have to understand how it works.

0 is 0 but deviation is not used on Market execution.

Thanks for your quick answer Alain.

I am lost, I saw your post about instant execution (only for market makers if I understand correctly, not ECN), but I can't see how it fits with the OrderSend function : there is no mention to the enum ENUM_SYMBOL_TRADE_EXECUTION (one of its value is SYMBOL_TRADE_EXECUTION_INSTANT) in the function spec.

Also, here there is an exemple of what I am doing now: https://www.mql5.com/en/docs/constants/tradingconstants/enum_trade_request_actions
Code is :

#define EXPERT_MAGIC 123456   // MagicNumber of the expert
//+------------------------------------------------------------------+
//| Opening Buy position                                             |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.symbol   =Symbol();                              // symbol
   request.volume   =0.1;                                   // volume of 0.1 lot
   request.type     =ORDER_TYPE_BUY;                        // order type
   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
   request.deviation=5;                                     // allowed deviation from the price
   request.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
//--- send the request
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code
//--- information about the operation
   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
  }

Why do they set deviation if it is not taken into account??

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each trade order refers to the type of the requested operation. Trading operations are described in the ENUM_TRADE_REQUEST_ACTIONS enumeration...
Alain Verleyen
36075
Alain Verleyen  
pdenoeud:

Thanks for your quick answer Alain.

I am lost, I saw your post about instant execution (only for market makers if I understand correctly, not ECN), but I can't see how it fits with the OrderSend function : there is no mention to the enum ENUM_SYMBOL_TRADE_EXECUTION (one of its value is SYMBOL_TRADE_EXECUTION_INSTANT) in the function spec.

Execute such code to check with trade execution mode is used :

  ENUM_SYMBOL_TRADE_EXECUTION executionMode=(ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_EXEMODE);
  printf("Trade execution mode for %s is %s",_Symbol,EnumToString(executionMode));
If it returns SYMBOL_TRADE_EXECUTION_INSTANT (or SYMBOL_TRADE_EXECUTION_REQUEST) then you can use "deviation" with OrderSend. Otherwise you can't.

Also, here there is an exemple of what I am doing now: https://www.mql5.com/en/docs/constants/tradingconstants/enum_trade_request_actions
Code is :

Why do they set deviation if it is not taken into account??

Because OrderSend() is a generic function, used with all kind of trading environment.

pdenoeud
1767
pdenoeud  
Alain Verleyen:

Execute such code to check with trade execution mode is used :

If it returns SYMBOL_TRADE_EXECUTION_INSTANT (or SYMBOL_TRADE_EXECUTION_REQUEST) then you can use "deviation" with OrderSend. Otherwise you can't.

Because OrderSend() is a generic function, used with all kind of trading environment.

Your code returns 

2018.05.08 14:33:53.876 test ([STOXX50],H1) Trade execution mode for [STOXX50] is SYMBOL_TRADE_EXECUTION_MARKET

So I can not use deviation with OrderSend. Do you know if I can use deviation with another function, or I just can't use deviation at all with my broker?

Alain Verleyen
36075
Alain Verleyen  
pdenoeud:

Your code returns 

2018.05.08 14:33:53.876 test ([STOXX50],H1) Trade execution mode for [STOXX50] is SYMBOL_TRADE_EXECUTION_MARKET

So I can not use deviation with OrderSend. Do you know if I can use deviation with another function, or I just can't use deviation at all with my broker?

It's broker dependent (in theory even symbol dependent). So if you want to use "deviation", you have to find an other broker.
To add comments, please log in or register