ForexCopilotEA

Backtesting

Walk-Forward Analysis in MT5: How to Test an Expert Advisor So It Does Not Just Fit the Past

By Benjamin Lee · Updated · 7 min read

An optimised backtest answers the question what would have been best in the past. Walk-forward analysis asks a better one: if I had picked settings the way I plan to, how would they have done on data I had not yet seen. It is one of the few practical defences against overfitting, the problem that makes weak Expert Advisors look brilliant on a chart. This guide explains the idea in plain words, shows what the MT5 Strategy Tester gives you out of the box, and describes a manual rolling process you can run when you want more than a single forward split.

Key takeaways

  • Optimise on one period (in-sample), then test those settings on the next (out-of-sample).
  • MT5's Forward setting gives one split. A full walk-forward repeats the process over several windows.
  • If results collapse out-of-sample, the settings were probably fitted to noise.
  • Judge the whole chain of out-of-sample periods together, not the best one.
  • Walk-forward reduces overfitting. It does not prove an EA will work live.

The idea in plain words

When you optimise an EA, the tester tries many combinations of inputs and shows the best. With enough combinations, something always looks good on any history, even random data. The question is whether the winner reflects a real edge or luck. Walk-forward analysis separates the two by splitting history. You optimise on an earlier slice, called in-sample, pick the best settings, and then run them unchanged on the following slice, called out-of-sample, which the optimiser never saw. If the edge is real, the out-of-sample result should be reasonably close to the in-sample one. If not, the optimiser was fitting noise. The risks of fitting are explained further in our overfitting guide, and the academic background is in the paper on backtest overfitting.

What the MT5 Strategy Tester offers

The Strategy Tester has a Forward field next to the date range. Choose a fraction such as one half, one third or one quarter, or a custom date. When you run an optimisation, the tester optimises on the earlier part of your range and then runs each pass on the forward part as well. The results are shown in separate columns, with the forward result next to the backtest result. MetaQuotes describes this in its help pages on strategy optimisation.

Reading backtest and forward columns
What you seeWhat it suggests
Forward result close to backtest resultThe settings may reflect something stable
Forward result much worse, still positiveSome fitting; treat the backtest figure as optimistic
Forward result negativeLikely overfitted to the in-sample period
Forward trades very fewNot enough data to judge
Best backtest pass has a poor forward pass, a mid-ranked pass is good in bothLook for stable settings, not the single best

A single forward split is better than none, but it is one sample. A lucky split can hide a fitted setting, and an unlucky one can hide a good one. A full walk-forward repeats the split several times.

A manual rolling walk-forward

MT5 does not include an automatic rolling walk-forward report, but you can run one by hand. Divide your history into windows. For each window, optimise on the in-sample part, take the chosen settings, test them on the next out-of-sample part, and record the out-of-sample result. Then move forward and repeat. Finally, join the out-of-sample results end to end. That chain is the performance you could have got by following the process.

Example windows over six years (illustrative)
WindowOptimise on (in-sample)Test on (out-of-sample)
1Years 1 and 2Year 3
2Years 2 and 3Year 4
3Years 3 and 4Year 5
4Years 4 and 5Year 6
  1. Step 1: Fix the rules before you start

    Decide the window lengths, the optimisation criterion and the inputs you will optimise. Do not change them after seeing results.

  2. Step 2: Use real ticks and realistic costs

    Set the modelling, spread, commission and delay as described in the Strategy Tester settings guide.

  3. Step 3: Optimise the first in-sample window

    Use the fast genetic algorithm if there are many inputs, and keep the number of optimised inputs small.

  4. Step 4: Choose by a stable region, not the single top pass

    Prefer settings whose neighbours also work, so a tiny change does not ruin the result.

  5. Step 5: Run the chosen settings on the next window

    Without any change. Record net profit, drawdown, profit factor and trade count.

  6. Step 6: Repeat for each window and join the results

    Compare the combined out-of-sample curve with the combined in-sample figures.

How to read the outcome

  • A practitioner's rule of thumb is that out-of-sample performance should keep a reasonable share of the in-sample level. No threshold is exact, so treat it as a guide, not a pass mark.
  • Look at drawdown as well as profit. An out-of-sample period with a deep drawdown tells you what a live account might meet.
  • Check consistency across windows. Four mildly positive periods are more convincing than three poor ones and one great one.
  • Count the trades. Hundreds across all windows give a better read than dozens.
  • If settings change a lot from window to window, the strategy may be unstable.

What walk-forward cannot do

It cannot see the future. If market conditions change after your last window, the EA can fail. It does not catch mistakes in the data, a spread that is too tight, or a strategy that cheats by peeking at future bars. It also gets weaker if you repeat the whole exercise many times and pick the version that looks best, because the repetitions themselves are then an optimisation. Do it once with fixed rules, and then move to forward testing on a demo account, as described in forward testing on demo.

Walk-forward checklist
0/8

The broader backtesting process is in how to backtest an EA in the MT5 Strategy Tester, and the report figures are explained in how to read an MT5 backtest report.

A worked example of reading the results

These numbers are invented to show the method. A gold EA is optimised on two-year windows and tested on the following year, over four windows. The table shows the net result for a 2,000 euro account and the maximum equity drawdown in each out-of-sample year.

Out-of-sample results by window (illustrative)
WindowIn-sample profit (2 years)Out-of-sample profit (1 year)Out-of-sample maximum drawdown
1+1,200 euros+260 euros14%
2+1,350 euros+90 euros19%
3+1,100 euros-120 euros23%
4+1,500 euros+310 euros12%
Combined out-of-sample+540 euros over four yearsWorst year 23%

Read it in three steps. First, the out-of-sample profit is much smaller than the in-sample profit even after halving it for the shorter period, which is normal and shows how optimistic fitted results are. Second, one of the four windows lost money, so the chain is positive but not smooth. Third, the worst drawdown was 23 percent, a figure you should compare with what you could stomach. The result says the EA may have a modest edge with large swings, and that the in-sample figures overstate it. It would be a reason to size down and forward test, not to scale up.

Sources and further reading

  1. MetaTrader 5 Help: Strategy OptimizationHow optimisation and forward testing work in the Strategy Tester.
  2. MetaTrader 5 Help: Strategy TestingThe Strategy Tester: testing modes, settings and forward testing.
  3. Bailey, Borwein, López de Prado and Zhu: Pseudo-Mathematics and Financial Charlatanism (Notices of the AMS, May 2014)A plain-language account of how backtest overfitting produces strategies that fail out of sample.

Frequently asked questions

What is walk-forward analysis?

It is a testing method that optimises an EA on one period and then tests the chosen settings on the next period, which the optimiser never saw. Repeating this over several windows shows whether the settings generalise.

Does MT5 have walk-forward analysis?

MT5's Strategy Tester has a Forward setting that gives one in-sample and out-of-sample split during optimisation. A full rolling walk-forward is something you run by hand with several windows.

How much data do I need for walk-forward?

Enough for several windows that each contain a meaningful number of trades. Several years on a liquid symbol is common, but it depends on how often the EA trades.

What if the forward result is much worse?

The settings were probably fitted to the in-sample period. Reduce the number of optimised inputs, choose a stable region, or treat the EA with more caution.

Is a good walk-forward result a guarantee?

No. It lowers the chance that you picked settings by luck, but markets change. Follow it with a demo forward test and a small live start.

Expert Advisors in these styles

Apply the checks above to any of these before you buy: read the manual, run your own backtest, and start on demo.

Browse Expert Advisors