True on the first bar of the chart, and false on every other bar. Use it to set up values once.
barstate.isfirst is true on bar_index 0, the oldest bar the script sees, and false afterwards. It stays the same when new bars arrive, because it refers to the start of the history.
Use it to initialise a variable once, to record the price the chart started at, or to create a drawing object a single time. For a variable that keeps its value across bars, var is usually shorter: var float start = close does the same.
Type
series bool
Remarks
- The first bar has no previous bar, so close[1] and every function with a lookback return na there.
- Scrolling or loading more history changes which bar is first, and the script runs again from the new first bar.
- On Sidechair: true on the first bar passed to the script, which is bar_index 0 of the loaded data.
Example
//@version=6
indicator("Since the start")
var float startPrice = na
if barstate.isfirst
startPrice := close
plot((close / startPrice - 1) * 100, "Percent since start", color.blue, 2)
hline(0)See also
Runs on Sidechair