A backtest replays a trading rule on past prices to show what it would have done. Here is how to run one properly, the mistakes that make backtests lie, the tools, and a real backtest on a year of NVDA prices, including the parts that did not work.
Updated November 16, 2026
19
min to read
The short answer
To backtest a trading strategy, write the rule precisely enough for a computer to follow, run it on past prices with trading costs included, and read the return, max drawdown, number of trades and time in the market next to buy and hold. Then test it again on data it has never seen, and on paper, before risking money.
A backtest is a simulation. You take a trading rule, run it over past prices, and record every trade it would have made: when it bought, when it sold, what each trade earned or lost, and how the account grew or shrank along the way. TradingView’s documentation describes backtesting as a way to evaluate “the past performance of a trading strategy or model by simulating and analyzing its results on historical market data.”
Done well, it is the cheapest way to kill a bad idea. In minutes it shows what you would otherwise learn with real money: how often the rule trades, how deep its losing stretches go, and whether it did any better than simply buying and holding the same market over the same dates.
What it can’t do is tell you the future. A backtest measures one path the market already took, under assumptions you chose. Change the dates, the market or the costs and the answer can flip, as the real example below shows. TradingView’s own docs warn that simulated results may not fully account for real-world factors, and that no strategy’s past performance can be counted on to continue. Asking an AI assistant to run one adds its own wrinkle: our guide to AI backtesting covers when ChatGPT or Claude actually runs the numbers, and when they just describe a plausible result.
| Term | What it means |
|---|---|
| Backtest | Running a fixed rule on past prices to see what it would have done. |
| Buy and hold | Buying on the first day and holding to the last. It is the plain benchmark a rule has to beat to be worth the effort. |
| Out-of-sample test | Running the same rule, unchanged, on data you did not use to build or tune it. |
| Forward test, or paper trading | Running the rule on live prices as they arrive, with simulated money. |
Seven steps, in this order. The first is where most backtests go wrong.
“Buy when it looks oversold” is not a rule. “Buy at the next day’s open when the daily RSI(14) closes below 30” is. Write down the market, the timeframe, the entry, the exit, the position size and any stop, so a computer could follow it with no judgment calls.
Use the data you would actually trade on, and know what it is: which venue, which time zone, whether it includes weekends, whether stock prices are adjusted for splits. Choose a period with rises, falls and flat stretches, not one clean rally.
Every buy and sell pays a fee and usually a spread. Slippage is the gap between the price you wanted and the price you got. Perpetual futures also pay or receive funding while you hold them. TradingView’s strategy tester charges no commission and no slippage unless you set them.
Each decision may only use data that existed at that moment. If the signal comes from a day’s close, the trade happens after that close, at the next open. That is also how TradingView fills orders on past bars by default.
Total return, max drawdown, number of trades, win rate and time in the market, all compared with what holding the market did over the same dates. The table below says what each one tells you.
Run the unchanged rule on a later period and on other markets. If you tuned anything in the steps above, this is the test that counts. Our guide to quantitative trading shows a rule that looked fine on the data it was fitted on, then failed this test.
Paper trade it on live prices for a while. TradingView’s docs point out that a forward test can’t suffer from look-ahead bias, because there is no future data to leak into it. Our paper trading guide covers testnets, demo accounts and a 30-day plan.
| Number | What it measures | What to watch for |
|---|---|---|
| Total return | How much the account grew or shrank over the test. | Compare it with buy and hold over the same dates, not with zero. |
| Max drawdown | The worst fall from a peak to a low, in percent. | Ask whether you could sit through it. A live drawdown can be deeper than any in the past. |
| Number of trades | How many times the rule bought and sold. | With a handful of trades, one lucky trade decides the result. |
| Win rate | The share of closed trades that made money. | Means little alone: many small wins can be erased by one large loss. |
| Time in the market | The share of days the rule held a position. | A rule that sits in cash looks good in a falling market and lags in a rising one. |
| Buy and hold | Buying on day one and holding to the end. | The benchmark. If a rule can’t beat it, ask what the rule is for: a smaller drawdown can be a reason, but say so. |
Here is one backtest, run start to finish on real prices. The rule is a textbook one: the RSI, or Relative Strength Index, a 0 to 100 gauge of how strongly a market has moved up or down over its recent closes. J. Welles Wilder published it in his 1978 book New Concepts in Technical Trading Systems and treated readings under 30 as oversold and over 70 as overbought, as StockCharts’ ChartSchool explains.
| RSI rule | Buy and hold | |
|---|---|---|
| Return, including costs | +2.2% | -10.5% |
| Return with no costs | +2.5% | -10.4% |
| Max drawdown, on daily closes | -16.6% | -33.2% |
| Trades | 2 (1 still open at the end) | 1 buy |
| Winning trades | 1 of 1 closed | Not applicable |
| Time in the market | 21.5% of days | 100% of days |
| Trade | Signal | Bought | Sold | Result |
|---|---|---|---|---|
| 1 | RSI closed at 27.7 on Feb 5 | Feb 6 at $170.32 | Apr 15 at $196.08, after RSI closed at 70.4 | +14.9% |
| 2 | RSI closed at 22.8 on Nov 5 | Nov 6 at $180.82 | Still open, valued at the Nov 13 close of $160.94 | -11.1% |
On the headline number the rule won: +2.2% against -10.5% for buy and hold, with half the drawdown. It would be easy to stop there. Look at what produced that number first:
| Stop the test on | RSI rule | Buy and hold |
|---|---|---|
| Oct 5, 2026 | +14.9% | +33.6% |
| Nov 6, 2026 | +19.4% | +4.6% |
| Nov 13, 2026 | +2.2% | -10.5% |
Same rule, same data, and the verdict flips with the day you stop counting: buy and hold wins by a mile on October 5, the rule wins on November 6, and both shrink by November 13. That isn’t a flaw of this example. It is what any backtest with two trades looks like.
Testing on data the rule wasn’t built on is the out-of-sample step. We tuned nothing (14, 30 and 70 are Wilder’s textbook settings), so the honest next check is to run the identical rule, over the same dates and with the same costs, on other markets from the same snapshot.
| Market | Trades | RSI rule | Buy and hold | Rule max drawdown | Time in market |
|---|---|---|---|---|---|
| NVIDIA | 2 (1 open) | +2.2% | -10.5% | -16.6% | 21.5% |
| Tesla | 2 | +37.7% | -9.3% | -20.2% | 53.4% |
| XYZ100 index | 2 (1 open) | +19.2% | +9.6% | -2.5% | 7.1% |
| Bitcoin | 2 (1 open) | -16.1% | -24.6% | -28.7% | 56.9% |
| Ether | 2 (1 open) | -13.8% | -36.3% | -36.1% | 57.5% |
| Solana | 3 (1 open) | -14.3% | -45.4% | -26.2% | 54.4% |
| HYPE | 1 | +40.3% | +97.5% | -25.7% | 11.9% |
The same rule and costs as above, on Hyperliquid daily candles taken November 14, 2026, with RSI computed from the first candle each market has in that data: October 2025 for the crypto markets and XYZ100, November 2025 for NVIDIA and Tesla (Tesla’s test starts a day later, on November 27, 2025, its first full RSI reading; XYZ100 is trade.xyz’s index of 100 large US non-financial stocks). Read it slowly:
The lesson is the method, not the rule. A year of daily data shows how a slow signal like this behaves; it can’t show whether it works. To judge it you would need many more trades: more years, more markets, or a faster timeframe, each with its own costs. For more rules tested this way, see six automated Hyperliquid strategies, backtested.
These are the classic ones. Each makes the past look kinder than trading the rule will be.
Overfitting means tuning a rule until it fits the noise of the past instead of a pattern that repeats. Try enough settings and one will look great by chance. David Bailey and Marcos López de Prado, with Jonathan Borwein and Qiji Zhu, worked out how fast this happens. Their yardstick is the Sharpe ratio, a strategy’s average return divided by how much that return swings. With five years of data, trying 45 independent variations of a rule with no real edge is enough to expect the best one to show a Sharpe ratio of 1 in the backtest, while its expected result on new data is zero. With two years of data, 7 variations are enough. Their conclusion: a backtest that doesn’t say how many variations were tried can’t be judged.
Real strategies show the same gap. Researchers at Quantopian, a platform where users wrote and tested trading algorithms, compared the backtests of 888 algorithms with at least six months of results after them. The backtest Sharpe ratio explained almost none of what came next (an R² under 0.025), and the more a strategy had been backtested, the bigger the gap between its backtest and what followed.
Using information the rule could not have had at the time: buying at the same close that produced the signal, using a day’s high or low before the day is over, or reading a higher timeframe’s candle before it has closed. TradingView calls it the leakage of future data into the past and lists it among the common causes of unrealistic strategy results. Act on the next bar, and forward test, where there is no future to leak.
Testing only what still exists today. Backtest a stock rule on today’s index members and you leave out the companies that collapsed and were dropped, so the past looks better than it was. Edwin Elton, Martin Gruber and Christopher Blake documented the same effect in mutual funds: funds that disappear tend to do so because of poor performance, which flatters any study that looks only at the survivors. In crypto, the same goes for coins that were delisted. Use lists of what existed at each point in time, dead names included.
As in the example above. A handful of trades can’t separate skill from luck. Get more trades from more history, more markets or a faster timeframe, and look at the spread of results, not the best one.
Fees, spreads, slippage and funding come out of every trade. Pierre Bajgrowicz and Olivier Scaillet tested technical trading rules on the Dow Jones Industrial Average from 1897 to 2011 and found that, even in sample, their performance was “completely offset by the introduction of low transaction costs.” TradingView’s docs show the same thing on a small scale: adding a 1% commission to their demo strategy significantly cut its net profit and deepened its drawdown.
Each time you tweak a rule because the last result disappointed, you run a new test on the same data, and the version you keep inherits every try before it. That is the trial count Bailey and his co-authors say a backtest must report. Write the rule down first, run it once, and if you change it, test the new version on data it has never seen.
| Mistake | The sign | The fix |
|---|---|---|
| Overfitting | Great results that vanish when you nudge a setting | Few settings, chosen before you test; count every try |
| Look-ahead bias | Fills at prices the rule could not have known | Act on the next bar; forward test |
| Survivorship bias | Only markets that still exist today | Use lists that include delisted names |
| Too few trades | One or two trades decide the result | More history, more markets or a faster timeframe |
| Ignoring costs | Profits that come from many small trades | Charge fees, spread and slippage on every fill |
| Editing the rule after the fact | The tenth version is the one you kept | Write it first; test any change on fresh data |
| Cherry-picking | The one market or period that worked | Show every market and period you tried |
| Synthetic charts | Tests on Heikin Ashi or Renko candles | Test on standard candles; TradingView says the others typically give unrealistic results |
Pick the tool by how much you want to write yourself. Each can do the job; they differ in what you must supply and what they assume for you. For a longer comparison, see best backtesting software.
| Tool | Good for | You need | Watch out for |
|---|---|---|---|
| A spreadsheet | Learning, and simple daily rules | Price data and patience | It is easy to let tomorrow’s price slip into today’s formula |
| TradingView strategy tester | Chart traders; built-in and community strategies on many markets | Pine Script, TradingView’s language, to write your own | No commission and no slippage unless you set them; higher bar detail needs a Premium or Ultimate plan |
| backtrader (Python) | Event-by-event simulation in a long-standing open-source library | Python | Its latest release on PyPI dates from April 2023 |
| vectorbt (Python) | Testing many variants at once on pandas data; its site says thousands of strategies in seconds | Python and pandas | That speed makes overfitting easy, so count your tries; some features, such as leverage, are in the paid PRO version |
| No-code builders | Clicking a rule together from indicators | An account with the provider | Check which data, fills and costs they assume |
| Ethy | Describing a rule in plain English and testing it on Hyperliquid markets or spot tokens | Nothing to code | Windows depend on the timeframe, up to 365 days |
To have Claude read your TradingView charts instead, see how to connect Claude to TradingView.
A backtest is exact about the past and silent about the future. Given the same data, rule and costs, it gives the same answer every time. Whether that answer carries forward depends on things you can check:
If you are weighing whether AI trading tools can make money at all, and how to tell a real one from a scam, read our guide to whether AI trading is legit.
If you would rather not write code, you can describe the rule to Ethy the way you would to a person, for example the NVDA rule above in one sentence. Ethy turns it into rules you can preview, backtests the exact version it would run, and shows every entry and exit on the chart next to buy and hold. It covers Hyperliquid’s perps, trade.xyz’s stocks, indices and commodities included, and spot tokens.
Ethy presents backtest results as estimates on past data, not a promise. Everything above still applies: few trades, the end date and cherry-picking can fool any tool, ours included.
Yes. A spreadsheet works for simple daily rules, and backtrader and vectorbt are free Python libraries (vectorbt also sells a PRO version). TradingView’s strategy tester runs built-in and community strategies; some deeper settings need a paid plan. On Ethy’s free plan, backtests run on the shortest window of each timeframe, 180 days on the daily.
There is no magic number, but more is better, and the results should hold across rising, falling and flat periods. One or two trades, as in our NVDA example, can’t separate a pattern from luck. If a slow rule trades rarely, add more history or more markets rather than tuning it until the few trades look good.
A backtest runs the rule on past data all at once. Paper trading, or forward testing, runs it on live prices as they arrive, with simulated money. Paper trading is slower but can’t leak future data into the test, and it shows how fills and costs behave now. Do both, in that order, before real money.
A chat assistant can write backtest code and explain results, but a number it states is only as good as the code and data behind it. Ask it to show the code, the data source and the full list of trades, then check a few trades by hand against the chart. A return with no trade list behind it is not a backtest.
Yes, as a filter. It is the cheapest way to learn that a rule loses money, trades too rarely or has drawdowns you couldn’t live with. What it can’t do is prove a rule will work. Treat a good result as a reason to keep testing, out of sample and on paper.
If you hold perp positions for days, yes: funding is a cost or a credit for as long as you hold. Our example left it out, which is one more reason to treat its numbers as a rough sketch rather than a trading record.
Trading involves risk, including the loss of your money. Ethy AI is a research and trading tool and does not give investment advice or recommendations. Backtests are simulations on historical data and do not predict future results.
Deploy your AI trading agent in one click.
