Pine Script repainting: what it is and how to detect it
Repainting is why a signal that looked perfect on the chart never works live: it changed after the fact. Here are the three ways it happens and how to catch each before you risk money.
A repainting indicator shows one thing while a bar is forming and a different thing once history is fixed. Your backtest is judged on the final, repainted version — which you could never have traded.
Cause 1: acting on the unclosed bar
Logic that fires intrabar can flip as the candle moves. At the close it looks like a clean signal; live, it flickered on and off. Gate entries on barstate.isconfirmed so they only evaluate on a closed bar.
Cause 2: lookahead in higher-timeframe data
Requesting a higher timeframe with lookahead on hands past bars the final HTF value before it was known. Request it safely:
htfClose = request.security(syminfo.tickerid, "60", close[1],
lookahead=barmerge.lookahead_off)Cause 3: future-referencing / dynamic series
Some functions and security calls back-adjust historical values (e.g. unconfirmed HTF, certain drawing or label updates). If a past value can change when new data arrives, it repaints.
How to detect it
- Bar Replay. Step bar-by-bar and watch whether past signals move. If they do, it repaints.
- Compare alerts to history. Log live alerts, then check if the historical chart later shows different signals at those times.
- Reload test. Note signals, refresh the chart; if they shift, you have repainting.
Why it matters for prop trading
A repainting system passes every backtest and fails every evaluation. On a trailing-drawdown account that means real blow-ups from signals that never truly existed. See also why backtests don't match live.
Puravida Edge signals evaluate only on confirmed bars and use lookahead-off data, so what you see in history is what fires live.
FAQ
What does repainting mean in Pine Script?
An indicator or strategy repaints when its past signals change after the fact — because it read an unclosed bar, used lookahead higher-timeframe data, or referenced values that get back-adjusted. The backtest then reflects signals you could never have traded.
How do I check if my indicator repaints?
Use Bar Replay to step through candles and watch whether historical signals move, compare logged live alerts against the later historical chart, or reload the chart and see if signals shift.
How do I stop a strategy from repainting?
Gate logic on barstate.isconfirmed, request higher-timeframe data with lookahead off and a one-bar offset, and avoid functions that back-adjust historical values.
Not financial advice. Performance figures referenced are hypothetical, modeled outputs (1,500-path Monte Carlo on a 12-month sample). Past performance does not guarantee future results. Tool names are referenced for education; verify current features and prop-firm rules directly.