Backtesting Explained: How to Test a Trading Strategy Honestly
Backtesting means running a trading rule on past prices to see how it would have performed. If your rule is "buy when price closes above the 50-day average, sell when it closes below," a backtest goes through history day by day, applies the rule, and records every trade. It is the cheapest way to find out whether an idea has any merit. It is also one of the easiest ways to fool yourself.
How a backtest works
- Define the rule exactly. Entry, exit, position size, and what price you trade at. "Buy on strength" is not testable. "Buy at the next day's open after the close crosses above the 50-day SMA" is.
- Choose the data. Which assets, which dates, which timeframe.
- Step through history. At each bar, use only the information that would have been available then.
- Record the results. Every trade, its profit or loss, and summary statistics.
- Judge the results against a simple alternative, like buying and holding.
A worked example
Say you test a rule on one stock over a year and get 10 trades:
| Trade | Result |
|---|---|
| 1 | +$420 |
| 2 | −$150 |
| 3 | −$180 |
| 4 | +$90 |
| 5 | −$160 |
| 6 | +$610 |
| 7 | −$140 |
| 8 | −$170 |
| 9 | +$300 |
| 10 | −$120 |
- Win rate: 4 winners out of 10 = 40%.
- Average win: (420 + 90 + 610 + 300) ÷ 4 = $355.
- Average loss: (150 + 180 + 160 + 140 + 170 + 120) ÷ 6 = $153.33.
- Net result: $1,420 − $920 = +$500.
A 40% win rate sounds bad, but winners averaged more than twice the size of losers, so the rule made money in this test. That is the logic behind the risk/reward ratio. But 10 trades is far too few to trust. A couple of lucky trades decide the whole result. If trade 6 had been a normal loss instead of +$610, the net would have been negative.
Key numbers to look at
- Net profit and profit per trade, after costs.
- Win rate and average win vs average loss together, never one alone.
- Maximum drawdown: the largest peak-to-trough drop in the account. This is what you would have had to sit through.
- Number of trades. More trades give more reliable statistics.
- Comparison to buy-and-hold. A strategy that made 8% while simply holding made 20% added risk and effort for less return.
The three biases that make backtests lie
Overfitting
Overfitting is tuning a rule until it fits past data perfectly, including random noise. Suppose you test moving-average lengths from 10 to 200 and find that a 37-day average crossed with a 113-day average gave the best result. That combination probably won by luck. Test enough variations and one will always look brilliant.
Signs of overfitting:
- Very specific, odd parameter values.
- Lots of rules and filters added to remove losing trades one by one.
- Great results on the test data, much worse on any other period or asset.
How to reduce it: keep rules simple, use common settings, and hold back a chunk of data you never look at while building the rule. Test on that "out-of-sample" data once, at the end. If performance collapses, the rule was fitted to noise.
Look-ahead bias
Look-ahead bias means the test uses information that was not available at the time of the trade. Classic examples:
- Using today's closing price to decide to buy at today's open.
- Using a day's high or low before the day has finished.
- Using financial data on the period it covers rather than the date it was actually published.
- Using indicator values that were later revised.
Look-ahead bias can make a worthless rule look spectacular. The fix is strict: at each step, only use data that existed before the decision. Trading at the next bar's open after a signal on the close is a common, honest convention.
Survivorship bias
Survivorship bias comes from testing only on assets that still exist today. If you backtest on the current members of the S&P 500, you are testing on companies that grew, survived and stayed in the index. The ones that went bankrupt, were acquired cheaply, or shrank out of the index are missing. A strategy that buys dips would look far better on survivors, because in the real past some dips never recovered.
The fix is to use data that includes delisted and removed assets as they existed at the time. In crypto, this is especially important because many coins have faded to near zero.
Other things backtests miss
- Costs. Commissions, the bid-ask spread and slippage can turn a small edge into a loss, especially for strategies that trade often.
- Market regimes. A trend strategy tested only during a long bull market will look better than it deserves.
- Liquidity. Thinly traded stocks may not fill at the prices the test assumed.
- You. A backtest never panics or skips a trade after three losses. Real people do. See trading psychology.
Common mistakes
- Trusting results from a small number of trades.
- Reporting only win rate without the size of wins and losses.
- Rerunning a test many times with small tweaks and keeping the best version.
- Ignoring drawdown because the final number looks good.
- Assuming a rule that worked on one ticker works on all tickers.
How Stupid Simple Trader uses backtesting
Each ticker page shows a 6-month backtest of the signal. It checks the bullish and bearish calls made over the past six months and records whether price had moved in the called direction 10 trading days later. The calculation uses the same fixed rules for every ticker, rather than tuning settings per ticker, which avoids one obvious form of overfitting.
It still has limits worth stating plainly. Six months is a short window covering one kind of market. It measures direction only, not the size of moves or costs. Accuracy varies widely between tickers and can be below 50%. Treat it as a quick read on how well a trend-and-momentum summary has fit that asset recently, not as a forecast. The details are in how Stupid Simple Trader signals work.
Try it
Compare the backtest on a steady large-cap like /t/MSFT with a volatile asset like /t/BTC-USD to see how much signal accuracy can differ between tickers.