session - Pine Script Variable
session
Section titled “session”Overview
Section titled “Overview”Booleans describing whether the current bar is the first or last bar of a trading session.
Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
session.isfirstbar | series bool | Returns 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_regular | series bool | Returns 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.islastbar | series bool | Returns 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_regular | series bool | Returns 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.ismarket | series bool | Returns true if the current bar is a part of the regular trading hours (i.e. market hours), false otherwise. |
session.ispostmarket | series bool | Returns true if the current bar is a part of the post-market, false otherwise. On non-intraday charts always returns false. |
session.ispremarket | series bool | Returns true if the current bar is a part of the pre-market, false otherwise. On non-intraday charts always returns false. |
Remarks
Section titled “Remarks”- Use
session.isfirstbar_regularandsession.islastbar_regularwhen you need regular-session boundaries regardless of extended hours. - Pair with
barstate.isconfirmedif 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.
Example
Section titled “Example”//@version=6strategy("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)