plot inside an if: output calls must be at the top level. Vary the value instead. A plotted na leaves a gap on
that bar, so plot na outside the window.
time(interval, session) returns na for bars outside the session string, which makes it the test for a trading window. The
session string is "HHMM-HHMM"; ranges may be joined with commas and followed by days (see Sessions and intervals).
time(interval.interval, "0930-1600", "America/New_York").
Let the chart user choose the window
input.session returns the session string the reader typed, ready for time(). bgcolor with na outside the window marks it:
Test the hour yourself
hour(time, timezone) returns the hour of a time in a zone you name, so the same script can ask the question in two zones.
syminfo.timezone is the instrument’s own zone. The bare variable hour is the hour of the bar’s own timestamp and takes no zone,
so use the function when the zone matters.
close unconditionally and let plotshape mark the bars: it takes the condition
as its first argument.