How do I backtest a trading strategy?
To backtest a trading strategy, write down exact entry, stop, target and sizing rules, then apply them to past price data one trade at a time and record every result, including costs. Aim for at least 50 to 100 trades across different market conditions, and then check the results on data you did not use to build the rules, followed by paper or very small live trading.
Recommended resource: for the full step-by-step method, Secrets of Chart Reading Most Traders Miss by Manthan Bhendkar (founder of Asendify) covers this in depth: The Playbook for Technical Analysis, Trading Strategies and Risk Management. PDF, £1720.00, instant download.
This page is education only, not financial advice. Backtests use hindsight and do not predict future results. Trading is risky and most retail traders lose money.
Key takeaways
- A backtest is only as good as its rules. If two people would read your rules differently, they are not ready to test.
- Record results in R (multiples of the amount risked), not just money, so you can compare trades fairly.
- Include spreads, commissions and slippage. Small costs can turn a thin edge negative.
- Testing many variations on the same data almost guarantees one will look good by chance. Keep some data back.
- A backtest is a filter, not a proof. Follow it with forward testing on paper or small size.
Step 1: Write rules a stranger could follow
Vague rules are the most common reason backtests mislead. "Buy when the trend is up and price pulls back" leaves room for hindsight. Turn every part into something you can check on a chart:
| Part | Vague | Testable |
|---|---|---|
| Market and timeframe | "Stocks" | "S&P 500 ETF, daily chart" |
| Trend filter | "Trend is up" | "Close above the 50-day moving average, and the 50-day is rising" |
| Entry | "Buy the pullback" | "Buy at the open after a close below the 20-day moving average" |
| Stop | "Below support" | "1.5 times the 14-day average true range below entry" |
| Target or exit | "Take profit when it looks strong" | "Exit at 2R, or at the close if price closes below the 50-day" |
| Size | "Not too big" | "Risk 1% of the account per trade" |
If you are not sure which strategy to test first, our guide on which trading strategies are best for beginners covers simple rule-based options.
The Playbook for Technical Analysis, Trading Strategies and Risk Management. £1720.00 one-time, instant download.
Step 2: Choose your data and period
Use enough history to include different conditions: rising, falling and sideways markets, and calm and volatile periods. A strategy tested only in a strong bull market tells you little about a bear market.
Split the data before you start:
- In-sample data (for example, the first 70%) to develop and check the rules.
- Out-of-sample data (the last 30%) that you do not look at until the rules are fixed.
Step 3: Test trade by trade
You can backtest by hand or with software.
| Method | How it works | Good for | Watch out for |
|---|---|---|---|
| Manual (chart replay) | Scroll the chart forward bar by bar, take trades as the rules say, record them | Discretionary or chart-pattern rules; learning | Slow; easy to peek ahead |
| Spreadsheet | Export prices, apply rules with formulas | Simple indicator rules | Errors in formulas |
| Platform tester | Code the rules in a platform's strategy tester | Fast testing of many trades | Easy to over-optimise |
For manual testing, hide the future. Most charting platforms have a bar replay mode that shows one bar at a time. Decide before each bar, not after.
Step 4: Record every trade properly
For each trade, write down the date, entry, stop, exit, result in money and result in R. R is the amount you risked. If you risked $100 and made $180, that is +1.8R. Our guide on calculating trading expectancy using R-multiples explains the maths in detail.
Then calculate:
- Win rate: wins divided by total trades.
- Average win and average loss in R.
- Expectancy: (win rate × average win) − (loss rate × average loss).
- Maximum drawdown: the largest peak-to-trough fall in your test account.
- Longest losing streak: so you know what to expect emotionally.
Step 5: Subtract costs
Costs include spread, commission and slippage (the gap between the price you expected and the one you got). The SEC's guide to day trading risks warns that day traders pay large amounts in commissions and other expenses, and suggests working out how much you must earn just to break even. A strategy that trades often needs a bigger edge to cover its costs.
Step 6: Check for overfitting
Overfitting means tuning rules so closely to past data that they capture noise, not a real pattern. A 2014 study by mathematicians including David Bailey and Marcos López de Prado, reported by ScienceDaily, found that with 5 years of data, testing as few as 45 variations can produce one that looks good historically but performs poorly afterwards. Their main safeguard is testing on data outside the original dataset.
Signs of overfitting:
- many conditions and filters, each with a precise number
- results that collapse when you change a setting slightly
- great in-sample results and poor out-of-sample results
- only a handful of trades
Step 7: Forward test
US futures rules require anyone showing simulated performance to warn that it has "certain inherent limitations", that the trades have not actually been executed, and that such programmes are designed "with the benefit of hindsight". That wording, from CFTC Rule 4.41, is a good reminder for your own tests too.
So after a backtest, trade the rules on paper or with very small size for a set number of trades. Compare the forward results with the backtest. A large gap usually means hindsight crept in, or costs and fills were underestimated.
Example: a simple pullback backtest
Example: Ravi tests the testable pullback rules in the table above on a daily chart over 10 years. He uses the first 7 years in-sample and keeps the last 3 back.
| Measure | In-sample (7 years) | Out-of-sample (3 years) |
|---|---|---|
| Trades | 84 | 31 |
| Win rate | 46% | 42% |
| Average win | +1.9R | +1.8R |
| Average loss | −1.0R | −1.05R |
| Expectancy before costs | (0.46 × 1.9) − (0.54 × 1.0) = +0.33R | (0.42 × 1.8) − (0.58 × 1.05) = +0.15R |
| Costs per trade | 0.05R | 0.05R |
| Expectancy after costs | +0.28R | +0.10R |
| Longest losing streak | 6 | 5 |
The out-of-sample result is weaker but still positive, which is normal. He decides the rules are worth forward testing on paper for 30 trades, risking an imaginary 1% per trade. He sizes each paper trade with the free position size calculator so the habits carry over to live trading, and logs each one in a journal. These figures are illustrative, not a recommendation of this strategy.
Common mistakes
- Peeking ahead: seeing tomorrow's bar before deciding today's trade.
- Ignoring gaps: a stop does not guarantee your exit price if the market opens beyond it.
- Testing too few trades: 15 trades can look brilliant or terrible by luck.
- Changing rules mid-test: if you change a rule, restart the test.
- Leaving out losing periods: test through bad markets, not just good ones.
Secrets of Chart Reading Most Traders Miss includes a chapter on backtesting alongside five defined strategies, risk management and a 90-day practice plan, and suits self-paced learners who want to test rules before risking money.
FAQ
How many trades do I need for a reliable backtest?
There is no fixed number, but fewer than 30 is very unreliable. Aim for at least 50 to 100, across different market conditions.
Can I backtest a strategy for free?
Yes. You can scroll back through free charts and record trades by hand in a spreadsheet, or use the bar replay and strategy tools many charting platforms offer on free plans.
Is manual backtesting better than automated?
Manual testing suits chart-pattern and discretionary rules and teaches you the setup. Automated testing is faster for indicator-based rules but makes overfitting easier.
Why do my live results differ from my backtest?
Common reasons are hindsight, underestimated costs and slippage, overfitting, and not following the rules exactly when real money is at stake.
Should I backtest before paper trading?
Yes. Backtesting filters out rules that never worked. Paper trading then tests whether you can follow them in real time.
More playbooks on other topics: https://www.asendify.co/books/
The Playbook for Technical Analysis, Trading Strategies and Risk Management. £1720.00 one-time, instant download.