declare lower;
#---------- MACD Inputs
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
#---------- BB Inputs
input displace = 0;
input length = 20;
input num_Dev_Dn = -2.0;
input num_Dev_up = 2.0;
input bbAverageType = AverageType.Simple;
#---------- MACD Section
def value = MovingAverage(macdAverageType, close, fastLength) - MovingAverage(macdAverageType, close, slowLength);
def avg = MovingAverage(macdAverageType, value, macdLength);
#---------- BB Section
def sDev = stdev(data = avg[-displace], length = length);
plot midLine = MovingAverage(bbAverageType, data = avg[-displace], length = length);
plot lowerBand = midLine + num_Dev_Dn * sDev;
plot upperBand = midLine + num_Dev_up * sDev;