# Beep Boop
# Converted from TradingView
# v1 - 20210115 barbaros
# v2 - 20210117 barbaros - Added filter to show only in long term direction
declare lower;
declare zerobase;
input FastLength = 12; # Fast Length
input SlowLength = 26; # Slow Length
input EMATrend = 50; # EMA Trend
input EMAFilter = no; # Only show in the direction of the trend
input EMAFilterPeriod = 200; # EMA Filter Trend Period
input Source = close; # Source
input SignalLength = 9; # Signal Smoothing, minval = 1, maxval = 50
input SMASource = no; # Simple MA(Oscillator)
input SMASignal = no; # Simple MA(Signal Line)
input ShowLabel = yes; # Show indicator label
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);