# macd_cross_yellow
#https://usethinkscript.com/threads/paint-following-two-candles-after-macd-cross.19152/
#paint following two candles after MacD Cross
# MacD produces an up signal
# the next two candles close above the open of that up signal bar, the three bars would be painted Yellow
# macd
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;
def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;
#UpSignal.SetHiding(!showBreakoutSignals);
#DownSignal.SetHiding(!showBreakoutSignals);
#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"));
#ZeroLine.SetDefaultColor(GetColor(0));
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
def up = if (!isnan(UpSignal) and close[-1] > open and close[-2] > open) or
(!isnan(UpSignal[1]) and close[0] > open[1] and close[-1] > open[1]) or
(!isnan(UpSignal[2]) and close[1] > open[2] and close[0] > open[2])
then 1 else 0;
def dwn = if (!isnan(downSignal) and close[-1] < open and close[-2] < open) or
(!isnan(downSignal[1]) and close[0] < open[1] and close[-1] < open[1]) or
(!isnan(downSignal[2]) and close[1] < open[2] and close[0] < open[2])
then 1 else 0;
AssignPriceColor(if up then color.cyan else if dwn then color.yellow else color.current);
addchartbubble(0, 0,
upsignal
, color.yellow, no);
#