```
# MACD_with_Signals_and_ColorBars
# Adapted from Tradingview MACD_with_Signals
# https://www.tradingview.com/script/ETBoNc7O-MACD-with-Signals/
# Based on TOS MACD with additional features
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Created by rad14733 for usethinkscript.com
# v1.0 : 2021-02-25 : Initial release
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = yes;
input colorChartBars = yes;
plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.BLUE);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.YELLOW);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
plot UpSignal = if Diff crosses above 0 then 0 else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(2);
UpSignal.SetHiding(!showBreakoutSignals);
plot DownSignal = if Diff crosses below 0 then 0 else Double.NaN;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(2);
DownSignal.SetHiding(!showBreakoutSignals);
plot Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
Value.SetDefaultColor(Color.CYAN);
Value.DefineColor("UpTrend", Color.CYAN);
Value.DefineColor("DownTrend", Color.MAGENTA);
Value.AssignValueColor(if Value > Value[1] then Value.color("UpTrend") else if Value < Value[1] then Value.color("DownTrend") else Color.CURRENT);
Value.SetLineWeight(2);
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
Avg.SetDefaultColor(Color.DARK_ORANGE);
Avg.SetLineWeight(1);
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);
ZeroLine.SetLineWeight(1);
AssignPriceColor(if colorChartBars then if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up") else Color.CURRENT);
# END - MACD_with_Signals_and_ColorBars
```