AdvancedLesson 5 of 64 min read

Building and testing a strategy: backtesting without fooling yourself

Quick answer

A backtest applies fixed rules to historical data to see how a strategy would have performed. Its biggest danger is overfitting: tuning rules until they fit the past perfectly, so they fail on new data. Keep rules simple, test on data you didn't use to design them, include realistic costs, then forward-test before committing.

In this lesson
  1. Start with rules a computer could follow
  2. In-sample vs out-of-sample
  3. The overfitting trap
  4. Include costs and realism
  5. Forward-test before you trust it
  6. Common mistakes to avoid
  7. Try it yourself
  8. Worked example
  9. Key takeaways
  10. Key terms
  11. FAQ
  12. Check your understanding

Start with rules a computer could follow

A strategy is testable only if every decision is defined: market, timeframe, entry condition, stop, target, size and trading hours. If you find yourself saying "it depends", the rule isn't finished.

In-sample vs out-of-sample

Split your history in two. Design and adjust on the in-sample period; then run the finished rules, unchanged, on the out-of-sample period. If performance collapses out-of-sample, the strategy was probably fitted to noise.

The overfitting trap

Researchers Bailey, Borwein, López de Prado and Zhu showed that strong backtest performance is easy to achieve just by trying enough strategy variations, and that the more configurations you test, the more likely the winner is overfit. Their warning: overfit strategies can lose money out-of-sample rather than merely break even.

Source: Bailey, Borwein, López de Prado & Zhu (2014)

Practical defences: few parameters, record how many variations you tried, prefer settings that work across a range of values rather than one magic number.

Equity curves: an overfit strategy rises steeply in the in-sample period then falls out-of-sample; a robust strategy rises more modestly in both periods in-sample (design)out-of-sample (test) overfitrobust time → (illustrative equity curves)
An overfit strategy looks best on the data it was tuned on and fails on new data.

Include costs and realism

  • Spreads (wider around news and at session opens).
  • Slippage on stops and market orders.
  • Overnight swaps if you hold positions.
  • Your account rules: does the equity curve ever breach a daily loss or max drawdown limit?

Forward-test before you trust it

Trade the finished rules live on a simulated account for a meaningful sample (50+ trades) and compare results with the backtest. Simulated environments, such as Tradeiators' virtual-funds accounts, are designed for exactly this stage.

Common mistakes to avoid

  • Changing rules after seeing the out-of-sample results, then calling it "out-of-sample".
  • Ignoring spreads, slippage and swaps.
  • Picking the single best parameter set from hundreds of combinations.

Try it yourself

Write one simple strategy in rule form (market, timeframe, entry, stop, target, size, hours). Test it manually on the last 50 setups on the chart, recording each result in R. Then test the same rules on the 50 setups before that, without changing anything. Compare expectancy.

Worked example

You test a moving-average crossover on 2019–2023 data and try 40 combinations of lengths. The best one shows +60%. On 2024–2025 data it makes −8%. Neighbouring settings (one bar longer or shorter) were all weak in-sample too. That's a classic overfit: one lucky configuration, not a robust edge.

Key takeaways

  • Define every rule before testing.
  • Design in-sample, validate out-of-sample.
  • More variations tried = higher overfitting risk.
  • Include costs and forward-test before trusting results.

Key terms in this lesson

Backtest
A test of fixed trading rules on historical data to estimate past performance.
Out-of-sample data
Historical data not used to design a strategy, kept aside to test it.
Overfitting
Tuning a strategy to past noise so it fails on new data.
Expectancy
Average result per trade: win rate × average win − loss rate × average loss, often in R.
Slippage
The difference between the price you expected and the price your order filled at.
See the full trading glossary

Frequently asked questions

What is backtesting?

Applying fixed trading rules to historical data to estimate how a strategy would have performed.

What is overfitting in trading?

Tuning a strategy so closely to past data that it captures noise rather than a real edge, so it performs poorly on new data.

How do I avoid overfitting?

Use few parameters, test on out-of-sample data you didn't design on, count how many variations you tried, include realistic costs and forward-test before trusting results.

Check your understanding

Three quick questions. Get all three right to mark the lesson complete.

1.What is overfitting?

2.Why keep out-of-sample data untouched?

3.A setting works only at exactly 37 bars and fails at 35 and 39. What does this suggest?

Finished reading? Track your progress across the Academy.

Educational content only. Tradeiators Academy lessons and videos are for general education and are not financial, investment or trading advice. Examples are illustrative; past or simulated performance does not guarantee future results. Trading leveraged products carries a high risk of loss. All trading on Tradeiators uses virtual funds; rewards are subject to each product's rules and verification. 18+ only. See the Terms & Conditions and Risk Policy.