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

 

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 

 

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...
 
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...
 
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.

 
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?

 
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.
 

I know this post is an old one. So sorry to bother you here ^^ 

I was having the same problem. So your post helped me to understand than my broker will not help me on this side.

Anyway, you can (if you are still there or if other are reading)

Use pending orders ;) Should be only limit ^^ And add something like living time of the order of 1 second you will have the equivalent of a fill or kill with 0 deviation order no ?

Have a nice day :) (if anyone have better idea i'm all ears !) 

 
Sacha Olivier Isabe Berthelon:

I know this post is an old one. So sorry to bother you here ^^ 

I was having the same problem. So your post helped me to understand than my broker will not help me on this side.

Anyway, you can (if you are still there or if other are reading)

Use pending orders ;) Should be only limit ^^ And add something like living time of the order of 1 second you will have the equivalent of a fill or kill with 0 deviation order no ?

Have a nice day :) (if anyone have better idea i'm all ears !) 

Pending orders also suffer slippage! You cannot prevent slippage with pending orders, whether that be negative or positive slippage.

Most good traders search for brokers that are ECN or NDD, and stay away from market makers or DD. Searching for those types of brokers because you want "Instant Execution" just to be able to have control over deviation, is setting yourself up to lose money.

Learn to embrace slippage by understanding it and how to trade with it!

 
Fernando Carreiro:

Pending orders also suffer slippage! You cannot prevent slippage with pending orders, whether that be negative or positive slippage.

Most good traders search for brokers that are ECN or NDD, and stay away from market makers or DD. Searching for those types of brokers because you want "Instant Execution" just to be able to have control over deviation, is setting yourself up to lose money.

Learn to embrace slippage by understanding it and how to trade with it!

When you set LIMIT order (example Buy Limit Order )   , Because of the order is under the price (should be under the price)  ,  when the price line triggered, the slippage is always POSITIVE,  Because if the price line doesn't reach the order line , the order dos not active (limit order), But when the price line passes the order line , so the price line goes UNDER the limit buy order.  So it's simple >>> The slippage is positive.
If I wrong please correct.
Reason: