The No-Repaint HTF Template Pack rests on one line of Pine Script. This is how I tested that line against four near-misses, what the counts were, and where the test stops being able to see anything.
The short version: on 2,677 higher-timeframe periods across three markets, the pack’s request matched an independent reference on every bar. The version that reads the future was caught on 99.6% of mid-period bars, and every bar it was not caught on belongs to a period that closed unchanged. And one of the two mistakes the pack warns about passed the test almost perfectly, which is the part worth understanding.
Each one asks for the close of a higher timeframe from a lower-timeframe chart. This block is copied from the probe script, not retyped.
// ---- The five requests under test ---- v1 = request.security(syminfo.tickerid, htf, close) // V1: no offset, lookahead_off (the default) v2 = request.security(syminfo.tickerid, htf, close, lookahead = barmerge.lookahead_on) // V2: no offset, lookahead_on v3 = request.security(syminfo.tickerid, htf, close[1], lookahead = barmerge.lookahead_on) // V3: [1] inside, lookahead_on (the pack's idiom) v4 = request.security(syminfo.tickerid, htf, close[1]) // V4: [1] inside, lookahead_off v5 = v1[1] // V5: lookahead_off, [1] outside the call
“The naive version” means V1 and nothing else: no offset, and lookahead left at its default.
A test of request.security() that is itself built on request.security() proves nothing. The reference here uses only the chart’s own bars: it watches for the first chart bar of each new period and records the close of the bar before it, which is the close of the period that just ended.
// ---- Reference: the chart's own closes, no request.security() ----
// firstOfP is true on the first chart bar of each higher-timeframe period.
// lastOfP is true on the chart bar that finishes a higher-timeframe period.
firstOfP = timeframe.change(htf)
lastOfP = time_close == time_close(htf)
var float prevClose = na // close of the last finished period (P-1)
var float prev2Close = na // close of the period before that (P-2)
var int periodsSeen = 0
var int barsInP = 0 // chart bars elapsed in the current period
if firstOfP
prev2Close := prevClose
prevClose := close[1]
periodsSeen += 1
barsInP := firstOfP ? 1 : barsInP + 1
// What could be known at the close of this chart bar: the period's own close
// if this bar finishes the period, otherwise the previous period's close.
known = lastOfP ? close : prevClose
known is what a trader could have known at the close of each chart bar: the period’s own close if that bar finishes the period, otherwise the previous period’s close. Every request is compared against it with exact equality.
The unit of evidence is the period transition, not the chart bar. Every chart bar inside one period is asking the same question, so run A is 1,876 tests, not 5,628.
| A: BTCUSDT, 5m chart, 15m request | B: AAPL, 5m chart, 60m request | C: EURUSD, 15m chart, 4h request | |
|---|---|---|---|
| Period transitions (the sample) | 1,876 | 480 | 321 |
| Chart bars counted | 5,628 | 5,341 | 5,136 |
| Mid-period bars (bars that do not finish a period) | 3,752 | 4,862 | 4,815 |
| Flat transitions (new period closed exactly where the old one did) | 2 | 1 | 3 |
Each run is the most recent history the tool would calculate, ending 14 Nov 2026 13:40 UTC (A), 13 Nov 2026 15:55 New York (B) and 13 Nov 2026 21:45 UTC (C). Counts are read on the last closed bar; the forming bar is excluded.
| A | B | C | |
|---|---|---|---|
| V1: bars that differ from what was knowable | 0 | 0 | 0 |
| V2: bars that differ from what was knowable | 3,748 | 4,851 | 4,770 |
| V3: bars that differ from the previous period close | 0 | 0 | 0 |
| V4: bars that differ from V3 | 3,748 | 4,857 | 4,770 |
| V4: mid-period bars equal to the close two periods back | 3,752 | 4,862 | 4,815 |
| V5: bars that differ from V3 | 0 | 1 | 0 |
V3, the pack’s request: 0 mismatches in 16,105 bars. This is also the probe’s own self-test. The reference never calls request.security() and the request never touches the reference, and they agree on every counted bar in all three runs.
V2, lookahead on with no offset: 3,748, 4,851 and 4,770 bars showed a number that was not knowable yet. I checked what the number was by waiting for each period to finish: of the 13,369 mismatches, 13,347 were confirmed as that period’s own final close, and the other 22 sit in the last, unfinished period of each run and could not be settled. The mid-period bars where V2 did not differ number 4, 11 and 45, which is exactly the mid-period bars of the 2, 1 and 3 flat periods (2 × 2, 1 × 11, 3 × 15). In a flat period the future close and the known close are the same number, so the leak is there and invisible.
V1, the naive version: 0 mismatches. On history it is clean. Its problem is on the live bar, where TradingView documents that the same call returns the period still forming, and this probe cannot see a live bar. What it can count is how often that would matter: on 13,363 of 13,429 mid-period bars the chart’s own close was a different number from the one V1 shows in history.
V4, offset inside with lookahead off: it never showed a future value, and it was late. On every one of the 13,429 mid-period bars it returned the close from two periods back, one full period behind V3, and caught up only on the bar that finishes the period. This is the answer to “lookahead off with [1] does not repaint either, it is just later”. On history it is a period late for most bars, and by TradingView’s documented behaviour the live bar does not carry that extra lag, so history and live still disagree, in the opposite direction.
V5, offset outside the call: 0, 1 and 0 mismatches. On history it is indistinguishable from the correct request. This is one of the two mistakes the pack’s guide warns about, and a history-only test passes it.
It runs on historical bars only. V1 and V5 fail on the live bar, so the probe has nothing to say about them beyond “history looks fine”, which is exactly why they survive in so many scripts. The check for those is the reload test in the one-bar repaint note: mark where the signals are, wait for a higher-timeframe bar to close, reload, compare. The Repaint Demo script shows the same thing on a live chart.
The one V5 mismatch in run B is a gap in the data, not a property of the request. On 2 Nov 2026 the feed I ran on has 73 five-minute AAPL bars instead of 78: nothing printed between the 14:20 and 14:50 bars, New York time. The missing bars include the one that finishes the hour ending 14:30. Because that bar never printed, V1 never showed that hour’s close on any chart bar, and V5, which is V1 one chart bar back, was still a period behind on the first bar after the gap. V3 was not affected.
The sample is small and recent: three symbols, about 5,000 bars each, which was the limit of the tool I ran it with, on the data my TradingView plan serves (regular session only, delayed where I have no realtime feed). A different feed can have different gaps. The comparison is exact equality on prices, with no tolerance.
Paste the script into the Pine Editor, add it to a chart on a timeframe lower than the “Higher timeframe” input, and read the totals in the Data Window on the last closed bar. Your counts will differ with the history your chart loads; the V3 zero should not. The script compiled on TradingView with 0 errors and 0 warnings on 14 Nov 2026.
//@version=6
indicator("HTF request probe", "HTF probe", overlay = false, max_bars_back = 100)
// Counts, bar by bar, what five ways of asking for a higher-timeframe close
// return on historical bars, against a reference built from the chart's own
// bars with no request.security() call in it.
//
// Run it on a chart timeframe lower than `htf`. Read the totals in the Data
// Window on the last closed bar. It measures history only: nothing here can
// see what a request returns on a live, still-forming bar.
htf = input.timeframe("15", "Higher timeframe")
// ---- Reference: the chart's own closes, no request.security() ----
// firstOfP is true on the first chart bar of each higher-timeframe period.
// lastOfP is true on the chart bar that finishes a higher-timeframe period.
firstOfP = timeframe.change(htf)
lastOfP = time_close == time_close(htf)
var float prevClose = na // close of the last finished period (P-1)
var float prev2Close = na // close of the period before that (P-2)
var int periodsSeen = 0
var int barsInP = 0 // chart bars elapsed in the current period
if firstOfP
prev2Close := prevClose
prevClose := close[1]
periodsSeen += 1
barsInP := firstOfP ? 1 : barsInP + 1
// What could be known at the close of this chart bar: the period's own close
// if this bar finishes the period, otherwise the previous period's close.
known = lastOfP ? close : prevClose
// ---- The five requests under test ----
v1 = request.security(syminfo.tickerid, htf, close) // V1: no offset, lookahead_off (the default)
v2 = request.security(syminfo.tickerid, htf, close, lookahead = barmerge.lookahead_on) // V2: no offset, lookahead_on
v3 = request.security(syminfo.tickerid, htf, close[1], lookahead = barmerge.lookahead_on) // V3: [1] inside, lookahead_on (the pack's idiom)
v4 = request.security(syminfo.tickerid, htf, close[1]) // V4: [1] inside, lookahead_off
v5 = v1[1] // V5: lookahead_off, [1] outside the call
// Counting starts on the first bar of the third period seen, so P-1 and P-2
// both exist, and it only ever runs on historical bars.
counting = barstate.ishistory and periodsSeen >= 3
// True when the period that has just ended was counted from its first bar.
var bool thisPeriodCounted = false
var bool prevPeriodCounted = false
if firstOfP
prevPeriodCounted := thisPeriodCounted
thisPeriodCounted := counting
// ---- Counters ----
var int nBars = 0 // chart bars counted
var int nTrans = 0 // period transitions inside the counted bars
var int nMid = 0 // counted bars that do not finish a period
var int nFlat = 0 // counted transitions where the new period closed exactly where the old one did
var int c1_ne_known = 0 // V1 differs from what was knowable
var int c1_mid_diff = 0 // mid-period bars where the chart's own close differs from V1
var int c2_ne_known = 0 // V2 differs from what was knowable
var int c2_future = 0 // V2 showed a period close before that period had finished
var int c2_pending = 0 // V2 mismatches in the still-unfinished last period
var int c3_ne_prev = 0 // V3 differs from the previous period's close
var int c4_ne_v3 = 0 // V4 differs from V3
var int c4_mid_prev2 = 0 // mid-period bars where V4 equals the close of two periods back
var int c5_ne_v3 = 0 // V5 differs from V3
var int t5_last = 0 // open time (seconds) of the last bar where V5 differed from V3
if firstOfP
c2_pending := 0
if counting
nBars += 1
if firstOfP
nTrans += 1
if prevClose == prev2Close
nFlat += 1
if not lastOfP
nMid += 1
if close != v1
c1_mid_diff += 1
if v4 == prev2Close
c4_mid_prev2 += 1
if v1 != known
c1_ne_known += 1
if v2 != known
c2_ne_known += 1
c2_pending += 1
if v3 != prevClose
c3_ne_prev += 1
if v4 != v3
c4_ne_v3 += 1
if v5 != v3
c5_ne_v3 += 1
t5_last := int(time / 1000)
// V2 future check, settled one period late. On the first bar of a new period,
// prevClose is the close of the period that just ended. Walk back over that
// period's bars and count the ones where V2 already showed that close while it
// differed from what was knowable on that bar.
if firstOfP and counting and prevPeriodCounted
n = barsInP[1]
for i = 1 to n
if v2[i] == prevClose and v2[i] != known[i]
c2_future += 1
plot(nBars, "bars counted", display = display.data_window)
plot(nTrans, "period transitions", display = display.data_window)
plot(nMid, "mid-period bars", display = display.data_window)
plot(nFlat, "flat transitions", display = display.data_window)
plot(c1_ne_known, "V1 != knowable", display = display.data_window)
plot(c1_mid_diff, "V1 mid-period: chart close differs", display = display.data_window)
plot(c2_ne_known, "V2 != knowable", display = display.data_window)
plot(c2_future, "V2 showed an unfinished close", display = display.data_window)
plot(c2_pending, "V2 pending in last period", display = display.data_window)
plot(c3_ne_prev, "V3 != previous period close", display = display.data_window)
plot(c4_ne_v3, "V4 != V3", display = display.data_window)
plot(c4_mid_prev2, "V4 mid-period == close two back", display = display.data_window)
plot(c5_ne_v3, "V5 != V3", display = display.data_window)
plot(t5_last, "last V5 != V3 bar time (s)", display = display.data_window)
An earlier Reddit reply of mine quoted 17,049 for a count that should have read 17,045, both taken from a first version of this probe. I no longer have that script or its output, so I cannot reproduce either figure. Everything above is re-measured from the script on this page, and the earlier figures should be treated as withdrawn.
If you want the ten checks I run before I believe any backtest, they fit on one page.
Historical simulations are not live results. Nothing on this site is investment advice.