declare lower;
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(CreateColor(64, 64, 64));
ZeroLine.HideTitle();
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff *2;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.DefineColor("Positive and Up", CreateColor(64, 234, 255));
Diff.DefineColor("Positive and Down", CreateColor(0, 167, 0));
Diff.DefineColor("Negative and Down", CreateColor (167,0,0));
Diff.DefineColor("Negative and Up", CreateColor (255,64,134));
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"));
input price = close;
# --- A Wave (Wave1): average of short-term MACDs using Fib EMAs ---
def macd1 = ExpAverage(price, 8) - ExpAverage(price, 34);
def macd2 = ExpAverage(price, 8) - ExpAverage(price, 55);
def macd3 = ExpAverage(price, 8) - ExpAverage(price, 89);
def macd4 = ExpAverage(price, 8) - ExpAverage(price, 144);
def macd5 = ExpAverage(price, 8) - ExpAverage(price, 233);
plot Wave1 = (macd1 + macd2 + macd3 + macd4 + macd5) / 5;
Wave1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Wave1.SetLineWeight(3);
Wave1.AssignValueColor(
if Wave1 > 0 then Color.dark_orange
else if Wave1 < 0 then Color.RED
else Color.GRAY
);
# --- C Wave (Wave2High / Wave2Low): envelope of longer-term MACDs ---
def macd6 = ExpAverage(price, 13) - ExpAverage(price, 34);
def macd7 = ExpAverage(price, 13) - ExpAverage(price, 55);
def macd8 = ExpAverage(price, 13) - ExpAverage(price, 89);
def macd9 = ExpAverage(price, 13) - ExpAverage(price, 144);
def macd10 = ExpAverage(price, 13) - ExpAverage(price, 233);
plot Wave2High = Max(Max(Max(Max(macd6, macd7), macd8), macd9), macd10);
plot Wave2Low = Min(Min(Min(Min(macd6, macd7), macd8), macd9), macd10);
Wave2High.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Wave2Low.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Wave2High.SetLineWeight(2);
Wave2Low.SetLineWeight(2);
Wave2High.AssignValueColor(Color.BLUE);
Wave2Low.AssignValueColor(Color.BLUE);