# Hull MA Trend Indicator - Arrows Alerts & Paint
# TD Ameritrade IP Company, Inc. (c) 2008-2017
# colors and arrows and labels by EBTrader 02.22.15
# modified by tiny bull 2.7.20
# version 1.3
input price = close;
input length = 20;
input displace = 0;
def HMA = MovingAverage(AverageType.HULL, price, length)[-displace];
def hmaAscending = HMA > HMA[1] and HMA[1] > HMA[2];
def hmaDescending = HMA < HMA[1] and HMA[1] < HMA[2];
#==============start painted candles...need to finish input (I'm lost there)...
#told to add paint candles variable to your assignpricecolor
#need to make hma dual colored up/down, currently just one color
input usehma = yes;
plot HullMA = if usehma then hma else double.NaN;
plot candlesHMA = MovingAverage(AverageType.HULL, price, length)[-displace];
input paint_candles = yes;
candlesHMA.DefineColor("Up", color.green);
candlesHMA.DefineColor("Down", color.red);
candlesHMA.AssignValueColor(if hmaascending then candlesHMA.color("Up") else candlesHMA.color("Down"));
AssignPriceColor(if hmaascending then candlesHMA.color("Up") else candlesHMA.color("Down"));
#===================start arrows and labels
input crossingType = {default any, above, below};
def signal = CompoundValue(1, if hmaascending then 1 else if hmadescending then -1 else signal[1], 0);
input showarrows = yes;
plot U1 = showarrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.green);
U1.SetLineWeight(3);
plot D1 = showarrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.red);
D1.SetLineWeight(3);
input usealerts = no;
Alert(usealerts and U1, "UP", Alert.BAR, Sound.Bell);
Alert(usealerts and D1, "DOWN", Alert.BAR, Sound.Chimes);
def uptrend = hmaascending;
def downtrend = hmadescending;
#label stopped working, need to fix
addlabel(uptrend, "Uptrend", color.green);
addlabel(downtrend, "Downtrend", color.red);