Choosing a backtest date range
The date range you optimize on quietly decides everything that follows. Too short and you tune to noise; cherry-picked to one smooth uptrend and you learn nothing about how the strategy behaves when the market turns. This is the decision to get right before you touch a single parameter.
Too short, and you are optimizing noise
A backtest over a few months produces a handful of trades, and a handful of trades is mostly luck. Optimize on that window and the settings you find are tuned to the specific wiggles of that slice, not to anything repeatable. The first job of a date range is to generate enough trades that the metrics mean something. See minimum trade count for how many is enough.
Warning
Recency bias
Optimizing only on the last few months bakes in whatever regime just happened. A strategy tuned to a calm uptrend falls apart the first time volatility returns.
Span bull, bear, and chop
Markets move through regimes: trending up, trending down, and ranging sideways. A robust strategy survives more than one of them. Choose a range long enough to contain at least one clear uptrend, one drawdown or downtrend, and one period of choppy, directionless price. If your window is one uninterrupted bull market, a strong backtest tells you the strategy is long-biased, not that it is good.
Mind TradingView's data limits
How much history you actually get depends on your TradingView plan and the timeframe. Lower timeframes give you far fewer days of history than daily bars, so a 5-minute backtest may only reach back a few months even though the daily chart goes back years. Check how far your bars actually load before committing to a range, and prefer a higher timeframe when you need more regime coverage. See timeframe-specific optimization for the trade-offs.
Expose the backtest window as inputs (Pine v5)
Pine v5Date inputs let you slide the optimize window and reserve a holdout without editing code. Gate entries so the strategy only trades inside the chosen range.
//@version=5
strategy("Windowed Backtest", overlay=true)
startDate = input.time(timestamp("2021-01-01 00:00"), "Backtest start")
endDate = input.time(timestamp("2024-12-31 23:59"), "Backtest end")
inWindow = time >= startDate and time <= endDate
// ... your entry condition ...
longSignal = ta.crossover(ta.sma(close, 20), ta.sma(close, 100))
if longSignal and inWindow
strategy.entry("Long", strategy.long)
if not inWindow
strategy.close_all() Reserve an out-of-sample tail
Whatever range you pick, do not optimize on all of it. Hold back the most recent slice, often the last 20 to 30 percent, and never let the optimizer see it. After you have your settings, run that holdout once. If the strategy falls apart on data it was not tuned to, you overfit. This single habit is the difference between a number you can trust and a number that flatters you. The full method is in in-sample vs out-of-sample.
Key idea
The one rule
Pick a range long enough to cover several regimes and produce a few hundred trades, then carve off the most recent slice as a holdout before you optimize.
Key takeaways
- Too short a range optimizes noise; aim for several hundred trades.
- Cover bull, bear, and sideways regimes, not one smooth uptrend.
- Lower timeframes load far less history; check before committing.
- Always reserve a recent out-of-sample slice you never optimize on.
Frequently asked questions
How long should a backtest date range be?
Long enough to span at least one uptrend, one downtrend or drawdown, and one sideways period, and to produce a few hundred trades. For daily and higher timeframes that usually means several years; for intraday timeframes you are often limited by how much history TradingView loads.
Should I optimize on the full date range?
No. Hold back the most recent 20 to 30 percent as out-of-sample data and never optimize on it. Use it once at the end to check whether the tuned settings generalise.
Why do my intraday backtests only go back a few months?
TradingView loads a limited number of bars per timeframe, and that limit translates to far fewer calendar days on a 5-minute chart than on a daily chart. Use a higher timeframe when you need more regime coverage and history.
Related guides
- Beginner
Choosing parameter ranges
Set smart min, max, and step ranges before optimizing a TradingView strategy. Tame the combinatorial explosion, fit your cycle budget, and work coarse to fine.
Read the guide - Intermediate
How many trades is enough?
How many trades a TradingView backtest needs before its metrics mean anything: sample size, statistical noise, and why too few make optimization a coin flip.
Read the guide - Intermediate
In-sample vs out-of-sample
Split TradingView backtest data into in-sample and out-of-sample periods, choose a split ratio, hold out data, and detect leakage when optimizing.
Read the guide
Put it into practice
Install TradingTune and optimize any TradingView strategy right in your browser. Free tier, no API keys. A free account is required to run.
Add to Chrome, it's free