Sidechair

barstate.isconfirmed

Browse the reference

True when the script is running on the final calculation of a bar, so the bar's values will not change again.

Try it in the editor

On every historical bar barstate.isconfirmed is true, because the bar is already closed. On a live chart it is false while the bar is forming, on every tick, and true on the last calculation, when the bar closes.

Check it before acting on a value that must not change: a signal you will alert on, an order condition, a label you do not want to flicker. Without it, a close above a level on one tick can reverse before the bar finishes, and the signal vanishes after it fired.

Type

series bool

Remarks

  • Requiring barstate.isconfirmed delays a signal until the bar closes, which is what history already assumes. It removes repainting from the signal at the cost of acting one bar later than a mid-bar trigger.
  • State such as var counters that you want to update once per bar should be updated inside an if barstate.isconfirmed block.
  • On Sidechair: true on every historical bar, and false only on a forming live bar. A chart with no live market shows true on every bar.

Example

Pine ScriptSignal only on a closed barOpen in editor
//@version=6
indicator("Confirmed crossover", overlay = true)
avg = ta.sma(close, 20)
cross = ta.crossover(close, avg) and barstate.isconfirmed
plot(avg, "SMA 20", color.gray)
plotshape(cross, "Cross", shape.triangleup, location.belowbar, color.green, size = size.small)

See also

Runs on Sidechair