Repaint Demo: Higher-Timeframe EMA, Both Ways

One daily EMA, requested two ways, plotted together on an intraday chart.
Red is the default request: lookahead off, no offset. On historical bars request.security() returns only confirmed values, so red steps to each day's EMA on that day's last bar. On realtime bars it returns the unconfirmed value, so red moves with every tick while the day is open. Reload the chart and those live values are replaced by confirmed ones. That difference between history and realtime is what TradingView's Pine docs call repainting, and this is the widespread, often acceptable kind, provided you know it is there.
Blue is the non-repainting idiom from the same docs: the expression offset by [1] inside the call, with lookahead on. It returns the last confirmed daily value and behaves the same on historical and realtime bars. The docs say the [1] and lookahead_on are interdependent: neither can be removed without compromising the function.
How to see it: add it to a 15-minute chart of a market that is trading, leave it running for a few hours, then compare the live stretch with the history. On history the two lines agree on every bar except each day's last. On the live stretch, red drifts away from blue. Then reload: blue does not move, and red's live path is gone.
What the honest version costs: blue can be up to one full higher-timeframe bar old. On a 15-minute chart that is up to 96 bars in a 24-hour market and 26 in a 6.5-hour US session. Two values in the Data Window show it: the red-minus-blue spread, and the chart bars since the daily bar opened.
A backtest run on red sees only the history version, so it cannot show you the live behaviour. That is the check: for every value an entry depends on, ask whether it could still have changed when you would have acted.
Open source. Platform mechanics, not a result of mine. Nothing here is investment advice.
Red is the default request: lookahead off, no offset. On historical bars request.security() returns only confirmed values, so red steps to each day's EMA on that day's last bar. On realtime bars it returns the unconfirmed value, so red moves with every tick while the day is open. Reload the chart and those live values are replaced by confirmed ones. That difference between history and realtime is what TradingView's Pine docs call repainting, and this is the widespread, often acceptable kind, provided you know it is there.
Blue is the non-repainting idiom from the same docs: the expression offset by [1] inside the call, with lookahead on. It returns the last confirmed daily value and behaves the same on historical and realtime bars. The docs say the [1] and lookahead_on are interdependent: neither can be removed without compromising the function.
How to see it: add it to a 15-minute chart of a market that is trading, leave it running for a few hours, then compare the live stretch with the history. On history the two lines agree on every bar except each day's last. On the live stretch, red drifts away from blue. Then reload: blue does not move, and red's live path is gone.
What the honest version costs: blue can be up to one full higher-timeframe bar old. On a 15-minute chart that is up to 96 bars in a 24-hour market and 26 in a 6.5-hour US session. Two values in the Data Window show it: the red-minus-blue spread, and the chart bars since the daily bar opened.
A backtest run on red sees only the history version, so it cannot show you the live behaviour. That is the check: for every value an entry depends on, ask whether it could still have changed when you would have acted.
Open source. Platform mechanics, not a result of mine. Nothing here is investment advice.
Ten checks before you believe a backtest — the free one-page checklist: quanticator.app/tv · No-repaint HTF Template Pack (Pine v6, $39): jordonharrell.gumroad.com/l/norepaint-htf-template-pack
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Ten checks before you believe a backtest — the free one-page checklist: quanticator.app/tv · No-repaint HTF Template Pack (Pine v6, $39): jordonharrell.gumroad.com/l/norepaint-htf-template-pack
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.