Sidechair

barstate.ishistory

Browse the reference

True on every bar that closed before the script loaded, and false on bars that arrive live.

Try it in the editor

barstate.ishistory is true on historical bars and false on realtime bars. It is the opposite of barstate.isrealtime, so exactly one of the two is true on any bar.

Use it to skip work that only makes sense on live data, or to keep a history-only calculation, such as a backtest summary, from running on every live tick.

Type

series bool

Remarks

  • A bar that was live when the chart loaded becomes history once it closes and the chart reloads.
  • On Sidechair: true on every bar unless the last bar is a live forming bar, where it is false.

Example

Pine ScriptHistory-only backgroundOpen in editor
//@version=6
indicator("History bars", overlay = true)
plot(close, "Close", color.gray)
bgcolor(barstate.ishistory ? color.new(color.blue, 92) : na)

See also

Runs on Sidechair