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.
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.
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.
Finished reading? Track your progress across the Academy.