Advertisement IC Markets

Walk-forward testing explained with a simple example

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 975
Joined: Sun Oct 18, 2026 12:25 pm

Walk-forward testing explained with a simple example

Post by FXS London Scalper »

Optimising an EA on historical data often produces parameters that fit the past but fail in the future. Walk-forward testing is one way to check whether optimisation generalises.

A simple version: split data into consecutive windows, for example two years for optimisation followed by six months for testing. Optimise on the first window, apply the best parameters to the next six months without changes, record the result. Then move both windows forward and repeat.

A worked example: across five windows, the optimised results might show strong profits each time, while the out-of-sample periods show mixed results. That gap measures how much of the optimisation was curve fitting.

If out-of-sample results are consistently positive, though smaller, the strategy may have a real edge. If they hover around zero, the optimisation was likely fitting noise.

MetaTrader 5 includes a forward testing option, though a manual walk-forward gives more control.

Has anyone run walk-forward tests on their EAs?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Walk-forward testing explained with a simple example

Post by Shadow Trader »

Walk-forward testing is one of those ideas that sounds technical but is really just honesty about the future. Thanks for laying it out with windows, because that's the part people usually find confusing.

A couple of practical things are worth adding for anyone trying it for the first time.

The first is to look at how stable the chosen parameters are from window to window, not just at the out-of-sample profit. If the best moving average length jumps from 12 to 47 to 20 across consecutive windows, the optimisation is probably finding noise even if a couple of the out-of-sample periods happen to be positive. If the best values sit in the same neighbourhood each time, that's a much better sign.

The second is to be careful about how many times you re-run the whole process. If you try ten different strategy ideas through walk-forward and keep the one that looks best, you've effectively optimised on the out-of-sample periods too. It's easy to do without noticing, so it helps to decide in advance what counts as a pass.

The third is about window length for scalping systems. Short-term strategies can produce enough trades to use shorter windows, which is good, but market conditions also shift within a year, so a window that includes a very volatile period and a very quiet one can give parameters that suit neither. Some people split results by volatility regime as well as by time, which gives a better idea of when the system can be expected to struggle.
Post Reply