Would this work?
def isopen=if secondsFromTime(0930)>=0 and secondstillTime(1600)>=0 then 1 else 0;
Plot SMA = if isopen = 1 then SimpleMovingAvg(Close,500,0,no) else 0;
def isopen=if secondsFromTime(0930)>=0 and secondstillTime(1600)>=0 then 1 else 0;
Plot SMA = if isopen = 1 then SimpleMovingAvg(Close,500,0,no) else 0;