Bar states. Built-in variables barstate.*
A set of built-in barstate.*
variables allows users to define a state
of the bar which calculations are being made for.
barstate.isfirst
—true
if current bar is the first in the whole range of bars available,false
otherwise.barstate.islast
—true
if current bar is the last in the whole range of bars available,false
otherwise. This flag helps to detect the last historical bar.barstate.ishistory
—true
if a current data update is a historical bar update,false
otherwise (thus it is real-time).barstate.isrealtime
—true
if current data update is a real-time bar update,false
otherwise (thus it is historical). Note that every real-time bar is also the last one.barstate.isnew
—true
if current data update is the first (opening) update of a new bar,false
otherwise.barstate.isconfirmed
—true
if current data update is the last (closing) update of the current bar,false
otherwise. The next data update will be an opening update of a new bar1.
All historical bars are new bars. That is because of the fact that the script receives them in a sequential order from the oldest to the newer ones. For bars that update in real-time a bar is considered as a new bar only at the opening tick of this bar.
Here is an example of a script with barstate.*
variables:
The script draws red and blue symbols under the first and the last bars accordingly and puts “h” on the top of the historical bars. Background of the new bars will be highlighted green, and the real-time bars will be colored black.
Footnotes
-
Variable
barstate.isconfirmed
returns the state of current chart symbol data only. It does not take into account any secondary symbol data requested with thesecurity
function. ↩