Category
Performance
Difficulty
Advanced
Used in
BacktestingStrategy designMT5 operation

Walk-forward analysis

A validation method that re-optimises a strategy on one window of history, trades those settings untouched on the window that follows, then slides both windows forward and repeats — quoting only the untouched segments.

also: WFA, walk-forward optimisation, WFO, rolling out-of-sample test

Updated · Reviewed · Reviewed by mt5depot research desk

In plain English

Tune the rules on one stretch of history, trade them untouched on the stretch that follows, then slide both stretches along and do it again. Only the untouched stretches count towards the number you quote.

Why it matters

A single out-of-sample test answers one question once. Walk-forward asks it again at every step, which is the only way to see whether an edge keeps surviving re-fitting rather than surviving it once by luck. It also rehearses what a deployer actually does: pick parameters from the recent past, then run them into a future nobody has seen.

  • It scores the procedure, not a setting. 'Re-fit this way, then trade' is what you will really do, so that is the thing worth validating.
  • It returns a series of out-of-sample results instead of one number, so a single flattering quarter cannot carry the claim on its own.
  • It exposes inputs that refuse to sit still. When every re-fit lands somewhere new, the rules track the sample rather than the market.
  • One hold-out hides the regime question. Two of our eight recorded searches passed the window after the search and then failed the window before it.

Using it to validate a strategy

Where it is used

  • Validating a strategy whose inputs you genuinely intend to re-fit on a schedule.
  • Choosing the re-optimisation interval — how long one set of inputs stays usable before it needs a refresh.
  • Separating an edge that survives several regimes from one that only ever existed in the window it was tuned on.
  • Building a defensible out-of-sample record when the history is too short to surrender one large reserved block.

What a reliable result looks like

  • Only the out-of-sample segments make up the headline, joined end to end, with the in-sample figures beside them rather than blended in.
  • You fixed the training length, the testing length and the step before the first run, and all three travel with the result.
  • The write-up quotes out-of-sample efficiency — out-of-sample performance as a share of in-sample — and not just the profit.
  • Every step lists the inputs it selected, so a reader can judge how far they wander.
  • The count of walk-forward configurations tried appears somewhere, because trying many is itself a form of fitting.

Warning signs

  • One combined figure, with no split between the in-sample and out-of-sample halves.
  • Window lengths that look tuned: an odd training-to-testing ratio that nobody explains.
  • Inputs that jump at every re-fit, which means each fit chases the last window's noise.
  • Efficiency near or above 100%, which points to a leak between the windows far more often than to an unusually robust strategy.
  • Anchored and rolling variants quoted interchangeably, since a growing window and a fixed one answer different questions.

Backtest vs live trading

  • Walk-forward closes part of the gap to live results because the tested procedure is the deployed procedure.
  • It leaves execution risk untouched. Slippage, spread widening and latency all sit outside the exercise.
  • It cannot invent regimes the history never held, so a strategy that survives twenty re-fits inside one calm decade remains untested against a stressed one.
  • Expect live results near the out-of-sample series rather than the in-sample one. In-sample figures diagnose the search; they forecast nothing.

Recommended validation method

  1. 1MetaTrader 5 ships no rolling walk-forward. The Strategy Tester's Forward field on the Settings tab cuts the interval once — 1/2, 1/3, 1/4 or a custom date — and scores the surviving passes on the tail in a separate Forward Results tab. One run buys one step.
  2. 2Build the series by hand: repeat the optimisation once per step, each with its date range shifted by the step length, and keep the forward row from each. Twenty segments cost twenty runs, so settle the step count before you start.
  3. 3Choose the optimisation criterion before you look at the grid, because it decides which pass MT5 calls the winner at every single step. Custom max routes that decision through OnTester() when no built-in criterion matches how you judge a run.
  4. 4MT5 always cuts its forward slice off the end of the range, so the window immediately before the training period never faces a test. Run that one yourself: on our own set it caught two designs that the forward check had already waved through.
  5. 5Log the winning inputs step by step. The Forward Results tab hands you a pass, never the trajectory of the settings across steps — and that trajectory is the finding.
  6. 6Treat the whole exercise as one experiment. Re-running it with fresh window lengths until it passes moves the overfitting up a level instead of removing it.

Example

One step, from our own recorded work: the eight parameter searches in EXP-PARAM-SEARCH-OUTCOMES-001. The ichimoku template searched a 12-combination grid on H1, kept its best in-sample pass, and then met two windows the search had never touched.

Grid searched
12 combinations
SL 30-80 x TP 60-250, H1
In-sample profit factor
1.37
Window after the search
0.89
Window before the search
0.80
Searches recorded / adopted
8 / 0

