Out-of-Sample Testing: Why Your Best Optimization Pass Usually Disappoints

27 November 2026, 08:19
Frederic Jean Andre Jouillerot
0
8

Every optimization run ends the same way: a table sorted by profit, and a best pass that looks great. The uncomfortable question is how much of that pass is skill and how much is luck. Out-of-sample testing answers it, and the answer is often humbling. This post shows the effect on a synthetic example and gives an MQL5 script to split your own results.

1. Optimizing a system with no edge

Synthetic example, not a real EA: 50 parameter variants of a system with exactly zero expectancy (40% winners at +1.5R, losers at -1R). Each variant trades 150 times in-sample, then 150 times out-of-sample. We pick the best variant on the in-sample profit factor, exactly as an optimizer would, and repeat the whole experiment 2,000 times.

  • In-sample: the best of 50 variants has a median profit factor of 1.42. In 95% of experiments it reaches 1.3 or more.
  • Out-of-sample: the same "best" variant has a median profit factor of 1.00. It reaches 1.3 or more in only 6% of experiments, and is profitable at all in 44%.

In one typical run, the winning variant went from PF 1.54 in-sample to 0.87 out-of-sample. Nothing changed in the system. The optimizer had simply selected the luckiest past.

2. Why this happens

An optimizer ranks variants by results that mix two things: the true edge and the noise of that particular sample. When the true edge is small or zero, the ranking is mostly noise, and the top of the table is the variant with the most favourable noise. Noise does not repeat, so the out-of-sample result falls back toward the true edge. This is regression to the mean, and the more variants you test, the stronger it gets.

3. Using the forward period in the MT5 Strategy Tester

The MT5 Strategy Tester has a built-in Forward option (1/2, 1/3, 1/4 of the period, or a custom date). Optimization runs on the first part only, and each pass is then replayed on the forward part. Sort by the back result, then look at what the forward column does to the top passes. If the top of the back table collapses forward, you have learned something important for free.

4. A script to split your own trade history

This script reads the account history (or a tester history) and computes the profit factor before and after a split date:

#property script_show_inputs
input datetime InpSplit = D'2024.01.01';   // first out-of-sample date

void OnStart()
  {
   if(!HistorySelect(0, TimeCurrent())) { Print("HistorySelect failed"); return; }

   double gIS = 0, lIS = 0, gOOS = 0, lOOS = 0;
   int    nIS = 0, nOOS = 0;
   int    total = HistoryDealsTotal();

   for(int i = 0; i < total; i++)
     {
      ulong tk = HistoryDealGetTicket(i);
      if(tk == 0) continue;
      if(HistoryDealGetInteger(tk, DEAL_ENTRY) != DEAL_ENTRY_OUT) continue;

      double p = HistoryDealGetDouble(tk, DEAL_PROFIT)
               + HistoryDealGetDouble(tk, DEAL_SWAP)
               + HistoryDealGetDouble(tk, DEAL_COMMISSION);
      datetime t = (datetime)HistoryDealGetInteger(tk, DEAL_TIME);

      if(t < InpSplit) { if(p > 0) gIS += p;  else lIS -= p;  nIS++;  }
      else              { if(p > 0) gOOS += p; else lOOS -= p; nOOS++; }
     }

   PrintFormat("In-sample:     %d trades, PF %.2f", nIS,  (lIS  > 0) ? gIS / lIS   : 0);
   PrintFormat("Out-of-sample: %d trades, PF %.2f", nOOS, (lOOS > 0) ? gOOS / lOOS : 0);
  }

Commissions charged on entry deals are not included, so treat the result as an approximation. The point is the comparison, not the third decimal.

5. How to read the gap

  • Out-of-sample close to in-sample: encouraging, provided the out-of-sample period has enough trades (a few hundred, not a few dozen).
  • Out-of-sample well below in-sample but still positive: normal. Some of the in-sample result was luck. Size your expectations on the out-of-sample figure.
  • Out-of-sample around break-even or worse: the in-sample result was most likely selection luck. Re-optimizing until the forward period looks good just turns your out-of-sample data into in-sample data.

6. Limits

  • One out-of-sample period is one more sample, with its own noise. Walk-forward analysis (several rolling in-sample / out-of-sample windows) gives a more stable picture.
  • Once you have looked at the out-of-sample result and changed the system because of it, that data is no longer out-of-sample.
  • A market regime change can hurt a genuine edge out-of-sample. A bad forward result is a warning, not always a verdict.

7. How we apply it

At Pipmaster France, we encourage anyone evaluating Titan Breakout, our H1 breakout EA, to run their own forward tests on their broker's data rather than trusting any single optimized report, including ours. It is free to download for backtesting and demo: Titan Breakout (free backtest and demo).

The figures above come from a synthetic simulation (2,000 experiments, fixed seed), 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.