Home > Blog > Walk-Forward Analysis

Walk-ForwardOptimizationCurve FittingBacktestingMT5

Walk-Forward Analysis

Published: 2026-10-02Read time: about 3 min
⏱ This article reflects information as of its publish date. EA performance figures (PF, DD, annual return) change with live trading and re-validation — check the latest on the EA pages. See the latest EA results →

Walk-Forward Analysis: Preventing Curve Fitting in EA Optimization

When you optimize parameters in the MT5 Strategy Tester, the tool finds the parameter set that performed best on historical data.

The catch is that those "best parameters" may have been overfit to past data (curve fitting) and will not hold up in live trading. Walk-forward analysis is the method used to guard against this kind of over-optimization.

Key takeaways

  • Split the data into an optimization window (in-sample) and a validation window (out-of-sample) at 70:30, and repeat this in chronological sequence
  • A WFE (Out-of-Sample PF ÷ In-Sample PF × 100%) of 60% or higher is the passing threshold
  • Limit optimization variables to 1–2, and adopt the median of the top cluster rather than the top-ranked set

Walk-Forward Analysis Steps (Overview)

StepWhat to doGuideline
1Limit optimization variables to 1–2e.g., EMA period only
2Optimize on the in-sample window5–7 years
3Select the top parameter setsThe median of the top 20% cluster, not the top-ranked set
4Backtest on the out-of-sample window2–3 years (ratio 70:30 to 80:20)
5Calculate WFE and judge≥ 60% passes; < 40% suggests curve fitting
6Shift the windows and repeat steps 2–5Whether PF is positive in every validation window

📧 Free 8-email course + subscriber-only pack of 13 MT5 indicators

Right after you sign up, you get a download link for a subscriber-only pack of our 13 MT5 indicators: compiled files (.ex5), source code and a setup guide. Then 8 emails on algo-trading essentials, reading backtests correctly and choosing a broker (one a day for the first 5 days, then 7, 14 and 30 days after signing up). You also get notified before each price rise of the versions sold on the MQL5 Market (launch pricing that steps up as copies sell). Our EAs are free on this site with a live account at a partner broker.

* Privacy strictly protected. You can unsubscribe at any time.

What Is Curve Fitting (Over-Optimization)?

The core problem with backtest optimization:
Parameters optimal for the last 10 years → may fail on future data

Example: optimizing EMA period across the range 10–50

EMA PeriodBacktest PFForward Test PF
21 (optimal)2.30.9 ← what actually happens
30 (runner-up)1.81.3
Average value1.51.4

The optimized value (EMA = 21) looks best in the backtest but often disappoints in live conditions. That is curve fitting.


How Walk-Forward Analysis Works

Walk-forward analysis splits data into an optimization window (in-sample) and a validation window (out-of-sample).

It then repeats this split in chronological sequence to detect over-optimization.

[Example split using 10 years of data]

├─ Optimization window ─┤─ Validation window ─┤
2015–2018               2019      → Derive params A, validate on 2019
     ↓
2016–2019               2020      → Derive params B, validate on 2020
     ↓
2017–2020               2021      → Derive params C, validate on 2021
     ↓
(repeat…)

Aggregating the results from each validation window tells you whether the EA's parameters remain stable as market conditions change.


How to Run Walk-Forward Analysis in MT5

The MT5 Strategy Tester has a built-in "Forward" setting (1/2, 1/3 or 1/4 of the period, or a custom start date): during optimization it holds out that part of the period as out-of-sample data and runs a single forward test, so you can compare the Optimization Results and Forward Results tabs. However, rolling walk-forward analysis, which shifts the window and repeats the process many times, is not a standard feature. The following workarounds are available.

Method 1: Manual In-Sample / Out-of-Sample Split

Steps:

  1. Set the backtest period to 2015–2020 and run the optimization.
  2. Select the top 3–5 parameter sets from the optimization results.
  3. Backtest those parameters on the out-of-sample period (2021–2025).
  4. Compare the PF between the optimization window and the out-of-sample window.
Evaluation metric (Walk-Forward Efficiency):
WFE = Out-of-Sample PF ÷ In-Sample PF × 100%

WFE ≥ 60% → Pass (no significant over-optimization)
WFE 40–60% → Watch closely
WFE < 40%  → Suspected curve fitting (do not use)

Method 2: Third-Party Tools

ToolWhat it can do
Strategy Quant XSupports automated walk-forward analysis
MT5 built-in "Forward" settingOne out-of-sample forward test per optimization (repeat manually for rolling walk-forward)

Key Cautions When Optimizing

Caution 1: Limit Optimization Variables to 1–2

