Learn › EAs and automated trading

Walk-forward Analysis: Test an EA on Rolling Windows Without Fooling Yourself

Fit settings on one stretch, test them on the next stretch you didn't use, then roll forward. Rolling vs anchored, walk-forward efficiency, and a worked example.

Intermediate 10 min read 21 October 2026

What you will learn
  • Walk-forward means fitting on one window, testing on the next window you didn't use for choosing, then rolling forward and repeating
  • The result you can trust is the test windows stitched together, not the fitting windows
  • Walk-forward efficiency = annualised test result ÷ annualised fitting result, a rough gauge of how much of the result disappears
  • A single fit over the whole period almost always looks better than reality, because it chose with knowledge of the future
  • If you go back and tweak the system until the test window looks good, that test window has just become a fitting window

Walk-forward analysis is a way of testing an EA where you fit its settings on one stretch of data, then run those settings on the next stretch that you didn’t use for choosing. Then you move both windows forward and do it again. What you end up with is a string of test periods the system had “never seen” when its settings were picked, which is much closer to what live trading looks like than a backtest tuned on the whole history at once.

Why a backtest tuned on everything fools you

Every time you run an optimisation and keep the best row, you are letting past data choose the settings for you. The winning set always carries some of that period’s luck, and the more sets you try, the more luck gets mixed in. That’s covered in detail in Overfitting: pick the plateau, not the peak.

The second problem is that markets change character. The best setting three years ago may not be the best setting today (market regime change). If you fit once over five years of data, you are choosing with full knowledge of what all five years looked like, which is exactly what you never have when trading live.

How walk-forward works

Two terms you need:

  • In-sample (IS) is the data used to fit the settings. It looks good because you picked it to look good
  • Out-of-sample (OOS) is data that wasn’t used to choose anything. That’s where results get closer to the truth

The steps:

  1. Pick a fitting window, say 2 years, and a test window, say 6 months
  2. Fit the settings on the fitting window, using a selection rule you wrote down beforehand
  3. Run those settings on the next 6 months. Record the result and change nothing
  4. Move both windows forward 6 months and go back to step 2
  5. Stitch the test windows from every round together. That’s your walk-forward result

There are two ways to move forward:

  • Rolling: the fitting window stays the same length, so old data drops off. It adapts faster, but uses less data
  • Anchored: the fitting window always starts at the beginning of the data and grows each round. Settings are steadier, but older data keeps pulling on them even after the market has changed
In-sample (fitting) Out-of-sample (test) FitFitFit FitFitFit Fit (grows every round) MA 70MA 60MA 20 MA 80MA 80MA 160 Round 1Round 2 Round 3Round 4 Round 5Round 6 Anchored (round 6): starts at day one Market changes character Year 012 345 Time (5 years of test data)
The rolling walk-forward used in this article's example: fit on 2 years, test on the next 6 months, then roll forward 6 months. The number in each test box is the MA length that round's fitting window picked. The dashed line is where the example series changes character. The test windows join up to cover the last 3 years with no overlap.

Worked example: a one-MA system in a market that changes

We built an illustrative price series in node, not a real market. It starts around 85 and moves between 73 and 132. For the first three years price runs in long up-and-down cycles; in the last two the cycles get much shorter. Random noise is added on every bar, and 250 bars count as one year.

The system is as simple as it gets: when the close is above an SMA (the average of the last n closes, see moving averages), hold a buy; when it’s below, hold a sell. Always hold 1 unit, and pay 0.1 points every time the position flips. The candidate settings are n = 10, 20, … 200, so 20 values. The selection rule is the highest net result in the fitting window.

RoundMA chosenFitting (points per year)6-month test (points)Test (points per year)
17025.4+13.927.9
26022.3+10.621.2
32029.2−14.5−29.1
48025.1+13.226.4
58022.4+16.132.2
616024.3+0.40.8

“Per year” just makes them comparable: the 2-year fitting result is divided by 2, the 6-month test result multiplied by 2.

