TradingView - Close position at end of day

Here’s a quick script that shows how to close a position at the end of the day.

//@version=3
strategy(title="Close at EOD Example", shorttitle="EOD", max_bars_back=100)
t = time(period, "0930-1550") 

session_open = na(t) ? false : true

if session_open
    strategy.entry(id="session open", long=true, when=session_open)
else
    strategy.close(id="session open")