All guides

How to Backtest a Trading Strategy (Without Fooling Yourself)

7 min read · Updated October 2026

A backtest replays a set of trading rules over historical prices to see how they would have behaved. Done well, it is the cheapest way to find out whether an idea has any edge before you put money behind it. Done badly, it produces a beautiful equity curve that falls apart the moment you trade it live.

This guide walks through the process we use in NightShift Trader, and the traps that make most backtests look better than reality.

1. Write rules a computer could follow

Every rule must be unambiguous. "Buy when the trend looks strong" cannot be tested. "Buy at the close when the 50-day moving average crosses above the 200-day moving average" can. You need four things: an entry condition, an exit condition, a stop-loss or risk rule, and a position size.

If you cannot write the strategy down precisely, you are not ready to test it, and you are certainly not ready to trade it.

2. Use enough data, from more than one market regime

A strategy tested only on a rising market will look like genius. Include at least one meaningful drawdown in your test window. For daily-bar strategies on stocks and ETFs, several years of data is a sensible minimum; for crypto, cover both a bull run and a bear phase.

Indicators also need warm-up history. A 200-day moving average has no value for the first 200 bars, so load extra history before the test period starts rather than letting early signals be computed on incomplete data.

3. Model fills the way they actually happen

  • Only act on information available at the time. If a signal uses the closing price, the earliest realistic fill is that close or the next open, never the bar's low.
  • When a price gaps through your stop overnight, you are filled at the open, not at your stop price.
  • If a stop and a target are both touched inside the same bar, assume the stop hit first. You cannot know the order, so take the pessimistic outcome.
  • Account for commissions and slippage, especially for strategies that trade often.

4. Read the right statistics

Total return alone says little. Look at maximum drawdown (the worst peak-to-trough fall, which is what you will actually have to sit through), win rate together with average win versus average loss, number of trades (a handful of trades proves nothing), and how the strategy compared with simply buying and holding the same asset.

A strategy that trails buy-and-hold but cuts the drawdown in half may still be worthwhile. One that beats buy-and-hold on six trades probably is not.

5. Stress the result before you trust it

Change the parameters slightly. If a 50/200 crossover works but 45/190 and 55/210 fail, you have found noise, not an edge. Test on a period you did not use while designing the rules. Then forward-test on paper in real time, where hindsight cannot help you.

Try it

In NightShift Trader you can describe a strategy in plain English, have it compiled into exact rules, and backtest it on real stock, ETF and crypto data with the fill rules above built in. Then deploy it as a paper-trading agent to see whether live results match the test.

Test your own strategy for free

Describe it in plain English, backtest it on real data, then paper-trade it. No card required.

Start free