How to Backtest a Trading Strategy in 6 Steps (No Code)
April 7, 2026 · AgentTrading
- 1 THESIS
- 2 EVIDENCE
- 3 BACKTEST
- 4 RISK
- 5 VERDICT
02 EVIDENCE · FUNDAMENTALS
04 RISK · IN PLAIN ENGLISH
Sample scenarios, not a live backtest of what you typed. Past performance does not guarantee future results. Educational analysis only, not financial advice.
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.
How do you do backtesting of stocks?
Backtesting a stock strategy means applying one explicit entry and exit rule to that stock's historical price record and comparing the outcome to simply holding it. Write the rule down precisely, pull 20+ years of split- and dividend-adjusted daily prices, charge a realistic cost on every trade, then measure total return, worst drawdown, and number of trades against buy-and-hold over the identical window. Anything less specific is not a backtest.
The single-stock case has one trap worth naming: survivorship. Testing a rule on a company that did well over the past two decades tells you about that company as much as about your rule, so run the same rule across several tickers, including ones that struggled, before believing it. The strategy tester handles the mechanics; the discipline of testing losers too is yours.
How do you backtest an investment strategy rather than a trade?
For an investment strategy, the unit under test is an allocation and a schedule instead of an entry signal. You specify the holdings and weights, say how often it rebalances, then run the mix across the same 20+ year window with a cost charged on every rebalance and compare against a single benchmark fund. The output that matters is compound growth next to worst drawdown, since the strategy you cannot hold through a bad year is not a strategy you own.
The mechanics for fund mixes are covered on ETF backtesting, and multi-asset portfolios with rebalancing schedules on portfolio backtesting.
How much history and how many trades does a backtest need?
At least 20 years of adjusted daily data and at least 100 to 200 closed trades, whichever bar is harder for your rule to clear. The calendar rule forces the strategy through 2008 and 2020 rather than only through a bull market; the trade-count rule keeps the average from being built out of two lucky outcomes. Fail either and the result is provisional at best.
The full checklist, including the out-of-sample split and the removal test, is in how long you should backtest a trading strategy. If your platform makes this hard, does thinkorswim have backtesting explains why the free tools stop where they do, and the same question answered for other brokers covers E*TRADE backtesting, which is options-income only, and tastytrade backtesting, where the Looks Like a Backtest tool stops at options structures.
Applying the same six steps to a whole allocation rather than one signal is its own exercise, and how to backtest a portfolio walks through weights, rebalancing schedules, and the drawdown that a mix actually produces. Running them on a single ticker is the opposite problem, with a much thinner sample and a heavy dose of company-specific luck, which is covered on stock backtesting.
How accurate is a backtest once you finish it?
Accurate about the past under stated assumptions, and consistently optimistic about the future. The decay has been measured: McLean and Pontiff studied 97 published stock-return predictors and found their returns were 26% lower out of sample and 58% lower after publication. Every common error, from unmodeled costs to quiet parameter tuning, pushes results the same flattering direction, which is why symmetric-looking measurement error is not what you should expect here.
The number of variants you tried is part of the answer too, and almost nobody records it. Bailey, Borwein, Lopez de Prado and Zhu showed that with only five years of daily data, trying more than about 45 independent strategy configurations is close to guaranteed to produce an in-sample Sharpe ratio of 1.0 with an expected out-of-sample Sharpe of zero. Count your attempts, write the rule down before you look at the data, and read the drawdown before the return. The six specific leaks that cause the gap, and how to detect each one, are set out in is backtesting accurate.
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.