✦ Guide
How to backtest a trading strategy
The short answer
Backtesting runs your exact trading rules on historical data to see how they would have performed. A useful backtest uses clean data, realistic costs, rules written before testing, and out-of-sample checks — and is still no guarantee of future results.
What a backtest is — and isn't
A backtest applies precise trading rules to past market data to estimate how a strategy would have behaved. It's a way to reject bad ideas cheaply. It is not proof that a strategy will work in the future.
Step by step
- Write the rules down first. Entry, exit, position size and stop-loss rules must be exact enough that a computer can follow them with no judgment calls.
- Get suitable data. Use data that matches how you'll trade (daily vs. intraday), adjusted for splits and dividends, and covering different market conditions.
- Model costs honestly. Include commissions, the bid-ask spread and slippage. Many strategies that look profitable disappear once costs are included.
- Hold data back. Develop on one period and test on another you haven't looked at (out-of-sample), or use walk-forward testing.
- Look beyond total return. Check maximum drawdown, the number of trades, win rate, and how results change across years.
- Paper trade. Run the strategy live with simulated money before risking capital.
The biases that make backtests lie
| Bias | What happens | How to avoid it |
|---|---|---|
| Overfitting | Rules are tuned until they fit past noise perfectly | Few parameters, out-of-sample tests |
| Look-ahead bias | The test uses information that wasn't available at the time | Only use data available at each decision point |
| Survivorship bias | Delisted or bankrupt stocks are missing from the data | Use survivorship-free data sets |
| Ignoring costs | Fees and slippage are left out | Model realistic costs on every trade |
From backtest to trading bot
If a strategy survives honest testing and paper trading, it can be automated through a broker's API — with risk controls such as maximum position size, daily loss limits and a kill switch. Fraser AI Solutions builds custom backtests and trading bots to each trader's specification.
This guide is general education, not investment advice. Trading involves risk of loss, and past performance — real or backtested — doesn't predict future results.