Out-of-Sample Testing for EAs: How to Hold Data Back So It Actually Means Something

Out-of-sample testing sounds simple. Keep some data aside, build the Expert Advisor (EA) on the rest, then see how it does on the part it never saw. Almost every EA developer knows the idea. Far fewer keep their out-of-sample data genuinely unseen, because the usual workflow quietly spends it.

This guide covers how to split your data, how to protect the held-back portion, how to run the split in MetaTrader 5 (MT5), and how to read the comparison without fooling yourself.

One point up front: out-of-sample data is a resource you use up. Every time you look at it and then change the strategy, some of its value is gone. A good out-of-sample result reduces the risk that a backtest is overfit. It doesn't predict future results or reduce the risk of loss.

In-sample vs out-of-sample: the definitions

In-sample (IS) data is everything the design process is allowed to touch: idea exploration, rule writing, optimization, filter choices.

Out-of-sample (OOS) data is held back and used only to evaluate a design that is already frozen.

The distinction is not about where the data sits on a calendar. It is about whether the data influenced a decision. Data you looked at and then reacted to is in-sample, whatever your folder names say.

Why out-of-sample data gets contaminated

Contamination is rarely deliberate. It usually looks like ordinary development:

  • You test on OOS data, see a weak result, adjust a filter, and test again. The second OOS result is now partly in-sample.
  • You compare twenty variants on OOS data and keep the best one. The selection used the OOS data.
  • You choose the split boundary after seeing where the strategy performs well.
  • You read about a market event in the OOS period and add a rule that avoids it.

Each of these leaks information from the held-back period into the design. The OOS result then looks better than an honest one would, which is exactly what it was supposed to guard against.

How to design the split

Split by time, not at random

Market data is ordered. Volatility clusters, regimes persist and indicators carry memory from bar to bar. Randomly assigning bars or trades to IS and OOS lets neighbouring, highly similar data land on both sides, which inflates OOS results. Use a chronological split: earlier data in-sample, later data out-of-sample.

Use three portions, not two

A practical structure:

  1. In-sample: design and optimization.
  2. Out-of-sample (validation): used to check designs and choose between a small number of finalists. Each look is logged.
  3. Final holdout: touched once, after the design is frozen. If the strategy fails here, you don't tune it and test again on the same holdout.

The final holdout is what keeps the process honest when the validation set has been used several times.

Size each portion by trades, not by dates

What matters is how many trades each segment contains. A daily-bar system might place a few dozen trades a year; a scalper might place thousands. Make sure the OOS and final holdout segments each contain enough trades to say something. A common starting point is around 70% in-sample and 30% out-of-sample, adjusted so the out-of-sample portion isn't starved of trades.

Cover more than one market regime

If all of your in-sample data comes from one long trend, the OOS test mainly tells you how the strategy behaves when that trend ends. That is useful, but be clear about what each segment contains: trending and ranging periods, high and low volatility.

Handle the boundary carefully

Trades that open in-sample and close out-of-sample belong to neither cleanly. Either exclude them or assign them by entry date consistently. Indicators also need warm-up bars: a 200-bar moving average needs 200 bars of history before the first OOS signal is valid, and those bars will come from the in-sample period. That's acceptable, as long as no OOS outcome informs the design.

Out-of-sample testing in MT5

MT5's Strategy Tester has a built-in single split.

  1. Open the Strategy Tester and select your EA, symbol and timeframe.
  2. Set the full date range you want to use.
  3. In the Forward setting, choose 1/2, 1/3, 1/4 or a custom date. The tester reserves the final part of the range.
  4. Choose a modelling mode that suits the strategy; "Every tick based on real ticks" where intrabar price movement matters. The modes and data checks are explained in MT5 backtest data quality.
  5. Run the optimization. MT5 optimizes on the earlier portion only and reports forward results separately for each parameter set.

Two cautions. First, the Forward tab shows results for many parameter sets. If you pick the parameter set with the best forward result, you have just optimized on the forward period. Choose based on the in-sample results and a stable region of parameters, then read the forward result for that choice. Second, MT5's Forward setting gives one split. For repeated splits across time, use walk-forward testing.

How to read IS vs OOS results

Compare the same metrics on both sides, using the same costs and the same sizing.

Illustrative teaching example. The figures below come from "System A-14", an anonymized, composite daily-bar trend system built for our sample stress-test report. It is not a live system or a client result.

MetricIn-sampleOut-of-sample (holdout)
Profit factor1.521.19
Win rate43%38%
Max drawdown16.1%18.6%
Trades14864

Illustrative example only. Historical simulation, not predictive of future or live results.

What to notice:

  • Every metric got worse. That is normal. A strategy should not perform better on data it wasn't tuned on.
  • The size of the drop is the question. A profit factor falling from 1.52 to 1.19, with a lower win rate and a wider drawdown, is visible decay but not disqualifying on its own. In the full report it was treated as a flag to investigate, and the walk-forward and parameter tests then found where the weakness was.
  • The OOS trade count is modest. Sixty-four trades is enough to see a direction, not enough for precise conclusions. That's why the next step matters.

Put a range around the OOS result

A single OOS profit factor from a modest number of trades carries a lot of uncertainty. A bootstrap gives a rough range by resampling the OOS trades:

import numpy as np

