True on the last bar of the chart, and on a live chart on every tick of the bar that is still forming.
barstate.islast is true only on the final bar the script runs on. On a chart with a live market that is the forming bar, so the script sees it as true on every tick until a new bar opens. On a chart with no live bar it is the last historical bar.
Use it to do work once at the end instead of on every bar: draw a label or line at the current price, fill a table, or print a summary. Drawing objects created inside if barstate.islast are recreated on every tick of the last bar, so keep them in a var variable and update them, or delete the previous one first.
Type
series bool
Remarks
- A value that depends on
barstate.islastchanges when a new bar arrives: the bar that was last stops being last, and the script does not run on it again. Do not use it to decide a trade or an alert condition that must be the same on history. - plot() cannot be called inside an if
barstate.islastblock: plot must run on every bar, so Pine rejects it in a local scope. Compute the value in the block and plot it outside. - On Sidechair: true when the bar is the last one loaded, whether or not the market is open.
barstate.isrealtimetells you whether that bar is still forming.
Example
//@version=6
indicator("Last bar label", overlay = true)
plot(close, "Close", color.gray)
if barstate.islast
label.new(bar_index, high, "Last: " + str.tostring(close, format.mintick), style = label.style_label_down)See also
Runs on Sidechair