Trading Education
How to Backtest a Trading Strategy: Step-by-Step Guide
Learn how to backtest a trading strategy step by step. Covers tools, methods, common mistakes, and how to interpret backtest results for beginners.
Source updated
- Originally published
- Source updated
In this article
Backtesting applies specified rules to historical data under an execution model. It estimates what that model would have produced, not what a real account definitely would have earned.
1. Write Rules Another Person Can Reproduce
Define the instrument, data source, session, signal timing, entry and exit orders, quantity method, costs and conditions for no trade. State whether a signal uses a completed bar. Version the rules before running the evaluation.
For a crossover example, specify the average type and periods, which bar confirms the cross, and the earliest subsequent order time. “Buy at the crossover” leaves important fill assumptions unresolved.
2. Check the Data You Could Have Known
Inspect missing bars, timezone changes, corporate-action adjustments and futures contract rolls. A current list of surviving stocks is not necessarily the historical universe. Economic releases and company figures may have been revised after the test date.
Higher-timeframe values and confirmed swing points can introduce future information if used too early. Preserve the data version and test settings so the result can be reproduced.
3. Model Orders and Costs
A bar containing both the target and stop does not tell you which was hit first. Use finer data where suitable or document a conservative ambiguity rule. A limit-price touch does not guarantee available quantity or a fill.
Include the actual fee structure and a justified range of adverse-fill assumptions. There is no universal one-to-two-tick slippage allowance appropriate to every order, instrument and event. TradingView's strategy documentation explains how one broker emulator handles orders and testing limitations; other tools can differ.
4. Review the Sequence, Not Just the Total
Record entry and exit timestamps, fills, quantities, costs, open exposure and reasons for skipped or rejected orders. Inspect net expectancy, drawdown and dependence on a few outliers alongside win rate and profit factor.
A 45% win rate with average gross winners twice average losses has positive gross expectancy in that model. Costs or different realised payoffs can reverse it. A fixed target ratio is not the same as an observed average winner.
5. Keep Evaluation Separate From Selection
Use one portion of the data to develop rules and a separate portion to evaluate them. Repeatedly tuning to the second portion turns it into another development set. Record how many variants were tried and include adverse periods.
No 100-trade threshold creates statistical significance on its own. Dependence between trades, payoff variability and market coverage matter. See sample-size uncertainty.
Forward simulation can then check timing and order workflow on newly arriving data. It remains simulation, and a good result does not require a live-money trial. Pause immediately for a safety or implementation issue rather than continuing just to reach a count.
Risk Disclaimer: Trading involves substantial risk of loss. Past performance is not indicative of future results. See our full risk disclaimer.