def profit_factor(pnl):
    gains = pnl[pnl > 0].sum()
    losses = -pnl[pnl < 0].sum()
    return gains / losses if losses else float("inf")

def pf_range(oos_pnl, runs=5000, level=0.90, seed=7):
    rng = np.random.default_rng(seed)
    pnl = np.asarray(oos_pnl)
    pfs = [profit_factor(rng.choice(pnl, size=len(pnl), replace=True))
           for _ in range(runs)]
    tail = (1 - level) / 2 * 100
    return np.percentile(pfs, [tail, 100 - tail])

print(pf_range(oos_trades))

If you export MT5 trades to run this, check first that your Python results reconcile with the platform's; Python vs MT5 backtesting covers the usual mismatches.

If the lower end of that range sits below 1.0, the OOS segment hasn't shown that the edge survived; it has only failed to show that it didn't. The same resampling idea, applied to drawdowns, is covered in Monte Carlo testing a trading strategy.

When OOS beats IS

Occasionally the out-of-sample period looks better than in-sample. Sometimes that's a favourable regime. Often it's a sign of a problem: data leaking across the boundary, a split chosen after seeing results, or too few OOS trades. Investigate before you celebrate.

Other kinds of out-of-sample evidence

A time-based holdout is the core test, but not the only one.

  • Walk-forward analysis chains many IS/OOS splits and shows whether performance holds as the strategy is re-optimized over time.
  • Related markets. If the logic should apply to similar instruments, testing it there unchanged is a form of OOS evidence. Not every strategy should generalize, so decide in advance whether it is expected to.
  • Incubation. Running the frozen EA on a demo account in current conditions produces data that genuinely didn't exist when you designed it. It's slow, but it's the cleanest OOS data there is. When demo results differ from the backtest, why an EA trades worse live than in its backtest explains where to look.

Common out-of-sample mistakes

  1. Iterating on OOS results. Each adjust-and-retest cycle turns OOS into IS.
  2. Choosing the best forward result in MT5. That's optimization on the forward period.
  3. Random splits on time-series data. Neighbouring bars leak across the boundary.
  4. Too few OOS trades. A small segment can look excellent or terrible by chance.
  5. Changing costs or sizing between segments. Compare like with like.
  6. Treating one good OOS result as proof. It is one piece of evidence. Pair it with parameter sensitivity, walk-forward and Monte Carlo checks; the overfitting warning signs guide covers the rest.

Out-of-sample testing checklist

  • Split chosen and written down before any results were viewed
  • Chronological split with in-sample, validation and final holdout portions
  • Each portion contains enough trades to be meaningful
  • Boundary trades and indicator warm-up handled consistently
  • Every look at OOS data logged, with what was changed afterwards
  • Parameters chosen from in-sample results, not forward results
  • IS and OOS compared with the same costs and sizing
  • Bootstrap range calculated for the OOS profit factor
  • Final holdout used once, after the design was frozen

Frequently asked questions

What is out-of-sample testing in trading?

It is testing a strategy on historical data that played no part in designing or optimizing it. The aim is to see whether the strategy's behaviour holds up beyond the data it was fitted to.

How much data should be out-of-sample?

There's no fixed rule. Around 30% is a common starting point, but the deciding factor is the number of trades in the OOS segment. It needs enough trades to show a meaningful result.

Is MT5's forward testing the same as walk-forward testing?

No. MT5's Forward setting creates one in-sample and one out-of-sample split. Walk-forward testing repeats the optimize-then-test cycle across many consecutive windows.

What if my EA does badly out-of-sample?

Treat it as information. Look at which metrics fell and why, check the overfitting warning signs, and simplify or redesign on the in-sample data. Then judge the new design on data neither version has seen.

Does a good out-of-sample result mean the EA will perform well live?

No. It reduces the risk that the backtest is overfit. It can't predict future market conditions or execution quality, and it does not reduce the risk of loss.

Want a second pair of eyes?

Start with our free Sample Stress-Test Report. It walks one anonymized, illustrative strategy through a full stress test, start to finish, so you can see what rigorous validation looks like before you test your own.

Read the Sample Stress-Test Report

Want your own backtest checked? The Strategy Audit + 60-minute call is a paid service at a launch price of £100, credited in full against our build and portfolio offers. You send an MT4/MT5 Strategy Tester report or trade-list CSV; what we can check depends on the files you supply, and walk-forward and parameter sweeps are not included because they need the strategy itself. It is analysis of strategy testing, not investment advice, and does not promise any trading or evaluation outcome. See the Strategy Audit

Disclaimers

CollosoTrading provides educational content and analytical services for retail and professional algorithmic traders. We do not provide regulated investment advice, financial advice, or personal recommendations. Trading derivatives, leveraged products, and CFDs carries a high level of risk and may result in losses exceeding deposits. Past performance, including any verified or unverified historical results referenced on this site, is not indicative of future results. Consult an independent regulated financial adviser before making investment decisions.

All figures are backtests or simulations unless marked LIVE. Hypothetical or backtested performance results have inherent limitations and may not reflect actual trading. No representation is made that any account will or is likely to achieve profits or losses similar to those shown. Individual results vary. All figures in this article come from an anonymized, illustrative teaching example. We do not guarantee the outcome of any prop firm challenge.