Round 3 is the round whose test window lands right on the change. Its fitting window picked MA 20, a lone peak (58.4 points, while MA 10 made 28.1 and MA 30 made 31.3), and it lost straight away in the test. In rounds 1, 4 and 5 the test did better than the fitting window. That is six months of luck, not the system getting smarter.

Adding it up

  1. The 6 test windows stitched together = 13.94 + 10.59 − 14.54 + 13.22 + 16.12 + 0.39 ≈ 39.7 points over 3 years = 13.2 points per year
  2. Average fitting result = (25.38 + 22.28 + 29.19 + 25.13 + 22.45 + 24.29) ÷ 6 = 148.72 ÷ 6 = 24.8 points per year
  3. Walk-forward efficiency (WFE) = 13.24 ÷ 24.79 = 0.53, or 53%

Check: 24.79 × 0.534 = 13.24, matching the test result. Roughly half of what the fitting windows showed disappeared on new data.

Compared with one fit over all 5 years, the best setting is MA 80 with 98.88 points over 5 years = 19.8 points per year. That looks 19.78 ÷ 13.24 = 1.49 times better than the walk-forward result, for the same system. The gap is what choosing with full knowledge of all five years buys you.

One series could be a fluke, so we built 200 more of the same kind, changing only the random noise. On average the fitting windows made 30.5 points per year and the test windows 12.1. A single fit over all 5 years reported 23.3 points per year, and beat the walk-forward result in 182 of the 200 series. In 39 series the walk-forward result was negative, even though the average fitting result was positive in every one.

FittingTestOne fit on all 5 years 25.427.9 22.321.2 29.2−29.1 25.126.4 22.432.2 24.30.8 24.813.219.8 4020 0−20 Round 1Round 2Round 3 Round 4Round 5Round 6 Overall
Points per year for the MA system on an illustrative price series (not a real market). The fitting windows are consistently good because we picked them to be. The test windows swing far more, and round 3, where the market changes character, loses. The group on the right is the overall picture: walk-forward made 13.2, while one fit over all 5 years reports 19.8.

How to use walk-forward efficiency

WFE is the annualised test result divided by the annualised fitting result. The idea is best known from Robert Pardo’s work on testing trading systems. It answers one question: how much of what you saw while fitting survives on new data?

  • Close to 100%: almost nothing was lost. That’s good enough to be suspicious, so check whether future data leaked in
  • Around 50% or more: many texts use this as a rough bar for acceptable
  • Very low or negative: most of the fitting result was that period’s luck

It’s a blunt number, so never judge on it alone. In the 6 rounds above, dropping just round 3 makes WFE jump from 53% to about 91% (21.7 ÷ 23.9). Always read it alongside three things:

  1. How many test windows lost money
  2. Whether the chosen setting jumps around or stays put (in the example it jumps from 20 to 80 to 160)
  3. Drawdown in the test windows compared with the fitting windows

How many windows, and how long

  • Each test window needs enough trades. If 6 months gives you 5 trades, that round is a coin toss. Lengthen the test window or add more markets
  • A common ratio is a fitting window about 3 to 5 times as long as the test window. This article uses 4 (2 years to 6 months)
  • More rounds are better. Two or three rounds say very little. Together, the test windows should cover both fast-moving and quiet markets
  • Re-fit as often as you will live. If you test by re-fitting every 6 months but in real life you set it once and leave it for 3 years, the test isn’t measuring what you do

Rolling or anchored? There’s no fixed answer. On the example series, anchored made 8.9 points per year, worse than rolling, because pre-change data kept pulling on the setting. Across the 200 series the two were very close (11.7 vs 12.1).

What to pick in each round

Write the selection rule down before you start and use the same rule every round. If you pick by eye each round, the walk-forward result is contaminated by decisions made after seeing results.

A rule many people use is to pick the middle of a plateau, a setting whose neighbours are also good, rather than a lone peak (explained in the overfitting article). In round 3 of the example, that rule would have chosen MA 70 instead of MA 20 and lost less (−9.1 instead of −14.5 points). But to be straight: across the 200 series, the plateau rule didn’t help in this toy (11.1 vs 12.1 points per year). A plateau protects you from noise peaks, not from a change in market character. For that, walk-forward’s job is to show you the damage.