65% lands inside the band most write-ups call strong. The same setting still lost money on both unseen windows, which is why one step reads as a data point and never as a verdict.

Calculation 0.89 divided by 1.37 = 65% efficiency on the step; 0.80 divided by 1.37 = 58% on the earlier window

Result 65% efficiency — on a setting we refused to ship

How to interpret it

Read the out-of-sample series first, then the ratio, then the stability of the inputs. Headline profit is the least informative of the three.

Range What it means
Below roughly 40% The search mostly fitted its own window. A small edge may survive, but not the advertised one.
Roughly 40-60% Ordinary once several inputs move. Plan around the out-of-sample figure, not the in-sample one.
Above 60% on a single step Encouraging, not a verdict. Our 65% step still lost on both windows it had not seen.
Above 60% across most steps, inputs stable Strong. The re-fits keep working and they agree about the settings.
Near or above 100% Suspect a leak between windows, a look-ahead, or too few segments to carry meaning.
  • Count the segments. Four segments is an anecdote; twenty is a distribution.
  • Chart the selected inputs across steps. An optimum that wanders is telling you it is noise.
  • Never blend in-sample and out-of-sample equity into one curve: that blend is part exam, part answer key.
  • Test the window before the training period as well. Two of our eight searches passed forward and failed backward.

mt5depot publishes the data window, tester model and trade count behind every run, so any out-of-sample claim here can be checked against the sample that produced it.

Common mistakes

Calling one MT5 Forward run a walk-forward

The Forward field splits the interval once and reports the tail. That is a single anchored hold-out with a tidier tab, and it answers the question once. Walk-forward needs the split to move, which in MT5 means driving the loop yourself: one optimisation per step, then collecting the forward rows into a series.

Tuning the walk-forward configuration itself

Searching several training and testing lengths, then publishing whichever pairing scored best, simply relocates the overfitting one level higher. The window lengths are parameters as well, so choose them, write them down, and then run.

Reading a high out-of-sample number as automatically good

Our macd_signal search reached 1.14-1.15 on the window after the search and 0.74-0.77 on the window before it. High out-of-sample numbers can mean a leak, a favourable regime, or too few segments — investigate before celebrating.

Assuming walk-forward proves robustness against unseen conditions

It only ever tests conditions the history contained. Twenty re-fits inside one regime produce twenty results from that regime, which says nothing about the next one.

In depth

Frequently asked questions

How do you run a walk-forward analysis in MetaTrader 5?
MT5 gives you the pieces rather than the loop. Set Forward on the Strategy Tester's Settings tab to 1/2, 1/3 or 1/4: the tester optimises on the front of your date range and scores the surviving passes on the tail, which it lists in its own Forward Results tab. That is one step. For a series, shift the whole date range forward by the step length and run the optimisation again, once per segment, recording the forward row and the winning inputs each time. Twenty segments means twenty runs.
What should the in-sample and out-of-sample window lengths be?
Long enough that the training window holds more than one regime and the test window holds enough trades to mean anything. The tester's built-in ratios of 1/2, 1/3 and 1/4 make sensible starting points, and a custom forward date gives a shorter test slice when the step is small. The rule matters more than the numbers: pick the ratio before the first run, because trying several and publishing the best repeats the mistake walk-forward exists to catch.
Does walk-forward analysis eliminate overfitting?
No. It relocates it and makes it visible. The re-fitting still happens inside each training window, so the method measures how much of that fitting survives contact with the next window instead of preventing it. Our own eight recorded searches ran 116 parameter combinations and adopted none: two of them cleared the window after the search and then failed the window before it, which is exactly the pattern a single hold-out hides.
What counts as a good out-of-sample efficiency?
Roughly 40-60% is ordinary once a handful of inputs move, and figures above 60% held across most steps with stable inputs count as strong. Treat any single step with suspicion: our best-fitting search read 65% on one step and its chosen setting still lost money on both windows it had not seen. A figure near or above 100% more often signals a leak between the training and testing windows than an unusually robust strategy.
Which optimisation criterion should rank the passes?
Decide before the grid appears, because the criterion — the objective function, in the wider literature — picks the winning pass at every step. Balance-based ranking rewards whichever pass took the most risk, drawdown-based ranking rewards whichever traded least, and Custom max hands the decision to your own OnTester() when neither fits. In our recorded searches the tester's ranking never settled anything on its own: every surviving pass then had to hold a profit factor above 1.0 on three windows, and not one of the eight managed it.
How does walk-forward differ from a single out-of-sample test?
A single test reserves one block of data and checks the final parameters against it once. Walk-forward repeats the tune-then-test cycle along the whole history, so it returns a series of out-of-sample results and tests the re-fitting procedure itself — the thing a deployer actually performs month after month.