← Backtesting guide

How to Backtest a Trading Strategy

To backtest a trading strategy: (1) define your entry and exit rules, (2) gather historical OHLCV data for your chosen market, (3) apply the rules bar-by-bar, (4) record each trade, then (5) compute summary statistics — Sharpe ratio, CAGR, maximum drawdown, and win rate. This article walks through each step in detail.

Step 1: Define your entry and exit rules precisely

Vague rules ("buy when RSI is low") cannot be backtested. Every condition must be expressed as a deterministic comparison: "go long when the 14-period RSI on the daily bar crosses below 30." Choose your indicator, its parameters, the comparison operator, and the threshold.

Step 2: Choose your data source and timeframe

Use exchange-sourced tick or OHLCV data. Avoid adjusted data for live trading strategies — splits and dividends alter prices in ways that misrepresent your real entry points. Choose a timeframe (1-minute, hourly, daily) that matches how you intend to trade.

Step 3: Apply your rules to the historical data

Process each bar sequentially. On each bar, check whether entry conditions are met (and you are flat), or whether exit conditions are met (and you are long). Record the entry price, exit price, and number of shares or contracts for each trade.

Step 4: Set position sizing

Fixed fractional sizing — risking a constant percentage of equity per trade — is the standard starting point. A common choice is 1–2% of equity per trade. Position sizing dramatically affects both returns and drawdowns.

Step 5: Compute and interpret the metrics

Key metrics: Sharpe ratio (risk-adjusted return — above 1.0 is acceptable, above 2.0 is strong), CAGR (compounded annual growth rate), maximum drawdown (the largest peak-to-trough equity loss — below 20% is manageable for most traders), and win rate (percentage of trades that are profitable — meaningless without also knowing the average win/loss ratio).

Next: Walk-forward analysis →

© 2026 backtester.run · All rights reserved · support@backtester.run

Backtest results are hypothetical and do not guarantee future performance.