0

For MT4,MQL

When sendOrder(),

It sometimes successes or sometimes misses mainly because of slippage.

I would like to get the real slippage when sendOrder().

Is it possible???

My source code for now is like this below.

     Ticket = OrderSend(_Symbol,OP_SELL, Lot,Bid,2, // '2' is slippage alloable limit.
     SL,TP,comment,Magic);

     if (Ticket > 0){
       // if slippage is under 2 it works.
       // want to check the real slippage
     }
     else {
        int err = GetLastError();
        if(err == ERR_NO_ERROR || 
           err == ERR_COMMON_ERROR ||
           err == ERR_SERVER_BUSY ||
           err == ERR_NO_CONNECTION ||
           err == ERR_TRADE_TIMEOUT ||
           err == ERR_INVALID_PRICE ||
           err == ERR_PRICE_CHANGED ||
           err == ERR_OFF_QUOTES ||
           err == ERR_BROKER_BUSY ||
           err == ERR_REQUOTE ||
           err == ERR_TRADE_CONTEXT_BUSY){
             //want to check the slippage here!!!
        }

     }
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
whitebear
  • 11,200
  • 24
  • 114
  • 237
  • AFAICT, you can't really test for slippage, apart from trying to make trade. By definition, *slippage* is what happens to the market in the very short time between your order is sent (using your terminal's latest prices) and the time it has finished processing by your broker's bank. I would suggest contacting your broker and hear what they say and compare to some others. – not2qubit Jul 21 '18 at 07:52

1 Answers1

1

You have to calculate slippage on your own by subtracting the OrderOpenPrice from the price you sent with the order.

Example:

   double price = Bid;
   double slippage = 0.0;
   int ticket = OrderSend(_Symbol, OP_SELL, Lot, price, 2, SL, TP, comment, Magic);
   if(OrderSelect(ticket, SELECT_BY_TICKET))
      slippage = int(NormalizeDouble(fabs(price - OrderOpenPrice()) / _Point, 0));
nicholishen
  • 2,602
  • 2
  • 9
  • 13