Skip to content
Algo Trade Analytics Docs

session.isfirstbar - Pine Script Variable

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.

bool

series

//@version=6
strategy("`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 longCondition
strategy.entry("Long", strategy.long)// Close the long position at the `close` of the trading session's last bar.
if session.islastbar and barstate.isconfirmed
strategy.close("Long", immediately = true)