Forward Testing in the MT5 Strategy Tester: Is Your Best Optimization Pass Real?

5 December 2026, 14:44
Frederic Jean Andre Jouillerot
0
8

An optimization in MetaTrader 5 always produces a best pass. The question is whether that pass found something real or only the luckiest combination of parameters on that particular history. The Strategy Tester has a built-in tool for this: the Forward setting. This post shows how to use it, what a simulation says about what to expect, and an OnTester() criterion that rewards consistency rather than a single lucky number.

1. What the Forward setting does

According to the MetaTrader 5 help, the Forward field accepts No, 1/2, 1/3, 1/4 or Custom (a start date you choose). The period set in the Date field is split in two: the first part is used for optimization, the second, always the latest part, checks the selected parameters. Forward results appear on a separate Forward tab, and the start of the forward period is marked by a vertical line on the chart.

In other words: the most recent part of your history is kept away from the optimizer and used as an exam.

2. Step by step

  1. Fix the test plan first. Symbol, timeframe, date range, modelling mode (Every tick based on real ticks when your broker provides the history), deposit, and the parameter ranges. Write them down.
  2. Choose the forward share. 1/3 is a reasonable start: two thirds to optimize, one third to check.
  3. Decide your pass/fail rule before running. For example: forward expectancy above zero after costs, at least a minimum number of forward trades, and a forward drawdown no worse than a level you set.
  4. Run the optimization and look at the backtest results and the Forward tab side by side.
  5. Judge the set you would actually trade, not the best line of the forward table. Picking the best forward result reintroduces the selection the forward test was meant to remove.

3. What to expect: a simulation

Synthetic illustration, not a real strategy. 100 parameter variants, each trade wins +1.5R or loses -1R, 300 trades in the optimization period and 150 in the forward period. The best variant is selected on the optimization period only. 20,000 repetitions.

  • No edge at all (40% win rate, expectancy 0): the best variant shows about +0.18R per trade in the optimization period, about +53R over 300 trades. In the forward period its average is 0.00R, and it is negative in 47% of cases.
  • A real edge of +0.10R in every variant (44% win rate): the best variant shows about +0.28R in the optimization period. In the forward period it averages +0.10R, negative in 14% of cases.

Two lessons. First, the optimization result of the best pass overstates the edge by roughly the same amount whether the edge exists or not: the gap comes from selection, not from the strategy. Second, the forward result removes that bias but stays noisy. With 150 trades, a zero-edge strategy still lands between -0.13R and +0.13R per trade in about 84% of cases, positive results included. A single positive forward period is evidence, not proof.

4. A custom criterion that rewards consistency

Maximizing net profit favours passes with a few big wins. A criterion based on the mean and dispersion of trade results favours steadier passes. Add this to your EA and choose "Custom max" as the optimization criterion. Inputs are examples.

input int InpMinTrades = 100; // passes with fewer trades score 0

double OnTester()
  {
   if(!HistorySelect(0,TimeCurrent()))
      return(0.0);
   int deals=HistoryDealsTotal();
   int n=0;
   double sum=0.0,sum2=0.0;
   for(int i=0;i<deals;i++)
     {
      ulong ticket=HistoryDealGetTicket(i);
      if(ticket==0)
         continue;
      long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
      if(entry!=DEAL_ENTRY_OUT && entry!=DEAL_ENTRY_OUT_BY)
         continue;
      double r=HistoryDealGetDouble(ticket,DEAL_PROFIT)
              +HistoryDealGetDouble(ticket,DEAL_SWAP)
              +HistoryDealGetDouble(ticket,DEAL_COMMISSION);
      sum+=r;
      sum2+=r*r;
      n++;
     }
   if(n<InpMinTrades)
      return(0.0);
   double mean=sum/n;
   double var=(sum2-n*mean*mean)/(n-1);
   if(var<=0.0)
      return(0.0);
   return(mean/MathSqrt(var)*MathSqrt((double)n)); // t-statistic of trade results
  }

Notes: the score is the t-statistic of the closing-deal results, so higher means a mean result that is large relative to its variability. Commission charged on entry deals is not included. It does not fix selection bias: the best score among many passes is still inflated, which is why the forward period matters.

5. Limits

  • The forward period is the most recent data. If you look at it, change something, and rerun, it is no longer out-of-sample.
  • One forward window is one sample. Several windows (walk-forward) or several symbols give more evidence.
  • A backtest, forward or not, is still a model of execution. Costs and slippage on a live account can differ.

Disclosure

I develop Titan Breakout, an H1 breakout Expert Advisor for MetaTrader 5, at Pipmaster France. If you evaluate it, or any EA, keep a forward period aside and decide the pass/fail rule before you look. Titan Breakout is free to download for backtesting: Titan Breakout.

The figures in section 3 come from a synthetic simulation, not from any real strategy or account. Trading leveraged products involves a high risk of capital loss. This is not investment advice.