Can someone tell me what I am doing wrong with this simple Column Scan? I only get green 2s in the column.
Code:
#
# 3SMA Column Scan ---------- only gives green 2s
#
def Length1 = 8;
def Length2 = 21;
def Length3 = 55;
def averageType = AverageType.SIMPLE;
def aggPeriod = AggregationPeriod.Fifteen_Min;
#have to match the above time frame or will get Secondary Time Frame Error Message
def fastAvg;
if !IsNaN(close(period=AggPeriod)[-1]) {fastAvg = Double.Nan;}
else { fastAvg = MovingAverage(averageType, aggPeriod, Length1);}
def medAvg;
if !IsNaN(close(period=AggPeriod)[-1]) {medAvg = Double.Nan;}
else { medAvg = MovingAverage(averageType, aggPeriod, Length2);}
def slowAvg;
if !IsNaN(close(period=AggPeriod)[-1]) {slowAvg = Double.Nan;}
else { slowAvg = MovingAverage(averageType, aggPeriod, Length3);}
def UpStack3 = fastAvg >= medAvg and medAvg >= slowAvg;
def DownStack3 = fastAvg < medAvg and medAvg < slowAvg;
plot _3SMA = if UpStack3 then 2 else if DownStack3 then 1 else 0;
_3SMA.AssignValueColor(if UpStack3 then color.green else if DownStack3 then color.light_red else color.white);
#End Code