The more parameters you optimize simultaneously, the higher the risk of curve fitting.

✅ Good: optimize only EMA period (range 10–50, step 5)
❌ Bad:  optimize EMA period × ATR multiplier × RSI period simultaneously

Adding more optimization variables simply increases the chance of stumbling on a lucky combination — it does not make the strategy more robust.

Caution 2: Do Not Use the Top-Ranked Parameter Set

The parameter set that shows the highest PF in the optimization results is also the one most likely to be overfit.

Use this approach instead:

Recommended approach:
1. Extract the top 20% of parameter sets.
2. Look for clusters of similar parameter values.
3. Adopt the value near the center of the densest cluster.

Example: if the optimization sorts results as EMA = 21, 23, 19, 35, 22, 20… by PF, a cluster exists around 20–23. Adopt the central value of that cluster (21–22).

Caution 3: Use a Long Optimization Window

Recommended settings:
- Optimization (in-sample) window:  5–7 years
- Validation (out-of-sample) window: 2–3 years
- Split ratio (in-sample : out-of-sample): 70:30 to 80:20

The shorter the optimization window, the higher the risk of over-optimization.


Reading Walk-Forward Results

AspectSigns of a solid EAWarning signs
WFE (Walk-Forward Efficiency)≥ 60%< 40%
Performance per validation windowPF is positive in every validation window (no losing periods)Only one specific validation window performs well (other windows are negative)
PF levelOut-of-sample PF is within 50–90% of the in-sample PFIn-sample PF ≥ 3.0 (a classic symptom of over-optimization)

Tips for Designing Parameters That Are Harder to Overfit

Tip 1: Check Parameter Sensitivity

Confirm that PF remains stable when parameters move ±10–20% away from the optimal value.

When EMA = 21 is the optimal value:
EMA = 18: PF 1.25
EMA = 19: PF 1.31
EMA = 20: PF 1.34
EMA = 21: PF 1.38  ← optimal
EMA = 22: PF 1.33
EMA = 23: PF 1.29
EMA = 24: PF 1.24

→ PF stays positive across nearby values = robust strategy

If PF swings sharply around the optimal value, over-optimization is likely.

Tip 2: Use Simple Logic That Is Inherently Harder to Overfit

EAs with fewer parameters and simpler logic are naturally more resistant to curve fitting. Combine straightforward building blocks such as EMA crossovers and ATR-based SL/TP settings.


Summary

Key takeaways from walk-forward analysis:

  1. Split in-sample (optimization) : out-of-sample (validation) = 70:30
  2. WFE = Out-of-Sample PF ÷ In-Sample PF × 100%
  3. WFE ≥ 60% is the passing threshold
  4. Limit optimization variables to 1–2
  5. Adopt the cluster center, not the single best-performing value

Running walk-forward analysis lets you identify EAs that perform consistently in forward testing as well. The better an EA looks in backtesting alone, the more important this validation becomes.


FAQ

Q: Can I run walk-forward analysis with the built-in MT5 tools?

Partially. The Strategy Tester's "Forward" setting (1/2, 1/3 or 1/4 of the period, or a custom start date) lets you validate one out-of-sample period at the same time as the optimization and compare the Optimization Results and Forward Results tabs. Rolling walk-forward analysis, where the window is shifted and the test repeated, is not built in, so split your date range manually and run multiple tests, or use an external tool.

Q: Can I use an EA with a WFE of 50%?

WFE 50% sits on the borderline. If the out-of-sample PF is 1.2 or higher, live trading is feasible — but it is strongly recommended to accumulate at least six months of forward-test results before committing real capital.

Q: Is it dangerous to use an EA without walk-forward analysis?

It is not an absolute disqualifier, but the curve-fitting risk does increase. At a minimum, make sure you at least hold back part of your data range as an out-of-sample period rather than optimizing on the entire dataset.


📧 Free 8-email course + subscriber-only pack of 13 MT5 indicators

Right after you sign up, you get a download link for a subscriber-only pack of our 13 MT5 indicators: compiled files (.ex5), source code and a setup guide. Then 8 emails on algo-trading essentials, reading backtests correctly and choosing a broker (one a day for the first 5 days, then 7, 14 and 30 days after signing up). You also get notified before each price rise of the versions sold on the MQL5 Market (launch pricing that steps up as copies sell). Our EAs are free on this site with a live account at a partner broker.

* Privacy strictly protected. You can unsubscribe at any time.

Have a question about EAs or FX?

You can post it on the Nattzy trading forum (free sign-up). Questions beyond this article are welcome too — EA settings, choosing a broker and more.

Ask on Nattzy ↗

Comments & questions