Walk Forward Testing for Forex Expert Advisors
Walk forward testing checks whether an EA's optimisation process works on data it has not seen. You optimise on one window of history, trade the chosen settings unchanged on the next window, then roll both windows forward and repeat. Stitching the unseen segments together gives an out-of-sample equity curve that is far more honest than a single backtest, because every trade in it was made with settings chosen in advance.
Key takeaways
- Walk forward analysis tests the re-optimisation routine, not one parameter set, which mirrors how most EAs are actually run.
- Only the stitched out-of-sample (OOS) segments count as evidence; the in-sample results are just the means of choosing settings.
- Walk-forward efficiency compares OOS performance with in-sample performance; persistently low or negative values suggest the optimisation is fitting noise.
- Each OOS window needs enough trades to mean something, which often forces longer windows than people expect.
- MetaTrader 5 supports one forward split natively; a full walk forward needs repeated runs, scripting or third-party software.
Why a single backtest is not enough
A standard optimisation finds the settings that performed best over the whole test period. That result is inflated: the settings were chosen precisely because they fitted that period. A single out-of-sample split helps, but it gives you one data point, and if the unseen period happened to suit the strategy you learn little. We cover the broader problem in curve fitting and over-optimisation.
Walk forward testing adds repetition. Instead of one verdict, you get six, ten or twenty independent OOS segments, each traded with settings chosen only from the data before it. If the process has a genuine edge, most of those segments should be profitable, or at least the combined curve should be. If the process only fits noise, the OOS segments will look random or worse.
It also matches reality. Many traders re-optimise their EA every few months. Walk forward testing simulates exactly that routine, so its results describe the thing you will actually do live.
The mechanics, step by step
- Choose the in-sample (IS) length. Long enough to contain plenty of trades and varied conditions, for example two years.
- Choose the out-of-sample (OOS) length. Commonly a quarter to a third of the IS length, for example six months.
- Optimise on the first IS window using a fixed, pre-decided selection rule (more on this below).
- Run those settings on the following OOS window without any changes. Record every trade.
- Shift both windows forward by the OOS length and repeat until you run out of data.
- Stitch together all the OOS trades into one equity curve and analyse it.
Rolling versus anchored windows
In a rolling walk forward, the IS window keeps the same length and slides forward, so old data drops out. In an anchored walk forward, the IS window always starts at the beginning of the data and grows longer each step. Rolling windows adapt faster to changing markets but use less data per optimisation. Anchored windows give more stable parameter estimates but may hold on to conditions that no longer apply. Neither is correct in general; pick the one that matches how you intend to re-optimise live, and decide before you look at results.
A worked example with six windows
The figures below are illustrative, built to show how to read a walk forward report, not results from any real EA. Imagine a trend-following EA on EUR/USD H1 with two optimised inputs: a breakout lookback and an ATR stop multiple. Data runs from January 2019 to December 2024. IS windows are 24 months, OOS windows are 6 months, rolling.
| Run | In-sample period | Out-of-sample period | Chosen lookback / ATR multiple | IS net (pips per year) | OOS net (pips, 6 months) | OOS trades |
|---|---|---|---|---|---|---|
| 1 | Jan 2019 to Dec 2020 | Jan to Jun 2021 | 40 / 2.5 | +620 | +140 | 38 |
| 2 | Jul 2019 to Jun 2021 | Jul to Dec 2021 | 40 / 2.5 | +580 | +60 | 35 |
| 3 | Jan 2020 to Dec 2021 | Jan to Jun 2022 | 50 / 3.0 | +540 | +310 | 31 |
| 4 | Jul 2020 to Jun 2022 | Jul to Dec 2022 | 50 / 3.0 | +700 | +180 | 33 |
| 5 | Jan 2021 to Dec 2022 | Jan to Jun 2023 | 50 / 2.5 | +760 | -150 | 40 |
| 6 | Jul 2021 to Jun 2023 | Jul to Dec 2023 | 45 / 2.5 | +520 | +20 | 36 |
Reading the table
Combined OOS result. Adding the OOS column gives +560 pips over three years of unseen data, about +187 pips a year, from 213 trades. That is the number that matters, and it is far below the 520 to 760 pips a year the IS windows showed. That gap is normal; IS results are inflated by selection.
Walk-forward efficiency (WFE). A common measure is annualised OOS return divided by annualised IS return. Here the average IS figure is about 620 pips a year and OOS is about 187, so WFE is roughly 30%. Practitioners often look for WFE above roughly 50% to 60% as a sign that the optimisation transfers well, though there is no universal threshold and the figure depends heavily on how inflated the IS numbers are. At 30%, this process is losing most of its apparent edge out of sample.
Consistency. Five of six OOS windows were positive, and one was a modest loss. That is more encouraging than a single large win surrounded by losses.
Parameter stability. The chosen lookback moved between 40 and 50, and the ATR multiple between 2.5 and 3.0. Stable choices suggest the optimiser is finding the same broad region each time. If the lookback had jumped from 15 to 90 to 30, the "best" setting would be noise and the OOS results would be closer to chance.
Sample size. Around 35 trades per OOS window is thin. Individual windows say little; only the combined 213 trades carry weight, and even that is a modest sample. Converting the result into money needs costs: if the IS and OOS figures already include spread and commission, fine; if not, subtract roughly 1 pip per trade, which here would remove about 213 pips, over a third of the OOS total.
A reasonable verdict on this illustrative EA: a possible but thin edge, not ready for meaningful capital, worth a longer forward test on demo.
Designing the test so it cannot fool you
Fix the selection rule in advance
The setting chosen in each IS window should come from a rule you wrote down before starting, for example "highest profit factor among combinations with at least 100 trades and maximum drawdown under 15%", or better, "centre of the most stable region on the heat map". If you look at OOS results and then change the rule, you have optimised on the OOS data.
Do not optimise the window lengths
It is tempting to try IS lengths of 6, 12, 18 and 24 months and keep whichever gives the best walk forward. That is just another layer of curve fitting. Choose window lengths from reasoning: how often you will re-optimise live, how many trades the strategy produces, and how long typical market regimes last.
Make every OOS window count
For a strategy trading five times a month, a three-month OOS window holds 15 trades, which is mostly noise. Either lengthen the windows or accept that you need more of them. The combined OOS curve should ideally contain several hundred trades before you draw firm conclusions.
Use realistic costs and data
Walk forward testing does not fix bad inputs. If the tester uses a fixed spread or generated ticks, every window inherits the flaw. Use real or variable spreads, include commission and slippage, and prefer tick-based modelling for strategies with tight stops.
How to run a walk forward in MetaTrader 5
MetaTrader 5's Strategy Tester has a "Forward" setting that splits the date range into an optimisation period and a forward period (half, a third, a quarter, or a custom date). That gives you one IS/OOS pair per run. To build a full walk forward manually:
- Set the tester dates to cover IS plus OOS for run 1, with a custom forward date at the boundary.
- Run the optimisation with your fixed criterion and note the chosen settings and the forward result.
- Save the forward trade report.
- Move both dates forward by the OOS length and repeat.
- Combine the forward trade lists in a spreadsheet to build the stitched curve.
Our guide on backtesting an EA in MT5 explains the tester settings in detail. Six manual runs are fine; twenty become tedious and error-prone. MT5 can be scripted, and some traders automate the loop in Python with the MetaTrader 5 package or external tools (see building forex bots in Python). Several dedicated testing platforms include built-in walk forward matrices that run many IS/OOS combinations at once; our comparison of backtesting software notes which ones do. Be careful with walk forward matrices: running dozens of window configurations and highlighting the best is the same multiple-testing problem in a new form.
What to do after the walk forward
If the stitched OOS curve is weak or negative, discard or rethink the system. Changing a filter and rerunning until it passes defeats the purpose.
If it is acceptable, three further steps are worth the time:
- Monte Carlo the OOS trades. Reshuffling and resampling the stitched trade list estimates the range of drawdowns you could face. See Monte Carlo simulation for forex.
- Forward test live on demo with the same re-optimisation schedule. A demo account costs nothing and exposes execution issues the tester cannot.
- Size from the OOS drawdown, not the IS one. If the worst OOS drawdown was 12% at 1% risk per trade, plan for worse than 12% live and size so that is tolerable.
| Walk forward outcome | Reasonable next step |
|---|---|
| Combined OOS negative | Reject the system or the optimisation approach |
| Combined OOS positive but WFE low and parameters unstable | Treat as unproven; simplify the system and retest on fresh data |
| Combined OOS positive, most windows positive, stable parameters | Monte Carlo the trades, then forward test on demo for several months |
| OOS better than IS | Check for bugs or look-ahead bias before believing it |
If you are newer to systematic trading, the broader workflow is set out in algorithmic forex trading for beginners.
Frequently asked questions
What is a good walk-forward efficiency for a forex EA?
Many practitioners look for walk-forward efficiency above roughly 50% to 60%, meaning out-of-sample performance retains at least half of the in-sample rate. There is no official standard, and the figure depends on how inflated the in-sample numbers are. Consistency across windows and a positive combined out-of-sample curve matter more than any single efficiency number.
How long should in-sample and out-of-sample windows be?
A common starting point is an out-of-sample window a quarter to a third the length of the in-sample window, for example 24 months and 6 months. The real constraint is trade count: each in-sample window needs enough trades to optimise meaningfully, and the combined out-of-sample segments ideally several hundred trades. Decide lengths before testing, not by trying several.
Is anchored or rolling walk forward better?
Neither is universally better. Rolling windows discard old data and adapt faster, which suits strategies sensitive to changing volatility. Anchored windows use all past data and give steadier parameters, which suits slower strategies. Choose the version that matches how you plan to re-optimise the EA in live trading.
Can MetaTrader 5 do walk forward testing automatically?
MetaTrader 5's tester supports a single forward period per optimisation run, not a full rolling walk forward. You can repeat runs manually with shifted dates, script the process, or use third-party software that automates multiple windows. Combine the forward trade lists yourself to build the stitched out-of-sample equity curve.
What is the difference between walk forward testing and forward testing?
Walk forward testing is a historical procedure: repeated optimise-then-test cycles on past data. Forward testing usually means running the EA in real time on a demo or small live account after development. Both are useful. Walk forward testing is quick and rejects weak ideas; real-time forward testing reveals execution, slippage and operational problems.
This article is general information, not personal financial advice. Figures such as spreads, fees, leverage and rules change; confirm them with the provider and check the provider is authorised for your country of residence.