Pine Script backtest validation
How can a Pine Script strategy avoid a fill before its signal was known?
Under TradingView default strategy settings, an order created when a bar closes can fill no earlier than the next bar open in the broker emulator. On-close processing changes the simulated timing and requires an explicit realism check.
TradingView's strategy report summarizes simulated trades. Its result depends on chart data, order settings and the rules chosen before testing.
What the Strategy Report measures
A Pine Script strategy creates hypothetical orders on historical and realtime bars. The Strategy Report lists simulated trades and summarizes returns, costs and risk metrics for the selected chart and settings.
A positive report is a result for that script and sample. Record the symbol, period, chart type, commission, slippage and order settings before comparing runs.
Fill assumptions and repainting
TradingView's broker emulator infers intrabar movement from chart prices by default. Bar Magnifier uses lower timeframe data where available, so an order can fill on a different bar.
With calc_on_every_tick enabled, a realtime strategy recalculates as updates arrive. Historical bars lack that same tick sequence, so a reloaded strategy can show different historical trades.
Higher timeframe requests can also leak future values when lookahead is enabled without an offset. Confirmed values and a fixed request convention make historical and realtime signals comparable.
A delayed signal on eight bars
Consider eight closes, in order: 99, 100, 101, 100, 99, 100, 101, 100. The entry rule is close > 101.5; no completed close passes it.
On bar four, suppose realtime updates are 100, 102, 102, 100. At the second update, 102 > 101.5 places a long market order; assume it fills on the next update at 102. The last update places an exit order because 100 <= 101.5; assume bar five opens at 99 and fills that exit. The realtime path has one trade with gross price change 99 - 102 = -3, while the confirmed-close rule has zero trades because no completed close exceeds 101.5.
With calc_on_every_tick, that provisional signal may place an order before the bar closes. Gating the rule with barstate.isconfirmed delays the decision until close; reading the previous close on the next bar also uses a completed value. These rules do not reconstruct an intrabar fill after a reload.
For higher timeframe data, request.security with a previous-bar expression and lookahead = barmerge.lookahead_on requests the last completed daily value. lookahead_on with an unshifted close would expose future daily values on historical bars.
Validate selection before Pine export
Keep a record of candidate rules and parameters. Use held-out periods or walk-forward windows, then examine the deflated Sharpe ratio and PBO for the search that selected the strategy.
Stochastly exports supported graph strategies to Pine Script from its intermediate expression tree. The export report identifies unsupported graph blocks and measured signal coverage; Pine source checks do not establish compiled or trade-level parity in TradingView.
After export, compare signal bars and direction against the Stochastly run on matching data. Recheck commissions, slippage, session boundaries and fills in TradingView.
Frequently asked questions
Does Strategy Report prove a strategy is robust?
It reports simulated performance for the chosen script, sample and settings. A separate search record and tests on unseen periods are needed to assess selection bias.
Does Bar Magnifier remove fill uncertainty?
It uses lower timeframe data where available. Compare its fills with the default emulator and inspect bars without intrabar coverage.
Sources
TradingView (n.d.). Strategies. Pine Script v6 User Manual. Accessed 2026-10-03.
TradingView (n.d.). Repainting. Pine Script v6 User Manual. Accessed 2026-10-03.
TradingView (n.d.). Execution model. Pine Script v6 User Manual. Accessed 2026-10-03.
TradingView (n.d.). Strategy properties. TradingView Help Center. Accessed 2026-10-03.