Spread making strong jumps every second - how to get the low spread? - page 2

 
Amir Yacoby:
Actually, the requested price is Ask or Bid, and they both include the spread. So slippage from requested price includes the max spread.

When i do the following:

double spreadmax=3;// Max Spread
if(MarketInfo(Symbol(),MODE_SPREAD) < spreadmax)
 {
  Order();
 }

This will only fire an order when spread < 3 

 Regardless of market price.

int ticket=OrderSend(symbol,OP_BUY,volume,ask,3,0,0,"Slippage",1234,0,Gold);

This has slippage also set to 3.

But it will still fire when you order at spread == 100

Those are two different things.

 
Marco vd Heijden:

When i do the following:

This will only fire an order when spread < 3 

 Regardless of market price.

This has slippage also set to 3.

But it will still fire when you order at spread == 100

Those are two different things.

Ok, but what is the symbol execution mode of the symbol involved with the second example?
 
Marco vd Heijden:

When i do the following:

This will only fire an order when spread < 3 

 Regardless of market price.

This has slippage also set to 3.

But it will still fire when you order at spread == 100

Those are two different things.

In mql5 you get execution type by those lines

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));

Unless it is one of those

SYMBOL_TRADE_EXECUTION_REQUEST

SYMBOL_TRADE_EXECUTION_INSTANT

you can't use deviation (an ECN broker probably).
I am using metaquotes demo MT5 server hedging account for AUDJPY I get SYMBOL_TRADE_REQUEST_INSTANT by this code and run this script 

#define EXPERT_MAGIC 123456   // MagicNumber of the expert
//+------------------------------------------------------------------+
//| Opening Buy position                                             |
//+------------------------------------------------------------------+
void OnStart()
  {
   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));
   
//--- 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=0;                                     // 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);
  }

to not get a price higher then request.price - I get requotes and sometimes it succeeds to get the request.price and opens only that price. 

*-but, you are partly right about the deviation that it refers price, it actually refers price + spread together and does not allow them both to exceed the max deviation set from request.price (in case you know it and want to set a deviation from it) - which means if you set the ask price like that - you will surely get it or better whatever the spread will be  

**-so if you write like what you wrote before that

double spreadmax=3;// Max Spread
if(MarketInfo(Symbol(),MODE_SPREAD) < spreadmax)
 {
  Order(); //--- the part with max deviation = 0 or whatever
 }

You will ensure them both - that the price + spread together won't deviate more then x points from the known ask at time of execution (no sudden spread jump should be possible) + that you only receive ask price when the spread is low (lower then 3 for instance)

Reason: