Sidechair

barstate.isnew

Browse the reference

True on the first calculation of a bar: every historical bar, and the first tick of a new live bar.

Try it in the editor

barstate.isnew is true when the script runs for a bar for the first time. On history each bar is calculated once, so it is true on all of them. On a live chart it is true on the opening tick of each new bar and false on later ticks of the same bar.

It lets live code act once per bar even though the script runs on every tick, for example to count bars or reset a flag at each open.

Type

series bool

Remarks

  • When a bar closes and the next opens, the closing tick has barstate.isconfirmed true, and the opening tick of the next bar has barstate.isnew true.
  • On Sidechair: true on every historical bar, and on a live chart true on the first tick of the forming bar.

Example

Pine ScriptCount bars once eachOpen in editor
//@version=6
indicator("Bar counter")
var int count = 0
if barstate.isnew
    count += 1
plot(count, "Count", color.blue)

See also

Runs on Sidechair