#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def value = MACD(fastLength, slowLength, MACDLength, averageType);
def avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
input signal = yes;
plot upsignal = if !signal then Double.NaN else value > 0 and Diff > 0 and value crosses avg;
upsignal.DefineColor("Negative to Positive", Color.GREEN);
upsignal.AssignValueColor(upsignal.Color("Negative to Positive"));
upsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upsignal.SetLineWeight(3);
plot dnsignal = if !signal then Double.NaN else value < 0 and Diff < 0 and value crosses avg;
dnsignal.DefineColor("Positive to Negative", Color.RED);
dnsignal.AssignValueColor(dnsignal.Color("Positive to Negative"));
dnsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnsignal.SetLineWeight(3);
input label = yes;
AddLabel(label, if upsignal then "(Cross and Histogram) > 0" else "(Cross and Histgram) < 0", if upsignal then Color.GREEN else Color.RED);
input bubbles = yes;
input bubbleoffset = 3;
addchartBubble(bubbles and (upsignal or dnsignal), if upsignal then low - ticksize() * bubbleoffset else high + ticksize() * bubbleoffset, if upsignal then "Up" else "Dn", if upsignal then color.green else color.red, if upsignal then no else yes);
input verticalline = yes;
AddVerticalLine(verticalline and upsignal, "", Color.GREEN, stroke = Curve.LONG_DASH);
AddVerticalLine(verticalline and dnsignal, "", Color.RED, stroke = Curve.LONG_DASH);
input alert = yes;
Alert(alert, if upsignal then "(Cross and Histogram) > 0" else "(Cross and Histgram) < 0", Alert.BAR, Sound.Chimes);