input aggregationperiod = AggregationPeriod.TWO_MIN;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
plot Value = MovingAverage(averageType, close(period = aggregationperiod), fastLength) - MovingAverage(averageType, close(period = aggregationperiod), slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
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"));
def cond1 = if Diff > 0
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
def cond2 = if Diff < 0
then Double.POSITIVE_INFINITY
else Double.NEGATIVE_INFINITY;
input showclouds = yes;
AddCloud(if showclouds
then cond1
else double.nan,
cond2,
Color.cyan, Color.magenta);