Ready to go further
Next: see why optimised numbers do not carry forward
The overfitting guide explains why the best settings in a backtest are not a forecast, and how to spot a curve that was fitted to noise.
What is included
- What it is, in plain words
- The formula or mechanism, with exact arithmetic
- How it hits grid, martingale and DCA bots
- A check you can run before you switch a bot on
Who it is for
- People who run or plan to run a trading bot
- Anyone reading a backtest or a bot sales page
- Readers who want the numbers, not the pitch
- Not advice, and not a signal service
Key facts
- Walk forward testing splits history into repeated pairs of windows: an in-sample window where settings are optimised, then an out-of-sample window where those settings are traded untouched.
- The out-of-sample windows, joined end to end, make one record that no setting was ever tuned on. That joined record is the result that counts.
- In the made-up example below the in-sample windows averaged 19.5 percent per 12 months, but the out-of-sample windows averaged 1.2 percent per 3 months, and 2 of 6 lost money.
- Walk forward efficiency compares the out-of-sample result with the in-sample result. A low figure is the classic sign of overfitting.
- It still can be fooled: the rules, the markets and the window lengths are chosen by a person who has seen the data.
What walk forward testing is
A normal backtest takes one stretch of history, tries many settings and keeps the best. The best settings are then reported as if they were a forecast. They are not. They are the settings that happened to fit that one stretch, noise included. This is overfitting.
Walk forward testing repeats a smaller, fairer test many times:
- Step 1. Take an in-sample window, for example 12 months. Optimise the settings on it.
- Step 2. Take the next out-of-sample window, for example 3 months. Trade it with the settings from step 1 and change nothing.
- Step 3. Move both windows forward by the length of the out-of-sample window and repeat.
- Step 4. Join all the out-of-sample windows into one record and judge that.
The key point is that every number in the final record came from settings chosen before those bars happened. The optimiser never saw them. That is what a single backtest cannot say.
Anchored and rolling windows
There are two common layouts. In a rolling walk forward the in-sample window keeps the same length and slides forward, so old data drops off the back. In an anchored walk forward the start stays fixed and the in-sample window grows. Rolling adapts faster when markets change. Anchored uses more data per fit. Neither is correct for every strategy, and the choice is one more setting that someone picked.
An efficiency near 100 percent says the settings held up on new data. An efficiency well under 50 percent, or a negative one, says most of the in-sample result was fit to noise. The cut-off people quote varies, so treat it as a rough guide and not as a pass mark.
A worked example with six windows
This is a made-up bot. It is optimised on 12 months, then traded for 3 months, six times in a row. The in-sample figures are the best result the optimiser found in each window, converted to a 3-month equivalent by dividing by 4, which is a simple scaling and not a forecast.
| Window | In-sample, 12 months | In-sample per 3 months | Out-of-sample, 3 months |
|---|---|---|---|
| Window 1 | +18.0% | +4.5% | +4.0% |
| Window 2 | +22.0% | +5.5% | -3.0% |
| Window 3 | +15.0% | +3.8% | +6.0% |
| Window 4 | +25.0% | +6.3% | -5.0% |
| Window 5 | +20.0% | +5.0% | +2.0% |
| Window 6 | +17.0% | +4.3% | +3.0% |
| Average | +19.5% | +4.9% | +1.2% |
Calculated by us on 29 Oct 2026, exact arithmetic on made-up inputs. The optimiser found an average of 19.5 percent per 12 months, or 4.875 percent per 3 months. Traded on unseen data, the same settings made 1.167 percent per 3 months. Walk forward efficiency is 1.167 / 4.875 = 23.9 percent (rounded). Windows 2 and 4 lost money.
Starting each record at $1,000, the in-sample numbers scaled to 3 months would have reached $1,330 after six windows. The out-of-sample record reached $1,067. The gap between those two lines is the part of the optimised result that did not survive contact with new data.
How it hits bots
- EAs with many inputs. A bot with ten adjustable settings can be fitted to almost any history. Walk forward tests whether the fitting method works, not whether one set of numbers is lucky. See expert advisors.
- Grid and martingale bots. Their step size and multiplier look excellent in the window that never had a long trend. A walk forward window that contains a trend shows the cost. See martingale and grid trading.
- Machine learning bots. Retraining on a rolling window is a walk forward process by design, and the same checks apply to it.
- Costs. Spread, commission and slippage must be inside every window, or the out-of-sample record is flattered too.
How to check a walk forward result
- Judge only the joined out-of-sample record. If the report leads with in-sample figures, it is the wrong report.
- Count the windows. Six windows is a small sample. A good average over six can still be luck. Look at how many windows made money and how bad the worst one was.
- Look at the settings between windows. If the best settings jump around from window to window, the strategy has no stable shape to find.
- Do not re-run until it passes. Changing the window lengths or the rules after seeing the result puts the future data back into the choice. Each re-run spends a little of the out-of-sample honesty.
- Follow with a forward test. The step after walk forward is trading live data in real time with no changes. See forward testing.
What it does not tell you
Walk forward testing cuts down overfitting. It does not remove it. The person running it picked the market, the rules, the window lengths and the measure to optimise, usually after looking at the same history. That is a quiet form of look-ahead choice. It also cannot see events that are not in the data, such as a regime that has not happened yet, and it says nothing about survivorship in the markets chosen. A passing walk forward is evidence that a method was not obviously fitted. It is not evidence about the future.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
What is walk forward testing?
A method that optimises a strategy on one window of history, trades the next window with those settings untouched, then rolls both windows forward. The joined out-of-sample windows form the result.
What is the difference between in-sample and out-of-sample?
In-sample data is what the settings were fitted to. Out-of-sample data is what they were not. Only the out-of-sample result says anything about how the settings behave on new data.
What is walk forward efficiency?
The out-of-sample return divided by the in-sample return, over the same length of time. A low or negative figure suggests the in-sample result was fitted to noise. Cut-offs people quote vary, so use it as a rough guide.
Does passing a walk forward test mean a bot will work?
No. It shows the method was not obviously overfitted on that history. Markets change, the sample can be small, and the choices of rules and windows were made by someone who had seen the data.
How long should the windows be?
There is no single correct length. The in-sample window needs enough trades to fit on, and the out-of-sample window needs enough trades to judge. Very short windows give noisy results, so check how many trades each one holds.
Are the numbers on this page real?
Example numbers are made up to show how the maths works, and the page says so. A figure only counts as exact when the page says it was calculated on a stated date. Nothing you enter in a calculator leaves your browser.
Can I use this to decide whether to run a bot?
It can show whether a bot's numbers hold together and how much an account can lose. It cannot say what the market will do, and it is not advice. Use it to ask better questions, then read the terms of your own broker or exchange.
Is this financial advice?
No. It explains a testing method in general terms. The example is made up and no result here predicts any real bot.
Know the Risk Before You Run It
Free calculators and guides, added every week. Leave your details and we will email you when new ones go up.
Trading carries a risk of loss