Measuring Round-Trip Execution Latency and Signed Slippage in MQL5

Leader ●1 ●17 ●40
calendar_today ago • schedule2 min read
— Originally published at guetaquant.com

When an Expert Advisor moves from the MT5 Strategy Tester to a live account, the first discrepancy you notice is rarely the indicator math. It is the fill price. Between calling OrderSend() and receiving the broker's confirmation, network transit and server matching take anywhere from 80 ms to 400 ms, and the quote moves in the meantime.

If you do not log both the round-trip time and the signed price difference on every fill, you have no way to tell whether a drawdown comes from a broken signal or from execution friction. I documented the full Spanish methodology and Colombian broker context in Deslizamiento (slippage) y latencia en MT5, and below is the MQL5 logging pattern I use on micro-lot test runs.

Latency and slippage flow from MT5 terminal T0 to broker server T1 and final execution T2

Keep latency and slippage in separate columns

A common mistake is recording only the absolute pip difference. That hides direction. Use a sign convention where negative always means cost to the account:

  • Buy orders: requested_price - deal_price
  • Sell orders: deal_price - requested_price

If a buy fills higher than requested, the result is negative. If it fills lower, the result is positive.

Logging GetTickCount64() and MqlTradeResult in MQL5

Wrap OrderSend() with GetTickCount64() to measure the terminal-to-server round trip in milliseconds, then check TRADE_RETCODE_DONE before computing the point difference:

void LogExecutionAudit(string symbol, ENUM_ORDER_TYPE orderType, double volume)
{
   MqlTradeRequest req = {};
   MqlTradeResult  res = {};

   double requested = (orderType == ORDER_TYPE_BUY)
                      ? SymbolInfoDouble(symbol, SYMBOL_ASK)
                      : SymbolInfoDouble(symbol, SYMBOL_BID);

   req.action       = TRADE_ACTION_DEAL;
   req.symbol       = symbol;
   req.volume       = volume;
   req.type         = orderType;
   req.price        = requested;
   req.deviation    = 20;
   req.type_filling = ORDER_FILLING_IOC;

   ulong t0 = GetTickCount64();
   bool ok = OrderSend(req, res);
   ulong rttMs = GetTickCount64() - t0;

   if(!ok || res.retcode != TRADE_RETCODE_DONE)
   {
      PrintFormat("EXEC_FAIL retcode=%u rtt_ms=%I64u", res.retcode, rttMs);
      return;
   }

   double fillPrice = res.price;
   double point     = SymbolInfoDouble(symbol, SYMBOL_POINT);
   double slipPts   = (orderType == ORDER_TYPE_BUY)
                      ? (requested - fillPrice) / point
                      : (fillPrice - requested) / point;

   PrintFormat("EXEC_OK deal=%I64u rtt_ms=%I64u req=%.5f fill=%.5f slip_pts=%.1f",
               res.deal, rttMs, requested, fillPrice, slipPts);
}

Two practical details from running this in production:

  1. On market-execution accounts where res.price can reflect the initial acknowledgment rather than the final clearing price, read HistoryDealGetDouble(res.deal, DEAL_PRICE) after selecting the deal in history.
  2. Never treat a rejected order (retcode != TRADE_RETCODE_DONE) as zero slippage. Track rejection rates alongside rtt_ms so missed entries are visible in your audit.

Before sizing up any position on MT5, I also run the stop-loss budget and margin checks separately (you can test the sizing math on our MT5 position sizer).

Educational software note only, not financial advice.

Want more #quant & #algorithmictrading deep dives?

Join 6,181+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

Algorithmic Risk Management in MT5: ATR Volatility Position Sizing & MQL5 Architecture

Guetaquant - Sep 9

Auditing Broker Execution Latency, FIX Protocol & Asymmetric Slippage in Algorithmic Trading

Guetaquant - Oct 5

The Silent Position Sizer Bug: When Accounts Are Small, Your Risk Inadvertently Doubles

Guetaquant - Sep 15

MT5 Tick Size vs Point: A Test Harness for Price Distance

Guetaquant - Oct 28

Why Perfect Backtests Fail: Walk-Forward Optimization and Deflated Sharpe in Python

Guetaquant - Sep 9
chevron_left
1.8k Points • 58 Badges
Bogotá, Colombia • guetaquant.com
19Posts
2Comments
15Connections
Founder & Lead Quantitative Engineer at Gueta Quant (https://guetaquant.com).

I design open-source... Show more

Commenters (This Week)

16 comments
6 comments
2 comments

Contribute meaningful comments to climb the leaderboard and earn badges!