session.islastbar - Pine Script Variable
session.islastbar
Section titled “session.islastbar”Overview
Section titled “Overview”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.
boolQualifier
Section titled “Qualifier”series
Remarks
Section titled “Remarks”- 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.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy("`session.islastbar` Example", overlay = true)longCondition = year >= 2022// Place a long order at the `close` of the trading session's last bar.// The position will enter on the `open` of next session's first bar.if session.islastbar and longConditionstrategy.entry("Long", strategy.long) // Close 'Long' position at the close of the last bar of the trading sessionif session.islastbar and barstate.isconfirmedstrategy.close("Long", immediately = true)