declare lower;
input MACD_type = {default SLOW, "FAST"};
input averagetype = averageType.EXPONENTIAL;
input avglookback = 89;
def fastlength;
def slowlength;
def MACDlength;
switch (MACD_Type) {
case SLOW:
fastlength = 33;
slowlength = 100;
MACDlength = 13;
case FAST:
fastlength = 12;
slowlength = 26;
MACDlength = 9;
}
### HIGH MACD ###
def highdata = -high;
def HIGHValue = MovingAverage(averageType, HIGHdata, fastLength) - MovingAverage(averageType, HIGHdata, slowLength);
def HIGHAvg = MovingAverage(averageType, HIGHValue, MACDLength);
plot HIGHaverage = (HIGHvalue+highavg)/2;
highaverage.setdefaultcolor(createcolor(255,103,20));
### LOW MACD ###
def lowdata = low;
def LOWValue = MovingAverage(averageType, LOWdata, fastLength) - MovingAverage(averageType, LOWdata, slowLength);
def LOWAvg = MovingAverage(averageType, LOWValue, MACDLength);
plot LOWaverage = (LOWvalue+LOWavg)/2;
lowaverage.setdefaultcolor(createcolor(50,201,86));
plot zeroline = 0;
zeroline.setdefaultcolor(createcolor(212,212,212));
zeroline.setlineweight(2);
zeroline.hidetitle();
### BUY LEVELS GRID
def chartlow = lowest(lowaverage,avglookback);
def charthigh = highest(highaverage,avglookback);
plot stageonebuy = chartlow/3;
stageonebuy.setdefaultcolor(createcolor(50,201,86));
stageonebuy.hidetitle();
plot stagethreebuy = chartlow;
stagethreebuy.setdefaultcolor(createcolor(0,51,204));
stagethreebuy.hidetitle();
plot stagetwobuy = (stageonebuy+stagethreebuy)/2;
stagetwobuy.setdefaultcolor(createcolor(0,153,255));
stagetwobuy.hidetitle();
plot stage25 = (stagethreebuy + stagetwobuy)/2;
stage25.setdefaultcolor(color.yellow);
stage25.hidetitle();
### SELL LEVELS GRID
plot stageonesell = charthigh/3;
stageonesell.setdefaultcolor(createcolor(255,103,20));
stageonesell.hidetitle();
plot stagethreesell = charthigh;
stagethreesell.setdefaultcolor(createcolor(255,226,66));
stagethreesell.hidetitle();
plot stagetwosell = (stageonesell+stagethreesell)/2;
stagetwosell.setdefaultcolor(createcolor(255,153,0));
stagetwosell.hidetitle();