How to Backtest a Trading Strategy (Step-by-Step)
A step-by-step guide to backtesting a trading strategy: objective rules, sample size, expectancy, drawdown, profit factor, common biases and forward testing.
Backtesting is the process of applying a trading strategy to historical price data to see how it would have performed. Done properly, it tells you whether your rules have an edge, what a normal losing streak looks like, and how much drawdown you should expect — before you put real money at risk.
Done badly, it tells you whatever you want to hear. This guide walks through how to backtest a trading strategy the right way, using the TJR model — liquidity sweep, market structure shift, then a 15-minute Fair Value Gap entry — as the running example.
What Is Backtesting in Trading?
Backtesting answers one question: if I had followed these exact rules in the past, what would have happened? It doesn't predict the future, but it gives you a baseline for what the strategy's results can look like across many trades and different market conditions.
The key word is exact. A backtest is only as useful as the rules you test.
Manual vs Automated Backtesting
| Manual backtesting | Automated backtesting | |
|---|---|---|
| How it works | You replay charts bar by bar and log each trade | Code scans historical data and executes rules |
| Speed | Slow | Fast — thousands of trades in minutes |
| Best for | Discretionary or visual concepts like FVGs and structure | Fully quantifiable rules |
| Skill required | Chart reading and patience | Programming and data handling |
| Main risk | Hindsight bias and inconsistent judgment | Curve-fitting and data errors |
Manual backtesting is where most price-action traders should start. Concepts like a valid market structure shift or a clean Fair Value Gap are easy to see but harder to code reliably. Replaying charts also trains your eye for live trading.
Automated backtesting works well once your rules are fully objective. It's faster and removes human inconsistency, but it introduces its own risks — especially over-optimizing parameters until the results look perfect.
How to Backtest a Trading Strategy: Step by Step
1. Define Objective Rules
Every rule must be specific enough that two different traders would mark the same trade. For our example model:
- Session: only setups forming inside the London or New York killzone.
- Sweep: price trades through a marked high or low, such as the Asia range or previous day's high or low. See our guide to liquidity sweeps.
- Shift: a 15-minute candle closes beyond the most recent opposing swing point with displacement.
- Entry: a limit order at the 15-minute FVG created by that displacement.
- Stop: beyond the sweep extreme.
- Target: minimum 1:2 risk-to-reward, or the next opposing liquidity pool.
- Invalidation: if price doesn't retrace into the FVG before the killzone ends, no trade.
If you find yourself thinking "it depends," that rule isn't finished yet.
2. Choose Your Market and Data
Pick one instrument to start — for example EURUSD, Gold, or NQ. Use clean historical data with the correct session times, and note whether your data includes spreads or commissions. Test across different conditions: trending months, ranging months and high-volatility news periods.
3. Replay the Charts Without Peeking
Use a bar-replay tool and move forward one candle at a time. Mark your levels before the session opens, then make every decision using only the information available at that moment.
4. Log Every Trade
Record each trade in a spreadsheet: date, session, direction, entry, stop, target, result in R, and a screenshot. Log the skipped setups too, with a reason. A consistent log is what turns a backtest into usable data.
5. Reach a Meaningful Sample Size
A handful of trades tells you almost nothing. Sample size matters because small samples are dominated by luck. As a general guideline, aim for at least 100 trades before drawing conclusions, and ideally spread them across different market conditions rather than one unusually clean month.
6. Calculate Your Metrics
Once the sample is complete, calculate the metrics below and review them honestly.
Backtesting Metrics That Actually Matter
R-Multiples
An R-multiple expresses each trade's result as a multiple of the amount risked. If you risk 1R and gain twice that, the trade is +2R. A full stop-out is -1R. Measuring in R lets you compare trades across different instruments, stop distances and account sizes. It also connects directly to position sizing.
Expectancy
Expectancy is the average result per trade, in R:
Expectancy = (Win Rate × Average Win) − (Loss Rate × Average Loss)
A positive expectancy means the strategy made money on average across the sample. It's the single most important number in a backtest, because it combines how often you win with how much you win.
Profit Factor
Profit factor is gross profit divided by gross loss. A value above 1.0 means the strategy made more than it lost. It's a quick way to sanity-check expectancy, but it doesn't tell you how bumpy the ride was.
Maximum Drawdown
Maximum drawdown is the largest peak-to-trough decline in your equity curve during the test. This number matters psychologically: it tells you how bad a normal rough patch can get. If you can't sit through the drawdown your backtest shows, you won't follow the strategy live.
Longest Losing Streak
Track the longest run of consecutive losses. Even a strategy with positive expectancy will produce losing streaks, and knowing their typical length in advance makes them far easier to sit through.
Common Backtesting Biases to Avoid
- Look-ahead bias: using information that wasn't available at the time — for example, knowing a sweep was "the" low of the day because you can see the rest of the chart. Bar replay is the best defense.
- Curve-fitting (over-optimization): tweaking rules until they fit past data perfectly. A strategy with ten finely tuned filters will often fall apart on new data. Keep rules simple and logical.
- Survivorship bias: testing only on instruments or periods that happen to look good today, while ignoring the ones that didn't. Test across multiple markets and conditions.
- Selection bias: skipping ugly trades because they "didn't count." If it met the rules, it goes in the log.
- Ignoring costs: spreads, commissions and slippage reduce real results, especially on short-term strategies.
Backtesting vs Forward Testing
Forward testing means running the strategy in real time — on a demo account or with very small size — after the backtest is finished. It answers a different question: can I execute these rules live, under real conditions and real emotions?
The two work together:
- Backtest to confirm the rules have a positive expectancy.
- Forward test to confirm you can execute them consistently.
- Compare forward results against your backtest metrics. Large gaps usually point to execution problems, not a broken strategy.
Execution is where psychology enters the picture — our guide to trading psychology and discipline covers how to follow your rules once the pressure is real.
Frequently Asked Questions
How many trades do I need to backtest?
Aim for at least 100 trades as a general guideline, spread across different market conditions. Fewer trades leave too much room for luck to distort your results.
Is manual backtesting better than automated backtesting?
Neither is better overall. Manual testing suits visual, price-action concepts like FVGs and structure shifts, while automated testing suits fully quantifiable rules and large datasets.
What is a good profit factor?
Anything above 1.0 means the strategy was profitable over the sample, before accounting for anything left out of the test. Treat very high values with suspicion — they often signal curve-fitting or too small a sample.
Can a backtest guarantee future results?
No. A backtest shows how rules performed on past data, and market conditions change. That's why forward testing and ongoing journaling are essential steps after a backtest.
Trading involves risk, and past performance — including backtested results — does not guarantee future results. This is not financial advice.
Want to see the sweep, shift and FVG model applied in live markets? View our verified trade history or get access to TJR Signals.