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