True on the first calculation of a bar: every historical bar, and the first tick of a new live bar.
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.isconfirmedtrue, and the opening tick of the next bar hasbarstate.isnewtrue. - On Sidechair: true on every historical bar, and on a live chart true on the first tick of the forming bar.
Example
//@version=6
indicator("Bar counter")
var int count = 0
if barstate.isnew
count += 1
plot(count, "Count", color.blue)See also
Runs on Sidechair