Skip to content
Algo Trade Analytics Docs

session - Pine Script Variable

Booleans describing whether the current bar is the first or last bar of a trading session.

FieldTypeDescription
session.isfirstbarseries boolReturns true if the current bar is the first bar of the day’s session, false otherwise. If extended session information is used, only returns true on the first bar of the pre-market bars.
session.isfirstbar_regularseries boolReturns true on the first regular session bar of the day, false otherwise. The result is the same whether extended session information is used or not.
session.islastbarseries boolReturns true if the current bar is the last bar of the day’s session, false otherwise. If extended session information is used, only returns true on the last bar of the post-market bars.
session.islastbar_regularseries boolReturns true on the last regular session bar of the day, false otherwise. The result is the same whether extended session information is used or not.
session.ismarketseries boolReturns true if the current bar is a part of the regular trading hours (i.e. market hours), false otherwise.
session.ispostmarketseries boolReturns true if the current bar is a part of the post-market, false otherwise. On non-intraday charts always returns false.
session.ispremarketseries boolReturns true if the current bar is a part of the pre-market, false otherwise. On non-intraday charts always returns false.
  • Use session.isfirstbar_regular and session.islastbar_regular when you need regular-session boundaries regardless of extended hours.
  • Pair with barstate.isconfirmed if you only want to react after the bar closes.
  • session.islastbar: This variable is not guaranteed to return true once in every session because the last bar of the session might not exist if no trades occur during what should be the session’s last bar.
  • session.islastbar_regular: This variable is not guaranteed to return true once in every session because the last bar of the session might not exist if no trades occur during what should be the session’s last bar.
//@version=6
strategy("Session edges", overlay=true)
plotshape(session.isfirstbar, title="First bar",
style=shape.triangleup, location=location.belowbar,
color=color.new(color.green, 0), size=size.tiny)
plotshape(session.islastbar and barstate.isconfirmed, title="Last bar",
style=shape.triangledown, location=location.abovebar,
color=color.new(color.red, 0), size=size.tiny)