displaced stacked moving averages indicator, issues having worked already checked all other questions
here is my code for 2 indicators, I want 2 small boxes to appear in the upper left and show green box if stacked bullish and grey if not stacked and red if bearish stacked, the 2 boxes (1 will be for 3 stacked moving averages and the other 1 will be for 4 moving averages as a stricter criteria), the issue is with this code there are two black and blank boxes that pop up and they don't work as intended, not sure if the indicator is having issues with the negative displacement number to displace these moving averages into the future. i want the displacement values to be negative to make these moving averages be displaced into the future. any help is much appreciated. have tried a few different ways of putting this together and always give a black box with no words in it
def price1 = hl2;
def price2 = hl2;
def price3 = hl2;
def price4 = hl2;
def length1 = 4;
def length2 = 9;
def length3 = 17;
def length4 = 34;
def displace1 = 2;
def displace2 = 4;
def displace3 = 9;
def displace4 = 17;
def sma5 = Average(price1[-displace1], length1);
def sma10 = Average(price2[-displace2], length2);
def sma20 = Average(price3[-displace3], length3);
def sma40 = Average(price4[-displace4], length4);
def bullishcascading1 = sma10 > sma20 and sma20 > sma40;
def bullishcascading2 = sma5 > sma10 and sma10 > sma20 and sma20 > sma40;
def bearishcascading1 = sma10 < sma20 and sma20 < sma40;
def bearishcascading2 = sma5 < sma10 and sma10 < sma20 and sma20 < sma40;
AddLabel(yes, " Stacked ", if bullishcascading1 then Color.GREEN else if bearishcascading1 then Color.RED else Color.GRAY);
AddLabel(yes, " Stacked ", if bullishcascading2 then Color.GREEN else if bearishcascading2 then Color.RED else Color.GRAY);
here is my code for 2 indicators, I want 2 small boxes to appear in the upper left and show green box if stacked bullish and grey if not stacked and red if bearish stacked, the 2 boxes (1 will be for 3 stacked moving averages and the other 1 will be for 4 moving averages as a stricter criteria), the issue is with this code there are two black and blank boxes that pop up and they don't work as intended, not sure if the indicator is having issues with the negative displacement number to displace these moving averages into the future. i want the displacement values to be negative to make these moving averages be displaced into the future. any help is much appreciated. have tried a few different ways of putting this together and always give a black box with no words in it
def price1 = hl2;
def price2 = hl2;
def price3 = hl2;
def price4 = hl2;
def length1 = 4;
def length2 = 9;
def length3 = 17;
def length4 = 34;
def displace1 = 2;
def displace2 = 4;
def displace3 = 9;
def displace4 = 17;
def sma5 = Average(price1[-displace1], length1);
def sma10 = Average(price2[-displace2], length2);
def sma20 = Average(price3[-displace3], length3);
def sma40 = Average(price4[-displace4], length4);
def bullishcascading1 = sma10 > sma20 and sma20 > sma40;
def bullishcascading2 = sma5 > sma10 and sma10 > sma20 and sma20 > sma40;
def bearishcascading1 = sma10 < sma20 and sma20 < sma40;
def bearishcascading2 = sma5 < sma10 and sma10 < sma20 and sma20 < sma40;
AddLabel(yes, " Stacked ", if bullishcascading1 then Color.GREEN else if bearishcascading1 then Color.RED else Color.GRAY);
AddLabel(yes, " Stacked ", if bullishcascading2 then Color.GREEN else if bearishcascading2 then Color.RED else Color.GRAY);