Your Backtest Drawdown Is a Minimum: Monte Carlo Reshuffling in MQL5

23 November 2026, 15:51
Frederic Jean Andre Jouillerot
0
16

Every MT5 Strategy Tester report prints a "Maximal drawdown". Most traders read it as the worst the strategy can do. It is not. It is the worst drawdown of one particular ordering of your trades, the one history happened to produce. Change the order and the same trades can dig a much deeper hole.

This post shows how to estimate that hidden risk with a simple Monte Carlo reshuffle, with an MQL5-friendly implementation you can run on your own tester results.

1. A synthetic example

To keep it honest, here is a synthetic system, not a real EA: 200 trades, 40% winners at +1.6R, losers at -1R. Expectancy is positive (about +0.12R per trade). In the order generated, the maximum drawdown is 10.4R and the longest losing streak is 6 trades.

Now reshuffle the same 200 trades 10,000 times and measure the drawdown each time:

  • Median maximum drawdown: 12.6R
  • 95th percentile: 20.2R, about twice the "historical" figure
  • 99th percentile: 24.4R
  • 77% of the reshuffled sequences were worse than the original
  • Longest losing streak at the 95th percentile: 12 trades, versus 6 in the original

Same trades, same win rate, same expectancy. Only the order changed.

2. Why this matters for position sizing

At 1% risk per trade, the original sequence suggests a maximum drawdown of about 10%. The 95th percentile says about 20%. If you trade under a 10% overall loss limit, as many prop firm challenges impose, sizing on the tester's number means accepting a realistic chance of failing the account on a sequence that is entirely consistent with your edge.

A more defensive rule: size so that a pessimistic percentile of the simulated drawdown, not the historical one, stays inside your limit with margin.

3. A minimal implementation

Export the closed trades' results in R (profit divided by initial risk) from the tester, then reshuffle them. A minimal MQL5 script:

double MaxDD(const double &r[])
  {
   double eq=0, peak=0, dd=0;
   for(int i=0; i<ArraySize(r); i++)
     {
      eq += r[i];
      if(eq > peak) peak = eq;
      if(peak - eq > dd) dd = peak - eq;
     }
   return(dd);
  }

void Shuffle(double &r[])
  {
   for(int i=ArraySize(r)-1; i>0; i--)
     {
      int j = MathRand() % (i+1);
      double t = r[i]; r[i] = r[j]; r[j] = t;
     }
  }

void OnStart()
  {
   double trades[];   // fill with your trade results in R
   int    runs = 10000;
   double dd[];
   ArrayResize(dd, runs);
   MathSrand(42);
   for(int k=0; k<runs; k++)
     {
      double t[];
      ArrayCopy(t, trades);
      Shuffle(t);
      dd[k] = MaxDD(t);
     }
   ArraySort(dd);
   PrintFormat("Median DD: %.1fR  P95: %.1fR",
               dd[runs/2], dd[(int)(runs*0.95)]);
  }

Note: MathRand() only returns values up to 32767, which is fine for a few hundred trades. For very large samples, combine two calls.

4. What reshuffling does not capture

  • Regime changes. Reshuffling assumes trades are independent. Real losing streaks often cluster in specific market conditions, which can make reality worse than the simulation.
  • Edge decay. If the edge weakens in the future, every percentile shifts.
  • Execution. Slippage and spread spikes are not in the reshuffled sample unless they were in the original trades.

So treat the 95th percentile as a planning number, not a guarantee. It is still far more realistic than the single figure printed in the report.

5. How we apply it

At Pipmaster France, we treat the backtest drawdown of Titan Breakout, our H1 breakout EA, as a lower bound, and its risk controls (fixed-percentage sizing from the stop distance, daily and overall drawdown halts) are built for sequences worse than the backtest. It is free to download for backtesting and demo, so you can run this exact reshuffle on its trades with your own broker data: Titan Breakout (free backtest and demo).

The figures above come from a synthetic example, not from any real strategy or account. Trading leveraged products involves a high risk of capital loss. Past or simulated results do not guarantee future performance.