declare lower;
declare zerobase;
input FastLength = 12;
input SlowLength = 26;
input EMATrend = 50;
input EMAFilter = no;
input EMAFilterPeriod = 200;
input Source = close;
input SignalLength = 9;
input SMASource = no;
input SMASignal = no;
input ShowLabel = yes;
def fast_ma = if SMASource then SimpleMovingAvg(Source, FastLength) else MovAvgExponential(Source, FastLength);
def slow_ma = if SMASource then SimpleMovingAvg(Source, SlowLength) else MovAvgExponential(Source, SlowLength);
def macd = fast_ma - slow_ma;
def signal = if SMASignal then SimpleMovingAvg(macd, SignalLength) else MovAvgExponential(macd, SignalLength);
def histVal = macd - signal;
def fastMA = MovAvgExponential(Source, EMATrend);
def longtermMA = MovAvgExponential(Source, EMAFilterPeriod);
def hist = if histVal > 0 and (!EMAFilter or low > longtermMA) then 0.1
else if histVal < 0 and (!EMAFilter or high < longtermMA) then 0.09
else if EMAFilter then Double.NaN else histVal;
AddLabel(ShowLabel,
if hist == 0.1 then
if (hist == 0.1) and (close > fastMA) and (open > fastMA) and (low > fastMA) then
"Grow Above"
else
"Fall Above"
else
if (hist == 0.09) and (close < fastMA) and (open < fastMA) and (high < fastMA) then
"Grow Below"
else
"FallBelow"
);
assignBackgroundColor(if hist == 0.1 then
if (hist == 0.1) and (close > fastMA) and (open > fastMA) and (low > fastMA) then
CreateColor(38, 166, 154)
else
color.lime
else
if (hist == 0.09) and (close < fastMA) and (open < fastMA) and (high < fastMA) then
CreateColor(255, 0, 0)
else
color.pink);