I am attempting to build an indicator that plots timeframes bias based on the 1 bar change in direction for the 10 period simple moving average in SPX, VIX, and $DXY, the latter 2 required to be in the opposite direction as SPX. The daily timeframe seems to be working fine, but some intraday timeframes are plotting colors not specified by the code at the beginning and/or ending of each day. All charts are loaded with plenty of data to plot a 10 period SMA. Does anybody have any idea as to what is going on and how I'd fix it?
Code:
# SPX_VIX_DXY_SMA
plot SMA = Average(close,10);
def VIX = Average(close("VIX"),10);
def DXY = Average(close("$DXY"),10);
SMA.assignValueColor(if SMA>SMA[1] and VIX<VIX[1] and DXY<DXY[1] then color.GREEN else if SMA<SMA[1] and VIX>VIX[1] and DXY>DXY[1] then color.RED else color.YELLOW);