TA School

Backtesting

Discover the science of backtesting: how to run historical tests, gather statistical data, compute edge metrics, and validate trading rules.

intermediate level12 min read

Interactive Model

Interactive Visual Walkthrough

Backtest Performance Curve

Step 1 of 7
STARTING CAPITAL BASELINE
Trading Idea

Define a clear, rule-based hypothesis: 'Buying the 50 EMA pullback in a daily uptrend with a 2:1 profit target.'

Why it matters: Without clear rules, backtesting is impossible. You cannot test a strategy that relies on 'intuition' or 'gut feel'.

Introduction

BacktestingBacktestingThe process of testing a trading strategy against historical data to evaluate its performance and expectancy before risking real money.Read full glossary entry → is the process of applying a set of technical trading rules to historical price data to determine how that strategy would have performed in the past. It is the cornerstone of strategy development, transforming speculative ideas into data-backed trading systems. By looking back, you can calculate the mathematical expectancy of your edge before putting capital at risk.


Why It Matters

  • Builds Execution Confidence: Knowing your strategy has survived years of historical data helps you execute rules without hesitation during drawdowns.
  • Quantifies the Statistical Edge: Provides objective numbers (win rate, average win/loss, max drawdown) instead of subjective guesses.
  • Eliminates Unprofitable Systems: Identifies flaws and weaknesses in a strategy before you lose real money executing it.
  • Develops Rule Objectivity: Forces you to define clear, mechanical rules for entries and exits.

Key Backtesting Metrics

When analyzing your historical test results, focus on these five core performance metrics:

  Metric                  Calculation / Definition
  ─────────────────────────────────────────────────────────────────────────────
  Win Rate                (Number of Winning Trades / Total Trades) * 100
  
  Average Win/Loss Ratio  Average Dollar Size of Wins / Average Dollar Size of Losses
  
  Profit Factor           Gross Profits / Gross Losses (Should be > 1.2)
  
  Max Drawdown            The largest peak-to-trough decline in equity
  
  Expectancy (R-multiple) Average profit per trade expressed as a multiple of risk (R)

The Expectancy Formula

Mathematical expectancy tells you how much you can expect to make per trade on average: $$\text{Expectancy} = (\text{Win Rate} \times \text{Average Win Size}) - (\text{Loss Rate} \times \text{Average Loss Size})$$


How to Conduct a Valid Backtest

  1. Write Down Strict Rules: You must define entry filters, stop-loss placement, and take-profit targets. If a rule involves "discretion," it cannot be cleanly backtested.
  2. Select a Diverse Dataset: Gather data spanning at least 2 to 5 years. Ensure this period includes a bull marketBull MarketA market condition characterized by a sustained period of rising prices, optimistic investor sentiment, and strong economic/fundamental indicators.Read full glossary entry →, a bear marketBear MarketA market condition characterized by a sustained period of falling prices, typically defined by a decline of 20% or more from recent highs, accompanied...Read full glossary entry →, and a consolidating (sideways) market.
  3. Log Every Trade: Keep a spreadsheet recording date, direction, entry, stop, exit, P&L (in R-multiples), and comments. Do not skip losing trades—that is cheating the data.
  4. Calculate Stats: Run the math to find your win rate, average risk-to-reward ratioRisk-to-Reward RatioA measure used to compare the potential profit of a trade against its potential loss. A ratio of 1:2 means the trader is risking $1 to potentially mak...Read full glossary entry →, and drawdown metrics.
  5. Forward Test: Execute the exact same rules in real-time on a demo account for 30–50 trades to verify if spreads, commissions, and execution lag alter the results.

Common Mistakes

[!WARNING]

  • Curve-Fitting (Over-optimization): Adding complex rules to eliminate historical losses (e.g., "Only buy on Tuesdays if RSI is below 42 and the moon is waxing"). This makes the system match the past perfectly but fail in the future. Keep rules simple and robust.
  • Hindsight Bias: Checking what happened after the signal before deciding if you would have taken the trade. When backtestingBacktestingThe process of testing a trading strategy against historical data to evaluate its performance and expectancy before risking real money.Read full glossary entry →, you must slide the chart bar-by-bar and make decisions without looking ahead.
  • Ignoring Transaction Costs: Failing to account for commissions, swap fees, and slippage. In high-frequency day trading, these costs can easily turn a profitable strategy into a losing one.

Key Takeaways

  • Backtesting is the process of testing a trading strategy on historical data to verify its statistical viability.
  • A valid backtest requires an adequate sample size (typically at least 100 trades) across different market regimes.
  • Key metrics to track include Win Rate, Profit Factor, Max Drawdown, and Average R-multiple.
  • Beware of curve-fitting: optimizing rules so perfectly to past data that they fail in live markets.
  • Always combine backtesting with forward testing (demo trading) to verify execution speed and slippage.
Knowledge CheckQuestion 1 of 5

What is the primary benefit of backtesting a trading strategy?