# macd_double_0
#https://usethinkscript.com/threads/dual-macd-candles.15288/
#dual macd candles
def na = Double.NaN;
def bn = BarNumber();
#----------------------------
# macd - hull
input m1_averageType = AverageType.HULL;
input m1_fast_Len = 12;
input m1_slow_Len = 26;
input MACD1_Length = 9;
def m1_Value = MovingAverage(m1_averageType, close, m1_fast_Len) - MovingAverage(m1_averageType, close, m1_slow_Len);
def m1_Avg = MovingAverage(m1_averageType, m1_Value, MACD1_Length);
def m1_Diff = m1_Value - m1_Avg;
def m1_up = (m1_Diff >= 0 and m1_Diff > m1_Diff[1]);
def m1_dwn = (m1_Diff <= 0 and m1_Diff < m1_Diff[1]);
#----------------------------
# macd - exp
input m2_averageType = AverageType.EXPONENTIAL;
input m2_fast_Len = 12;
input m2_slow_Len = 26;
input MACD2_Length = 9;
def m2_Value = MovingAverage(m2_averageType, close, m2_fast_Len) - MovingAverage(m2_averageType, close, m2_slow_Len);
def m2_Avg = MovingAverage(m2_averageType, m2_Value, MACD2_Length);
def m2_Diff = m2_Value - m2_Avg;
def m2_up = (m2_Diff >= 0 and m2_Diff > m2_Diff[1]);
def m2_dwn = (m2_Diff <= 0 and m2_Diff < m2_Diff[1]);
#----------------------------
def grn = m1_up and m2_up;
def red = m1_dwn and m2_dwn;
input change_bar_color = yes;
AssignPriceColor(if change_bar_color and grn then color.green
else if change_bar_color and red then color.red
else if change_bar_color then color.gray
else color.current);
#----------------------------
input test_updwndots = no;
plot z1up = if test_updwndots and m1_up then high*1.002 else na;
z1up.SetPaintingStrategy(PaintingStrategy.points);
z1up.SetDefaultColor(Color.green);
z1up.setlineweight(2);
z1up.hidebubble();
plot z2up = if test_updwndots and m2_up then high*1.004 else na;
z2up.SetPaintingStrategy(PaintingStrategy.points);
z2up.SetDefaultColor(Color.cyan);
z2up.setlineweight(2);
z2up.hidebubble();
plot z1dwn = if test_updwndots and m1_dwn then low*0.998 else na;
z1dwn.SetPaintingStrategy(PaintingStrategy.points);
z1dwn.SetDefaultColor(Color.red);
z1dwn.setlineweight(2);
z1dwn.hidebubble();
plot z2dwn = if test_updwndots and m2_dwn then low*0.996 else na;
z2dwn.SetPaintingStrategy(PaintingStrategy.points);
z2dwn.SetDefaultColor(Color.yellow);
z2dwn.setlineweight(2);
z2dwn.hidebubble();
#