Optimization

Walk-Forward Optimization Explained

Walk-forward analysis repeatedly optimises on one window and tests on the next. Rolling vs anchored windows, choosing window sizes, walk-forward efficiency and how to read the stitched result.

By AlgoXP4 min readUpdated

Walk-forward analysis: rolling in-sample optimization windows each followed by an out-of-sample test

A single in-sample/out-of-sample split gives one verdict on one period. Walk-forward analysis repeats the split many times as it moves through history: optimise on a window, test on the period right after it, step forward, and repeat. The out-of-sample pieces are then stitched together into one equity curve that was never seen by the optimiser.

It is the closest a historical test gets to the way strategies are actually used: you tune on the past, then trade an unknown future, then re-tune.

How it works

  1. Choose the window sizes - for example, 24 months in-sample (IS) and 6 months out-of-sample (OOS).
  2. Optimise the strategy on the first IS window.
  3. Apply the chosen parameters to the following OOS window and record the trades.
  4. Move forward by the OOS length and repeat.
  5. Stitch all OOS segments together and evaluate them as one result.

With data from 2016 to 2025, a 24/6 walk-forward produces about 16 runs. The stitched OOS result covers six and a half years, every trade of it made with parameters chosen without seeing that period.

Rolling vs anchored

Rolling (sliding) windows keep the IS length constant: the oldest data drops out as new data is added. They adapt faster to changing behaviour but can be noisier.

Anchored windows always start at the beginning of the data and grow. They produce more stable parameters but react slowly to structural change.

Rolling Anchored
Adapts to recent markets Faster Slower
Parameter stability Lower Higher
Sensitive to old regimes Less More

Choosing window sizes

There is no universal answer, but some guidance:

  • The IS window must contain enough trades for the optimisation to mean something - ideally well over 100 for the strategy being tuned.
  • The OOS window is usually 20-35% of the IS length: long enough to collect trades, short enough that re-optimisation keeps up with changes.
  • Longer holding periods need longer windows.

Test two or three window combinations. If results depend heavily on the exact choice, that dependency is a finding in itself.

Measuring the result

Stitched OOS equity curve. The main output. Judge it with the usual metrics: expectancy, maximum equity drawdown, profit factor, trade count.

Walk-forward efficiency (WFE). Compare annualised OOS performance with annualised IS performance:

WFE = OOS annual return / IS annual return

An efficiency around 0.5 or higher suggests a meaningful share of the optimised edge survives on new data. Near zero means the optimisation found mostly noise.

Share of profitable OOS windows. If 12 of 16 windows are profitable, the edge is reasonably consistent. If two windows produce all the profit, it is not.

Parameter drift. Plot the chosen parameters for each run. Stable or slowly moving values are a good sign. Values that jump across the whole range from run to run mean the optimiser is chasing noise.

A worked example

A trend-following cBot on XAUUSD H1 is analysed with 24-month IS and 6-month OOS rolling windows from 2016 to 2025:

  • In-sample results average 28% per year.
  • The stitched OOS curve returns 13% per year with a 17% maximum drawdown.
  • WFE is about 0.46; 11 of 15 OOS windows are profitable.
  • The optimised trend length moves between 80 and 140 and never jumps to the edges.

Conclusion: the strategy keeps roughly half of its optimised performance on unseen data, with a consistent edge and stable parameters - a credible candidate for forward testing. Expect live results nearer the OOS figures, not the IS ones.

Limitations

  • It is still history. Walk-forward reduces selection bias but cannot remove regime change.
  • It needs data. Many runs with meaningful trade counts require long histories, especially for slow strategies.
  • It can be gamed. Trying many window sizes and choosing the best one reintroduces the same selection problem one level higher.
  • Re-optimisation must be practical. If live you will not re-optimise every six months, test the schedule you will really use.

Doing it on cTrader

cTrader’s optimiser runs one optimisation over the date range you set, so walk-forward is done as a manual routine: optimise on the IS dates, apply the chosen pass, backtest the OOS dates, record the result, move both ranges forward. Saving each optimisation’s results and keeping a simple table of runs makes the process repeatable. For larger studies, the cTrader CLI can run optimisations and backtests from scripts.

Key takeaways

  • Walk-forward analysis repeats optimise-then-test through history.
  • The stitched out-of-sample curve is the honest result; in-sample numbers are not.
  • Check walk-forward efficiency, consistency across windows and parameter drift.
  • Avoid optimising the walk-forward settings themselves.

Related: over-optimisation and Monte Carlo simulation.

FAQ

What is walk-forward efficiency?

The ratio between out-of-sample and in-sample performance, usually annualised. A value around 0.5 or higher suggests that a meaningful part of the optimised performance carries over to new data. Values near zero or negative point to overfitting.

Rolling or anchored windows?

Rolling windows drop old data and adapt faster to changing markets. Anchored windows keep all history from the start and give more stable parameters. Run both if you can; if they disagree strongly, the strategy is sensitive to which history it learns from.

How many walk-forward runs do I need?

Enough out-of-sample segments to cover different market conditions and to collect a meaningful number of out-of-sample trades - often at least 6-10 runs.

Sources and further reading

  1. Bailey et al.: The Probability of Backtest Overfitting - papers.ssrn.com
  2. cTrader Help: Optimise a cBot - help.ctrader.com