Guide

How TradingView Backtesting Actually Works

The Strategy Tester is easy to trust too much. Understanding how it fills orders and what it assumes is the difference between a real backtest and a comforting illusion.

12 min read

TradingView's Strategy Tester is one of the most accessible backtesting tools anywhere. Write a strategy, and it shows you net profit, win rate, drawdown, and a list of trades, all on the chart. The danger is precisely that accessibility: it is so easy to read the headline number that people trust it without understanding what it assumes. This article is about those assumptions, because they are where backtests quietly mislead.

AssumptionWhat it can hide
Orders fill at bar closeReal fills happen intrabar, at worse prices
calc_on_every_tick offHistorical and live results differ
No slippage or commission setResults look far better than reality
Lookahead in requestsFuture data leaks into the backtest
Too few tradesResults are statistically meaningless

How orders get filled

By default, the Strategy Tester evaluates your strategy on the close of each bar and fills market orders at the open of the next bar. That is a reasonable, conservative model, but it is a model, not reality. Real fills happen intrabar at whatever price is available, which can be worse than the assumed price, especially on gaps or fast moves. The tester cannot see what happened inside a bar unless you tell it to, so a strategy that depends on precise intrabar timing may look better in the test than it could ever perform live.

calc_on_every_tick and intrabar behavior

The calc_on_every_tick setting changes when your strategy is evaluated. Off, it calculates on bar close, matching how historical bars work. On, it calculates on every realtime tick, which can make live behavior diverge from the historical backtest, because history has no ticks to replay. This connects directly to the historical-versus-realtime distinction in the execution model guide. If your live results differ from your backtest, this setting is one of the first things to check.

pine
//@version=6
strategy("Realistic test settings", overlay = true,
     commission_type = strategy.commission.percent,
     commission_value = 0.05,
     slippage = 2,
     calc_on_every_tick = false)

longSignal = ta.crossover(close, ta.sma(close, 50))
if longSignal
    strategy.entry("Long", strategy.long)

exitSignal = ta.crossunder(close, ta.sma(close, 50))
if exitSignal
    strategy.close("Long")

Slippage and commission: the silent inflators

A backtest with zero slippage and zero commission is almost always too optimistic. Every real trade costs something: a spread, a commission, a little slippage on entry and exit. Leave those at zero and a strategy that trades often can show impressive results that evaporate once realistic costs are applied. Set commission and slippage to values that match your broker and instrument before you believe any headline number. This is a settings change, not a code change, and it is the single most common reason a strategy looks better in the tester than in an account.

Realistic assumptions matter more than the headline net-profit figure

Lookahead and future leaks

If your strategy uses request.security with lookahead enabled, or otherwise references data that would not have been known at decision time, the backtest is reading the future. This produces beautiful equity curves that are impossible to trade. It is the same future-leak repainting covered in repainting explained and multi-timeframe analysis without repainting. A backtest that looks too good is often a backtest that cheated, and lookahead is the most common way it happens.

Sample size and statistical meaning

A strategy with eight trades tells you almost nothing, no matter how good the numbers look. You need a meaningful sample, generally at least 50 to 100 trades, before the results carry statistical weight, and more is better. This is one reason the v6 unlimited backtesting change matters: testing over more history produces more trades and more reliable statistics. Judge a backtest by its sample size first and its headline return second.

Reading results honestly

Net profit is the most misleading number to lead with, because it says nothing about risk, consistency, or how the profit was earned. Look at the number of trades first, then at risk-adjusted measures and drawdown, then at whether the assumptions were realistic. A modest, robust result with realistic costs and a large sample is worth far more than a spectacular one built on zero costs and forty trades. If you use the platform's performance calculators, feed them numbers from a test you actually trust.

Most of these pitfalls are settings and correctness issues, not strategy issues, and they are exactly what generic AI-generated strategies get wrong, since a model cannot see the tester or feel the difference between historical and realtime bars. PineScripter generates strategies with realistic, non-repainting structure and sensible defaults, so the backtest you read reflects behavior you could actually have traded. If you want a strategy whose test you can trust before you commit to it, build it at PineScripter.


Disclaimer: PineScripter is a coding tool for Pine Script development. It does not provide financial advice and does not guarantee trading profits. Always backtest strategies thoroughly and understand the risks before live trading.