What you will learn
- Explain what backtesting is and why it turns opinion into evidence
- Understand why a rule must be defined precisely to be backtested
- Calculate a win rate and know its key measures
- Anticipate the pitfalls, and remember that past performance does not guarantee the future
Everything in this unit so far has been about reading charts and forming judgments. But how do you know whether any of it actually works? The answer is backtesting: systematically testing a trading rule against historical data to see how it would have performed. This is the bridge from subjective chart reading to evidence, and it leads into the quantitative and algorithmic methods of Unit 8 and the platform's strategy tester.
How to backtest a trading strategy on TradingView (TradingLab)
A beginner walkthrough of testing a signal on historical data. Watch how a clearly defined rule is applied across the chart and tallied.
What backtesting is
Backtesting takes a clearly defined trading rule and applies it to historical price data, simulating every trade the rule would have triggered and tallying the results. Instead of saying a strategy looks like it works, you can measure how it would actually have done over years of data. This turns a vague impression into a testable claim, which is the essence of a quantitative mindset.
Key terms
- Backtesting
- Testing a defined trading rule against historical data to see how it would have performed.
- Win rate
- The percentage of trades that were profitable. High alone does not guarantee a good strategy.
- Drawdown
- The largest peak-to-trough loss a strategy suffered, a gauge of the pain endured.
- Transaction costs
- Fees and the bid-ask spread, which real trading incurs and which can erase an apparent edge.
A simple example
Consider a basic rule built from the moving averages you already know: buy when the fifty-day moving average crosses above the two-hundred-day, and sell when it crosses below. To backtest it, you apply this exact rule across many years of historical prices, record each buy and sell it would have generated, and then measure the outcome. The rule must be defined precisely and mechanically, with no room for after-the-fact judgment, because a backtest can only test a rule it can follow without ambiguity.
What to measure
- Total return: how much the strategy would have made or lost overall, ideally compared against simply buying and holding.
- Win rate: the percentage of trades that were profitable, though a high win rate alone does not guarantee a good strategy.
- Drawdown: the largest peak-to-trough loss the strategy suffered along the way, a crucial measure of the pain you would have had to endure.
- Risk-adjusted return: measures that weigh return against volatility, which Unit 6 covers, since raw return ignores how much risk was taken.
Calculating a win rate
A backtest of a rule generated 75 trades over ten years. Of those, 45 were profitable. What is the strategy's win rate?
- Take the winning trades over the total. 45 winning trades out of 75 total.
- Divide. 45 divided by 75 is 0.60.
- Convert to a percent. 0.60 times 100 is 60 percent.
Why it matters: A win rate is just wins over total trades. But note it says nothing about the size of the wins versus the losses, so a high win rate alone does not make a strategy good.
Calculate the win rate
A backtested rule made 40 trades, of which 26 were profitable. What is its win rate, as a percent?
A backtest turns I think this works into here is how it would have done. That shift from opinion to evidence is the whole point of going quantitative.
TradingView backtesting guide, with a live example (TC Trading)
A fuller tutorial testing a strategy on historical data. Watch for the metrics reported and how costs and drawdown are handled.
The pitfalls to anticipate
Backtesting is powerful but riddled with traps that the next lesson addresses in depth. Among them: lookahead bias, accidentally using information in the test that would not have been available at the time, which Unit 8 treats carefully. Survivorship bias, testing only on companies that still exist while ignoring those that failed. And ignoring transaction costs, since real trading incurs fees and the bid-ask spread that can erase a strategy's apparent edge. Above all is overfitting, the subject of the next lesson, which is the biggest danger in backtesting.
Necessary but not sufficient
Finally, hold onto the most important caveat, the one repeated across this field: past performance does not guarantee future results. A strategy that worked beautifully in historical data may fail completely going forward, because markets change and because, as you are about to learn, it is alarmingly easy to find patterns in the past that were merely coincidental. Backtesting is an essential discipline that separates serious analysis from wishful thinking, but a good backtest is a starting point for confidence, never a promise of profit.
The backtest looks great. Now what?
A rule you invented shows a fantastic backtest over the past five years. Before trusting it with real money, what is the single most important thing to keep in mind?
Keep in mind that past performance does not guarantee future results. A great backtest is a starting point for confidence, not a promise, and it could reflect coincidence or overfitting rather than a genuine edge.Match the backtest metric
Pair each backtest measure with what it tells you.
Backtesting turns opinion into evidence, but it invites one dangerous mistake above all. The next lesson tackles it head on: overfitting.