Blog / Code & convert EAs · Backtesting · Expert Advisors

Walk-Forward Testing in MT5

Learn how to use MT5 forward testing to check EA optimisation results and identify strategies that fail on unseen data.

· 6 min read

A good backtest does not automatically mean an Expert Advisor is ready for live trading. If you optimise an EA using historical data and then evaluate it on exactly the same period, you may simply be measuring how well its settings fit the past.

Walk-forward testing helps address this problem by separating the data used to optimise a strategy from the data used to evaluate it.

MetaTrader 5 includes a built-in forward-testing option in the Strategy Tester, making it possible to check how selected optimisation results perform on a later, previously unseen section of historical data.

Here's how to use it and interpret the results.

1. What is walk-forward testing?

Walk-forward testing is a method of evaluating a trading strategy using separate historical periods.

The process has two main stages:

  • In-sample testing: The EA is optimised using one section of historical data to identify suitable input parameters.
  • Out-of-sample testing: The selected parameter sets are tested on a later section of data that was not used during optimisation.

For example, suppose you want to evaluate an EA using historical data from January 2021 to December 2025.

You could reserve January 2021 to December 2024 for optimisation and use January to December 2025 for forward testing.

The first period helps identify suitable settings. The second helps determine whether those settings remain useful beyond the data on which they were selected.

The important distinction is that the forward period should not influence the original optimisation. Overfitting: How to Spot a Curve-Fitted EA explains why.

2. Configure forward testing in MT5

MetaTrader 5 provides a built-in Forward option in the Strategy Tester.

To configure it:

  1. Open MetaTrader 5 and launch the Strategy Tester.
  2. Select the Expert Advisor you want to evaluate.
  3. Choose the trading symbol and timeframe.
  4. Set the historical date range.
  5. Select an optimisation mode rather than a single test.
  6. Find the Forward setting and choose your preferred split.
  7. Configure the EA's input parameters and optimisation ranges.
  8. Start the optimisation.

MT5 offers these forward-period options:

Setting Forward period
No No forward testing
1/2 Last half of the selected period
1/3 Last third
1/4 Last quarter
Custom A manually specified forward start date

The first section of the selected date range is used for optimisation. The later section is reserved for forward testing.

For example, if you select a five-year date range and choose 1/4, the final quarter of that period becomes the forward-testing segment.

MT5 performs the optimisation on the earlier segment and then evaluates the best parameter sets from it on the forward segment.

3. Compare the optimisation and forward results

When the optimisation finishes, don't focus exclusively on the highest profit in the original optimisation results.

Open the Forward Results tab and compare the results with the corresponding optimisation results.

Pay attention to:

  • Net profit: Does performance hold up, or does it deteriorate sharply?
  • Maximum drawdown: Does the strategy experience substantially larger losses?
  • Profit factor: Does gross profit remain reasonably strong relative to gross loss?
  • Expected payoff: Does the average result per trade remain positive?
  • Trade count: Does the EA generate enough trades to make the comparison meaningful?

A strategy does not need to produce identical results in both periods. Markets change, and performance naturally varies.

However, a strategy that produces exceptional optimisation results and then collapses during forward testing deserves further investigation.

Also remember that MT5's built-in forward optimisation does not test every parameter combination again on the forward period. According to the MetaTrader 5 help, it takes the best 10% of passes from a complete search, or the best 25% from the genetic algorithm, and runs only those on the forward period.

4. What do good and bad forward results look like?

Consider a simplified, hypothetical example:

Metric Optimisation Forward
Net profit $8,500 $2,100
Profit factor 1.85 1.42
Maximum drawdown 12% 16%
Total trades 420 115

The forward result is weaker, but it stays positive, with a profit factor above 1 and a moderate increase in drawdown.

That does not prove the strategy will succeed live, but it gives you more reason to investigate it than a strategy whose forward performance is deeply negative.

Now consider a different outcome:

Metric Optimisation Forward
Net profit $8,500 -$2,900
Profit factor 1.85 0.68
Maximum drawdown 12% 34%
Total trades 420 115

This is a much stronger warning. The strategy's historical performance has not carried into the later period.

Both tables are made-up figures, not results from a real EA, and neither establishes a universal pass or fail threshold. Interpret real figures in the context of the EA's trading frequency, risk model, instrument, and intended use.

5. Avoid contaminating your forward-testing data

One common mistake is repeatedly changing an EA's parameters after seeing poor forward results, then testing those new settings on the same forward period.

Once you do this, that period is no longer genuinely unseen. You have started using it to guide optimisation.

A better approach is to:

  1. Define your optimisation period before testing.
  2. Reserve a later period for forward evaluation.
  3. Select your parameter configuration using the optimisation results.
  4. Evaluate it on the reserved period.
  5. Record the results without repeatedly adjusting settings to improve that same test.
  6. If you make substantial changes, reserve another untouched period for independent evaluation.

This helps preserve the value of out-of-sample testing.

6. Understand the limitations of MT5 forward testing

MT5's built-in forward feature is useful, but it is not a guarantee of future performance.

A single historical split may favour a particular market environment. A strategy could perform well during one forward period and struggle during another.

For a more thorough evaluation, consider repeating the process with different date ranges. You can also use a rolling walk-forward approach: optimise on one historical window, test on the next window, then move the windows forward and repeat.

For example:

  • Optimise on 2021–2022, then test on 2023.
  • Optimise on 2022–2023, then test on 2024.
  • Optimise on 2023–2024, then test on 2025.

This provides several observations of how the strategy behaves as market conditions change.

You should also account for realistic spreads, commissions, slippage, and execution delays. Forward testing cannot compensate for unrealistic assumptions in the underlying backtest; Spread, Commission and Slippage shows how to set them in MT5.

Conclusion

Walk-forward testing helps determine whether an MT5 Expert Advisor can perform beyond the historical data used to optimise it.

The built-in Forward option makes the process accessible: choose an optimisation period, reserve a later section for forward evaluation, and compare the results rather than relying on the best historical pass alone.

For more confidence, repeat the process across different periods and market conditions. A strategy that remains reasonably consistent across independent tests is more interesting than one that only looks impressive on a single optimised backtest.

With PositionAlpha's Bot Builder, you describe your trading idea and the AI writes MT4 or MT5 code for you to review and test, with a plain-English explanation and setup steps. Run a forward test on it in the Strategy Tester, and test it on a demo account before you rely on it.

Build a bot from your idea

Describe your trading idea and the AI writes MT4 or MT5 code for you to review and test, with a plain-English explanation and setup steps. Your first bot is free.

More from the blog