How to Backtest a Trading Strategy in 6 Steps (No Code)
April 7, 2026 · Agenttrading
To backtest a trading strategy, define the rule precisely, get split- and dividend-adjusted historical data, include trading costs, run the rule mechanically over the full period, read the drawdown as carefully as the return, and sanity-check the result out of sample. Those six steps separate evidence from wishful thinking, and none of them requires code. Here is each step in detail, with the numbers that matter and the mistakes that quietly ruin results.
Step 1: Define the trading rule precisely
A backtest can only test a rule a computer could follow without asking you anything. "Buy quality stocks when they dip" is a mood, not a rule. "Buy SPY at the close when the 14-day RSI drops below 30, sell at the close when it rises above 55" is a rule: it names the asset, the entry condition, the exit condition, and the execution price.
Write down four things before anything runs:
- Universe: which ticker or basket the rule trades (SPY, AAPL, a list of dividend blue chips).
- Entry: the exact condition that opens a position, with every parameter stated (RSI period 14, threshold 30).
- Exit: the exact condition that closes it. A rule with no exit is half a rule.
- Sizing: what fraction of capital each position takes. All-in-all-out is fine for a first test; just say so.
The test is only as honest as this specification. A stranger reading your rule should reach the same trades you would. This is also where a trading strategy builder earns its keep: you type the sentence, and it restates the structured rule card, entry and exit with every parameter filled in, so you can catch a misreading before the test runs.
Step 2: Get quality historical data (adjusted, 20+ years)
Use daily prices adjusted for splits and dividends, covering 20 or more years so the rule faces bull markets, bear markets, and long sideways stretches. Two data flaws inflate results more than any other:
- Unadjusted prices. A 4-for-1 stock split looks like a 75 percent overnight crash in raw data, and ignoring dividends understates long-run equity returns badly: dividends have contributed on the order of a third of the S&P 500's total return over long horizons.
- Survivorship bias. Testing a rule only on companies that still exist today quietly deletes every bankruptcy and delisting from history. The survivors, by definition, did well.
Twenty-plus years matters because it forces the rule through at least two full cycles: the 2007-2009 financial crisis (S&P 500 down roughly 57 percent from its October 2007 close to its March 2009 close), the 2020 COVID crash (down about 34 percent in 23 trading days), and the grinding 2022 bear market. A rule tested only on 2012-2021 has never met a real bear. The historical stock data page explains what a clean, adjusted 20-year record looks like and why every test here runs on one.
Step 3: Include trading costs in the backtest
Model commissions, bid-ask spread, and slippage on every trade. For liquid US stocks and ETFs, a reasonable default is about 0.1 percent per trade, round trips counted as two trades. That sounds tiny. It is not, because it compounds with trade count:
| Trades over the test | Cost per trade | Approximate cumulative drag |
|---|---|---|
| 20 | 0.1% | about 2% |
| 100 | 0.1% | about 10% |
| 200 | 0.1% | about 18% |
| 500 | 0.1% | about 39% |
A fast mean-reversion rule that trades 200 times in 20 years must beat its benchmark by roughly 18 percentage points cumulatively just to pay its own tolls. Many published "edges" exist only at zero cost. If a rule's advantage disappears when you add 0.1 percent per trade, you have learned something valuable: the edge was never yours to keep.
Step 4: Run the rule over the full period, no exceptions
Apply the rule mechanically to every bar in the record, with no discretion, no "I would have skipped that one," and no pausing during the ugly stretches. The moment you hand-edit trades, the output stops being a test and becomes a story.
Plot the strategy's equity curve against a buy-and-hold benchmark of the same asset over the same dates. That comparison is the whole point: a strategy that turned $10,000 into $30,000 sounds good until you see that simply holding the same ticker made $45,000. Dedicated backtesting software does this pass in minutes and, just as important, prints the assumptions on the result: date range, cost per trade, rule parameters, dividend treatment. If an assumption would change the answer, you want it visible, not buried in a spreadsheet cell.
Step 5: Read the drawdown, not just the return
Find the maximum peak-to-trough decline, how long it lasted, and how long recovery took. Then answer the only question that matters: would you actually have held through it?
Two rules with identical 20-year returns are not equal if one spent 4 years underwater and the other spent 14 months. The arithmetic of recovery is brutal and asymmetric: a 20 percent drawdown needs a 25 percent gain to break even, and a 50 percent drawdown needs 100 percent. As a concrete anchor, an investor who held the S&P 500 through the 2007-2009 decline waited until roughly March 2013, about five and a half years from the 2007 peak, for the price index to make a new high. Our post on maximum drawdown walks through the recovery math in full.
Past performance does not guarantee future results. For educational and informational purposes only. Not financial advice. Consult a licensed advisor.
Step 6: Sanity-check the result out of sample
The final step catches the most seductive failure in all of backtesting: a rule fit to noise. Do three checks before believing any result.
- Hold out data. Re-run the rule on a period or a ticker you did not look at while designing it. A rule tuned on 2003-2015 should be judged on 2016-2025.
- Nudge every parameter. If RSI(14) with a 30 threshold works but RSI(12) or a 32 threshold falls apart, the result is a coincidence wearing a lab coat. Robust rules degrade gracefully; overfit rules shatter.
- Count the trades. A rule that fired 9 times in 20 years proves almost nothing, whatever the chart shows. Small samples produce spectacular flukes.
Most impressive backtests die at this step, and that is the step working as intended. A weak idea disproven in an afternoon costs nothing; the same idea discovered with real money costs a great deal more. The companion piece on common backtesting mistakes catalogs the seven ways results lie, including look-ahead bias, the subtle cousin of overfitting.
What a finished backtest should tell you
A complete backtest answers five questions in plain language: what exact rule was tested, on what data and date range, at what assumed cost, how it compared to buy-and-hold, and how bad the worst stretch was. If any of those five is missing, the test is not finished. And even a finished test describes history, not the future; regimes change, and a rule's past behavior is evidence to weigh, never a promise.
If you want to run this loop without a spreadsheet weekend, an AI trading assistant can take the rule as a plain-English sentence, restate it before running, test it on 20+ years of split- and dividend-adjusted daily data with costs included by default, and stamp an honest verdict, including UNDERPERFORMED when buy-and-hold wins. Pick an idea you have been carrying around, write it down as a rule, and see what two decades of history actually say.
Put it on the bench
Ideas are cheap. Verdicts take a bench.
Agenttrading restates your idea as a testable rule, backtests it on 20+ years of adjusted daily data, and explains the risks in plain English. Honest verdicts, even when the idea loses.
Past performance does not guarantee future results. For educational and informational purposes only. Not financial advice. Consult a licensed advisor.