# hull_avg_cross
#https://usethinkscript.com/threads/hull-mas-crossover.16698/
#Hull MAs Crossover
def na = Double.NaN;
def bn = BarNumber();
def price = close;
input show_lines = yes;
input show_arrows = yes;
input enable_crossing_alerts = yes;
input ma1_len = 20;
#input ma1_type = AverageType.EXPONENTIAL;
input ma1_type = AverageType.HULL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);
input ma2_len = 30;
input ma2_type = AverageType.HULL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);
plot z1 = if show_lines and ma1_len > 0 then ma1 else na;
z1.SetDefaultColor(GetColor(1));
#z1.setlineweight(1);
z1.HideBubble();
plot z2 = if show_lines and ma2_len > 0 then ma2 else na;
z2.SetDefaultColor(GetColor(2));
#z2.setlineweight(1);
z2.HideBubble();
def xup = ma1 crosses above ma2;
def xdwn = ma1 crosses below ma2;
plot zup = if xup and show_arrows then low * 0.9995 else na;
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.SetDefaultColor(Color.GREEN);
zup.SetLineWeight(3);
zup.HideBubble();
plot zdwn = if xdwn and show_arrows then high * 1.0005 else na;
zdwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zdwn.SetDefaultColor(Color.RED);
zdwn.SetLineWeight(1);
zdwn.HideBubble();
# Sound.Ding, higher , up sound
# Sound.Bell, lower , down sound
alert((enable_crossing_alerts and xup), "crossed up" ,alert.BAR, sound.DING);
alert((enable_crossing_alerts and xdwn), "crossed down" ,alert.BAR, sound.bell);
#