declare lower;
# ########################################################
# MACD with a more Normal Distribution by Mobius V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.
input fastLength = 8 ; # short 6, 13, 6 BB length 5
input slowLength = 17; # default 8 17 9
input MACDLength = 9;
input showBreakoutSignals = yes;
input ma_length = 21; #Length(180-200 for floating S/R , 55 for swing entry)
# Four Pole Filter
script g {
input length = 4;
input betaDev = 2;
input price = OHLC4;
def c;
def w;
def beta;
def alpha;
def G;
c = price;
w = (2 * Double.Pi / length);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
plot zeroline = 0 ;
zeroline.SetDefaultColor(Color.GRAY);
# Modified MACD
def MACD_Value = g(length = fastLength) - g(length = slowLength);
plot MACD_Avg = g(price = MACD_Value, length = MACDLength);
def Diff = MACD_Value - MACD_Avg;
AddCloud(MACD_Value, MACD_Avg, Color.GREEN, Color.RED);
def PositiveUp = MACD_Value > MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeUp = MACD_Value < MACD_Value[1] and MACD_Value > MACD_Avg ;
def NegativeDown = MACD_Value < MACD_Value[1] and MACD_Value < MACD_Avg ;
def PostiveDown = MACD_Value > MACD_Value[1] and MACD_Value < MACD_Avg ;
# ########################################################
# Charting and Formatting
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
plot Buy_scan = MACD_value < 0 and MACD_value >= MACD_value[1] and MACD_Value crosses above MACD_Avg ;
plot Sell_scan = MACD_value < MACD_avg and MACD_value < MACD_value[1] ;
Buy_scan.Hide();
Sell_scan.Hide();
plot Buy_signal = if Buy_scan and !Buy_scan[1] then MACD_value else double.NaN ;
Buy_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
Buy_signal.SetDefaultColor(color.cyan) ;
Buy_signal.SetLineWeight(5);
plot sell_signal = if sell_scan and !sell_scan[1] then MACD_value else double.NaN ;
sell_signal.SetPaintingStrategy(PaintingStrategy.LINE_Vs_poINTS);
sell_signal.SetDefaultColor(color.magenta) ;
sell_signal.SetLineWeight(5);
# ########################################################
plot MACD_dots = MACD_Value ;
MACD_dots.AssignValueColor(
if buy_scan then GlobalColor("Pre_Cyan") else
if sell_scan and !sell_scan[1] then color.magenta else
if PositiveUp then GlobalColor("LabelGreen") else
if PostiveDown then color.dark_green else
if NegativeUp then Color.DARK_gray else
if NegativeDown then Color.RED else
Color.GRAY);
MACD_dots.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
MACD_dots.SetLineWeight(1);
# ########################################################
input ShowLabels = yes ;
AddLabel(ShowLabels,
if buy_scan then "MACD Trend Begin" else
if sell_scan and !sell_scan[1] then "MACD Trend End" else
if PositiveUp then "MACD Trending " + Round(Diff, 1) else
if PostiveDown then "MACD Rising " + Round(Diff, 1) else
if NegativeUp then "MACD Watch It " + Round(Diff, 1) else
if NegativeDown then "MACD Falling " + Round(Diff, 1) else "MACD Wait ",
if buy_scan then GlobalColor("Pre_Cyan") else
if sell_scan and !sell_scan[1] then color.magenta else
if PositiveUp then GlobalColor("LabelGreen") else
if PostiveDown then color.dark_green else
if NegativeUp then Color.DARK_gray else
if NegativeDown then Color.RED else
Color.GRAY);