Skip to main content
Module 30 · Building a Trading Plan & System

Backtesting Your Strategy

5 min readYou'll be able to Run an honest backtest of a written setup — with costs, an out-of-sample check and the right statistics — and recognise the biases that make backtests lie.

Backtesting means applying your exact rules to historical price data to see how the strategy would have performed. Done honestly, it gives you a large sample of trades in days instead of months, and shows you the losing streaks and drawdowns to expect before you live through them. Done carelessly, it produces beautiful results that vanish the moment real money is involved — so how you test matters as much as what the results say.

Backtesting Your Strategy
Quick demo

A pullback strategy, tested two ways (hypothetical numbers). You test your setup on two years of data. You use the first 18 months to study it (in-sample) and lock the last 6 months away until the end (out-of-sample).

In-sample: 120 trades, 48 winners averaging 1.9R, 72 losers at 1.0R.

  • Gross profit = 48 × 1.9R = 91.2R. Gross loss = 72 × 1.0R = 72R.
  • Profit factor = 91.2 ÷ 72 ≈ 1.27
  • Expectancy = (91.2 − 72) ÷ 120 = +0.16R per trade
  • After costs of about 0.05R per trade: +0.11R

Out-of-sample, untouched until now: 60 trades, 24 winners at 1.8R, 36 losers at 1.0R.

  • Net = 43.2R − 36R = 7.2R → +0.12R gross, +0.07R after costs

The edge held up on unseen data, but smaller. That shrinkage is normal and expected — and it is the number you should plan around, not the in-sample one.

Step by step

  1. Freeze the rules. Write the context filter, trigger, stop, target and time exit before you look at a single trade. If you change a rule, you restart the test.
  2. Choose the data. Use enough history to include different conditions — trending, ranging, high and low volatility. Split it: something like the first 70% in-sample, the last 30% out-of-sample.
  3. Record every trade. Date, time, entry, stop, exit, result in R, and a screenshot or note. Include the ones you "would have skipped" — if the rules said take it, you take it.
  4. Apply costs. Commissions, exchange fees and a realistic slippage estimate on every trade, especially stops and market orders.
  5. Calculate the statistics on the in-sample set. Only then run the out-of-sample set, once.
  6. Compare. If out-of-sample collapses, the in-sample result was probably fitted to noise.

The statistics that matter

Expectancy
Average R per trade
The core number — must be positive after costs
Profit factor
Gross profit ÷ gross loss
Above 1 is profitable; many traders want 1.3+ after costs
Max drawdown
Worst peak-to-trough, in R
Sets your real risk tolerance

Add three more: win rate and average win / average loss (to understand how the strategy makes money), and the longest losing streak (so you know what normal pain looks like).

Total profit is the least useful number. It depends on how many trades you took and your position size, and it hides how bumpy the path was.

Expectancy per trade, in R — in-sample vs out-of-sample (illustrative)
0.16RIn-sample, gross0.11RIn-sample, net0.12ROut-of-sample, gross0.07ROut-of-sample, net

Illustrative numbers from the hypothetical test above. Costs and unseen data both shrink the edge; the out-of-sample, after-cost figure is the one to plan with.

The biases that make backtests lie

Overfitting (curve-fitting). Every extra parameter — a moving-average length, an RSI level, a time filter — lets the strategy bend to fit the past. Test enough combinations and one will look great by pure chance. Warning signs: results that collapse when a parameter changes slightly (a 20-period average works, 19 and 21 do not), or many rules with few trades. Prefer few rules and settings that work across a range of values.

Look-ahead bias. Using information that was not available at the time — for example entering at the open based on that day's close, or using a daily high that had not formed yet. In manual testing, hide the future bars as you go.

Survivorship bias. Testing stocks only from today's index list ignores the companies that were dropped or went bankrupt. Results look better than reality.

Unrealistic fills. A limit order that price only touched may not have filled in reality — you were in a queue. Conservative testers count a limit fill only if price traded through the level. Stops in fast markets fill worse than the stop price.

Ignoring costs. As the edge chapter showed, a few dollars per trade can turn a short-term strategy from profitable to losing.

Manual versus automated testing

Automated backtests (code in a testing platform) can run thousands of trades and many variations quickly — which also makes overfitting easier. Manual testing (bar-by-bar replay, recording each trade by hand) is slower but trains your eye, and forces you to deal with the same ambiguity you will face live. For discretionary setups, a manual test of 100+ trades is often more realistic than a perfect-looking automated one.

How many trades?

More is better, but quality matters. Aim for at least 100 trades in-sample if the setup is frequent enough, and remember from the edge chapter that even 100 trades leaves roughly ±10 percentage points of uncertainty on the win rate. A strategy that produces 30 trades in five years may be real, but you will never be very sure.

Common mistakes

  • Testing until it works. Trying 50 variations and keeping the best is data mining, not discovery.
  • Skipping trades in the test that "didn't feel right". If you cannot code or write that feeling as a rule, it does not exist in the backtest.
  • Testing one market regime. Two years of a bull market tells you little about how a long strategy behaves in a decline.
  • Trusting total profit instead of expectancy and drawdown.
Check yourself

1. A backtest shows gross profit of 90R and gross loss of 60R over 100 trades. What are the profit factor and expectancy?

2. A strategy works with a 20-period moving average but fails with 18 and 22. What does that suggest?

3. Why keep part of the data out-of-sample?

4. In a conservative backtest, when should a limit order count as filled?