DEV Community

Gueta Quant
Gueta Quant

Posted on Edited on Originally published at guetaquant.com

Why Positive Backtests Bleed in Live MT5: Auditing Slippage Asymmetry in Python

Intraday strategies with a 1.5 to 2.5 pip average profit per trade rarely fail in live trading because the entry logic suddenly stopped working. They fail because the backtest assumed zero-cost fills, or assumed slippage averages out to zero over time.

In live CFD and FX execution, slippage is rarely symmetric. Favorable price movement during order transit is often absorbed or requoted, while adverse movement passes straight to the fill price. Even a 0.3 to 0.4 pip net drag per side can wipe out the edge of a high-frequency or short-horizon system.

Symmetric ideal slippage distribution vs asymmetric live execution with negative tail

This post looks at the Python side of the audit: taking a real CSV export of micro-lot fills and checking whether execution cost is neutral or structurally skewed against the account. (For the MQL5 data-collection setup and Colombian regulatory context, see the original Spanish guide at Deslizamiento (slippage) y latencia en MT5.)

Why mean slippage lies if you do not check the tails

Suppose you run 40 micro-lot (0.01) test orders outside major macro releases (CPI, FOMC, BanRep) and export two columns: slip_pts (where negative means a worse fill than requested) and rtt_ms (terminal-to-broker round trip).

Looking only at the median can mislead you. A broker can give you 0.0 points on half your trades while hitting you with -4.0 to -8.0 points on the worst 10% of fills.

import numpy as np

# Sample audit array in points (negative = adverse fill cost)
slip_pts = np.array([-3.0, -1.0, 0.0, 1.0, -5.0, -2.0, 0.0, -4.0, 2.0, -2.0])
rtt_ms = np.array([118, 124, 112, 130, 340, 145, 119, 285, 121, 138])

mean_slip = float(np.mean(slip_pts))
p05_adverse = float(np.percentile(slip_pts, 5))
neg_rate = float(np.mean(slip_pts < 0) * 100.0)
pos_rate = float(np.mean(slip_pts > 0) * 100.0)

print(f"Mean: {mean_slip:.2f} pts | p05 tail: {p05_adverse:.2f} pts")
print(f"Negative fills: {neg_rate:.1f}% vs Positive fills: {pos_rate:.1f}%")
print(f"Median RTT: {np.median(rtt_ms):.0f} ms | p95 RTT: {np.percentile(rtt_ms, 95):.0f} ms")
Enter fullscreen mode Exit fullscreen mode

Feeding real drag back into your backtest

Once you have the observed mean slippage (mean_slip) and the 95th percentile latency (p95), run a simple sensitivity check on your historical trade list:

def net_expectancy(gross_pnl_pts: np.ndarray, spread_pts: float, avg_slip_pts: float) -> float:
    # avg_slip_pts is negative when execution hurts the account
    net = gross_pnl_pts - spread_pts + (2.0 * avg_slip_pts)  # entry + exit
    return float(np.mean(net))

sample_trades = np.array([12.0, -8.0, 15.0, -7.0, 10.0, 14.0, -9.0, 11.0])
print("Gross mean (pts):", float(np.mean(sample_trades)))
print("Net after 1.2pt spread & -1.4pt slip/side:", net_expectancy(sample_trades, 1.2, -1.4))
Enter fullscreen mode Exit fullscreen mode

Notice the 2.0 * avg_slip_pts term: both entry and exit market orders pay execution friction, and stop-losses during volatile bars often pay more than limit take-profits.

If your strategy's net expectancy turns negative after plugging in the empirical drag from 30 to 50 live micro-lot fills, do not tweak the entry indicator. Either move to a higher timeframe where average trade payoff dwarfs execution noise, or fix the routing/VPS latency first. You can track live vs expected fills over time in a local-first trading journal without uploading account data to third-party servers.

Educational analysis only; not financial advice.

Top comments (0)