Walk-forward testing: Why a backtest that looks great can fail on the next window

Every optimized backtest has a flaw built into it: the parameters were chosen after the data was already known.
Suppose you test a EUR/USD rule with 10 lookback lengths and 6 band widths. That is 60 versions, and you keep the one at the top. The winner is partly a good rule and partly the version whose quirks happened to line up with the noise in that particular stretch of prices.
The backtest cannot tell you how large each part is. The next window of data can.
Walk-forward analysis is a standard way to ask the next window. It does not throw optimization away. It tests the habit of optimizing, by repeating the choose-then-trade cycle the way you would actually live through it.
This article explains how the method works, walks through a hypothetical example step by step, and shows how to size the windows and read the results before you trust a strategy.
Only the unseen windows go on the record
The history is split into consecutive blocks. The in-sample window is the stretch the optimizer is allowed to see when it picks the parameters. The out-of-sample window is the stretch that comes right after it, where the chosen parameters are traded without any change.
When that out-of-sample block is finished, both windows move forward by its length and the cycle starts again.
At the end, only the out-of-sample blocks are joined into one equity curve. Every trade on that curve was taken with a setting chosen before the trade's data existed, which makes it the closest thing a backtest can offer to a real track record.
Robert Pardo describes the method at length in The Evaluation and Optimization of Trading Strategies, and the efficiency ratio used below comes from the same book.
An illustrative example: Five windows, one forecast record
The numbers in this section are hypothetical and only show how the reading works. Assume a mean-reversion rule on EUR/USD hourly bars with two parameters, a lookback length and a band width. Each in-sample window is 24 months, each out-of-sample window is 6 months, and the windows roll forward. Results are in pips after costs.
Window | Setting picked in-sample | In-sample result (24 months) | Out-of-sample result (6 months) |
1 | 20 / 2.0 | +1,140 | +160 |
2 | 20 / 2.0 | +1,260 | -90 |
3 | 30 / 2.0 | +1,020 | +210 |
4 | 30 / 2.5 | +1,320 | +40 |
5 | 30 / 2.5 | +1,200 | +120 |
Read it one row at a time. Every in-sample figure looks excellent, between about 42 and 55 pips a month. That is what an optimizer always delivers, because it gets to pick.
The out-of-sample column is the forecast record, and it is much quieter: four of five windows positive, one losing window, and 440 pips in total over 30 months.
Efficiency shows how much survived
Walk-forward efficiency puts the two columns on the same scale. The windows have different lengths, so compare monthly rates rather than totals:
Walk-forward efficiency = (out-of-sample profit / out-of-sample months) / (in-sample profit / in-sample months)
Out of sample, 440 / 30 = 14.7 pips a month. In sample, 5,940 / 120 = 49.5 pips a month. The efficiency is 14.7 / 49.5, or about 30%.
So roughly 70% of the in-sample performance did not survive contact with unseen data.
Many traders treat an efficiency of half or more as acceptable, and a small fraction as a sign that the optimizer was mostly fitting noise. These are working thresholds rather than laws, but 30% would make most careful traders slow down.
The rule may still have an edge, since the joined out-of-sample result is positive. It is simply a much smaller edge than any single optimized backtest would have suggested.
Two more readings from the same table
There is a second number worth computing and then setting aside. Suppose the one setting that looks best over the whole 54 months would have made 1,100 pips over the same 30 out-of-sample months.
That figure is a ceiling, not a result. In window 1 nobody could have known which setting would look best four and a half years later. Judging a strategy by its whole-history optimum is exactly the mistake the test exists to prevent.
The parameter history is worth a look as well: 20/2.0, 20/2.0, 30/2.0, 30/2.5, 30/2.5. The picks move between neighbouring values instead of jumping across the grid, and that stability is a good sign in its own right.
If the picks had wandered from one end of the ranges to the other, the out-of-sample total would deserve less trust even if it were positive.
Size the windows by trades, not by the calendar
The right in-sample length depends on trade count. Twenty-four months means little for a daily E-mini S&P 500 (ES) strategy that trades twice a month, and a great deal for an intraday strategy that trades every session.
As a rough guide, the optimizer needs at least 30 to 50 trades in each in-sample window, and more when the rule has more parameters. With fewer, the winning setting is often just the one that happened to dodge two or three losing trades.
Keep the out-of-sample window at roughly one third to one fifth of the in-sample length, and match it to how often you would really re-tune. If you would re-optimize every six months in live trading, test with six-month windows.
Aim for at least four or five out-of-sample windows. One window is a single verdict that could be lucky or unlucky, and with only one or two you cannot count wins and losses.
Rolling windows drop the oldest data at each step. Anchored windows always start at the first bar and keep growing. Test the version that matches your live habit, then run the other one.
If both give similar results and similar picks, the strategy is not sensitive to that choice, which is one more point in its favour.
What walk-forward cannot fix
Walk-forward analysis removes hindsight inside each window. It does not remove hindsight applied to the walk-forward runs themselves.
If you try twenty combinations of window lengths, objectives and parameter ranges and then report the best joined result, that result is no longer out of sample, because you selected it after seeing it.
The defence is plain bookkeeping. Write down the objective, the parameter ranges, the selection rule and the window lengths before the first run, and count every run, including the ones you discard.
If you test a small grid of window lengths, judge the whole grid. Most cells behaving alike is reassuring; one bright cell in a dull grid is a warning.
Takeaway
Before trusting an optimized backtest, fix the selection rules in advance, judge only the joined out-of-sample windows, compare their monthly rate with the in-sample rate, and check that the chosen settings stay close to one another.
A positive walk-forward result promises nothing about next year. It shows that a specific re-tuning process held up on the history you tested, with the costs you included.
That is still far more useful than an optimized backtest, because it is the only backtest number you could actually have traded.
This content was partially created by an AI tool.
Author

Soren Huang
MultiAlphas by Valynox
Soren Huang is the founder of Valynox and the lead developer of MultiAlphas. He began teaching himself futures trading at seventeen, later moved into algorithmic trading, and has specialised in futures strategy development for more than 15 years.
