The Forward option in the MT5 Strategy Tester

In the Strategy Tester’s Settings tab there is a Forward option, with 1/2, 1/3, 1/4 or a custom date. MT5 holds back the end of your date range, runs the optimisation on the first part, then tests the parameter sets on the held-back part. The forward results appear in their own Forward tab.

That is a single split, not a multi-round walk-forward. For several rounds, re-run the optimisation yourself, shifting the start and end dates one step at a time, and log the chosen setting and the test result in a table. And watch for the big trap: if you scroll the Forward tab and pick the set with the best forward result, the forward period has just been used to choose. For reading the numbers in the report, see the MT5 backtest report explained.

A lesson from our own testing: the right rule, broken by us

In our backtests on gold (XAUUSD) M1, one research notebook set its rule on the very first page: search on 2022–2024, confirm on 2025–2026, and never choose a formula from the confirmation years.

But real tick data only existed for 2026. Earlier years used ticks the tester generated from price data (see tick data quality). So 2026 was the year with the best data and the most tempting one to use, and before long the testing was choosing settings on 2026 alone, layer upon layer.

Here is one combined system that was selected and assembled on 2026 (January to September, real ticks, 0.10 lot, 10,000-dollar balance):

  • 2026, the year used for choosing: +43,963 dollars, 1,832 trades, Profit factor 1.47
  • The same set on 2025, not used for choosing: −694 dollars, with equity drawdown reaching 61%
  • 2024: −197 dollars

The conclusion written down was that choosing from 2026 is “nested in-sample”. A confirmation year that has been used for choosing is no longer a confirmation year. And there was an extra complication: the test years left over had lower-quality data, so when results got worse it was impossible to fully separate the system from the data.

The rule used from then on: the latest year is for finding ideas, and can be trusted when it says a system is “dead”. Deciding on settings takes many years. Confirming with only two years can fool you too, because those two years may both happen to suit the system. These are all backtest results. Past results do not predict future results, and they are not returns you should expect.

A test window can only be used once. The moment you look at its result and go back to change the system, it becomes a fitting window.

Passed walk-forward. Now what?

Passing walk-forward means the system has survived self-deceiving parameter selection to some degree. It does not mean it will make money. Next steps:

The result you decide on is the stitched test windows, not the top row of the optimisation table.

Common mistakes

  • Reporting the fitting result as the system’s result. Fitting numbers look good because you chose them to. Only the test windows tell you anything
  • Peeking at the test window. Looking at the test result, then adding a filter, changing the parameter range or changing the selection rule, and re-running until it looks good. The test window becomes a fitting window, just like our 2026 lesson
  • Changing the split after seeing results. Trying 1-, 2- and 3-year fitting windows and keeping whichever gives the best walk-forward is just another layer of optimisation
  • Too few rounds, too few trades. Two rounds of 10 trades each give a WFE that swings so much it means nothing
  • Leaking future data. An indicator calculated on a bar that hasn’t closed, or a filter whose threshold was set from whole-period statistics, makes the test windows look better than they should
  • Believing a pass lasts forever. Walk-forward measures the past one step at a time. The market ahead can change character again, so keep watching the system after it goes live

Frequently asked questions

How is walk-forward different from simply splitting the data in two?

A two-way split is a single test, and the result depends on what kind of market the test window happened to be. Walk-forward repeats the test over many periods, and it also mimics what you will actually do live, which is re-fit every so often using the latest data.

What walk-forward efficiency counts as good?

There is no hard line. Many texts use around 50% or more as a rough bar, but the number swings a lot when there are only a few windows or a few trades. Read it together with how many test windows lost money and the drawdown inside the test windows.

Does MT5 do walk-forward automatically?

The Forward option in the Strategy Tester holds back the end of your date range for a single test. It doesn't roll the windows for you. For several rounds you have to re-run the optimisation yourself, shifting the dates one step at a time.

This is general education, not investment advice. Trading is risky and you may lose all of your capital.

Tools Chat on LINE