Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: barstate · Entries: 8
barstate (library)
Definition
Seven boolean series that tell your script which kind of bar it is being evaluated on: the first, a new one, a historical one, the last, the last confirmed historical one, one that is still updating, and one that is confirmed.
No functions live here — the namespace is variables only.
Example
barstate.isconfirmed (variable)
Definition
Returns true if the current bar is confirmed (closed). On historical bars this is true, except on the last historical bar while the market is open, where it is false because that bar is still forming. On the real-time bar this is false until the bar closes.
Type
series bool
Example
barstate.isfirst (variable)
Definition
Your script is being evaluated on the first bar of the chart. On every bar after that one, this reads false.
A script is evaluated once per bar, in order, so this holds on the earliest run only.
Type
series bool
Example
barstate.ishistory (variable)
Definition
Tells your script whether the bar it is being evaluated on is a historical bar. On a bar that is not historical it reads false.
The value is a series, so the answer it gives changes as the script moves from bar to bar.
Type
series bool
Example
barstate.islast (variable)
Definition
The bar your script is on is the last bar of the chart. On every bar before it, this reads false.
It marks a single position in the series rather than a range of bars.
Type
series bool
Example
barstate.islastconfirmedhistory (variable)
Definition
This marks the last confirmed historical bar of the chart, when the market is closed. Every other bar reads false.
While the market is open the flag is false on every loaded bar, because the last loaded bar is still forming and is not confirmed. It is a separate flag from barstate.islast, which marks the last bar.
Type
series bool
Example
barstate.isnew (variable)
Definition
The bar being evaluated is a new bar. Where it is not, your script reads false.
Read it in a condition, as you would any series value: the answer it gives changes from bar to bar.
Type
series bool
Example
barstate.isrealtime (variable)
Definition
The bar under evaluation is a live bar: this is true on every run of that bar, including the run when the bar closes, and false on historical bars.
It is not the opposite of barstate.isconfirmed: on the run when the bar closes both are true. To test that a bar has closed, use barstate.isconfirmed. If a result must not move once it is drawn, base it on a bar that has closed.
Type
series bool
Example