declare upper;
# @Darquer, 2023-12-09
# Requested Indicator to plot arrows and alert when price closes above or below
# the 9EMA - UseThinkScript.com
#
input length = 9;
input arrowWeight=3;
input alerts = yes;
# Custom Colors - @Darquer
DefineGlobalColor("SteelBlue", CreateColor(14, 58, 99));
DefineGlobalColor("Mustard", CreateColor(157, 157, 37));
DefineGlobalColor("Mauve", CreateColor(107, 33, 112));
def EMA = MovingAverage(AverageType.EXPONENTIAL, close, length);
def upSignal = close > EMA && close[1] <= EMA;
def downSignal = close < EMA && close[1] >= EMA;
def upLoc = low;
def downLoc = high;
plot trendline = EMA;
trendline.SetDefaultColor(GlobalColor("Mustard"));
plot upSignalArrow = if upSignal then uploc else double.nan;
Alert(upsignalArrow, Sound.Ding);
upSignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upsignalArrow.SetDefaultColor(GlobalColor("SteelBlue"));
upsignalArrow.SetLineWeight(arrowWeight);
upsignalArrow.HideTitle();
plot downSignalArrow = if downSignal then downLoc else double.nan;
Alert(downSignalArrow, Sound.Ding);
downSignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downsignalArrow.SetDefaultColor(GlobalColor("Mauve"));
upsignalArrow.SetLineWeight(arrowWeight);
upsignalArrow.HideTitle();