Why Pine Script indicators repaint and how barstate.isconfirmed works
When an indicator runs in TradingView, the script executes on every historical bar once (at bar close) and on every real-time price update (tick by tick). On an active, open bar, the close price constantly changes until the bar period ends. If an indicator plots a signal when close > ta.ema(close, 20), that condition might turn true midway through a 5-minute bar, draw a green buy arrow, and then turn false two minutes later if price drops before the bar closes. On historical refresh, only the final close exists, so the arrow disappears. The built-in variable barstate.isconfirmed resolves this by staying false throughout intra-bar ticks and evaluating to true exclusively on the bar closing tick.
| State variable | Intra-bar tick behavior | Bar closing tick behavior | Historical bar behavior |
|---|---|---|---|
| barstate.isconfirmed | false (suppresses premature triggers) | true (confirms permanent signal) | true (every historical bar is confirmed) |
| barstate.isrealtime | true | true | false |
| barstate.isnew | true on first tick only | false | false |
| barstate.ishistory | false | false | true |