```
input price = close;
input fastLength = 9;
input slowLength = 20;
input averageType = AverageType.EXPONENTIAL;
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.AssignValueColor(if FastMA > SlowMA then color.green else color.red);
SlowMA.AssignValueColor(if FastMA > SlowMA then color.green else color.red);
plot ArrowUp = if FastMA crosses above SlowMA
then low
else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(3);
ArrowUP.SetDefaultColor(Color.Green);
AssignBackgroundColor( if Fastma > slowma
then Color.BLUE
else Color.red);
plot ArrowDN = if FastMA crosses below SlowMA
then high
else double.nan;
ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
ArrowDN.SetLineWeight(3);
ArrowDN.SetDefaultColor(Color.Red);
def countUP = if !isNaN(ArrowUp)
then 1
else if FastMA > SlowMA
then countUP[1] + 1
else if !isNaN(ArrowDN)
then 0
else countUP[1];
def countDN = if !isNaN(ArrowDN)
then 1
else if FastMA < SlowMA
then countDN[1] + 1
else if !isNaN(ArrowUP)
then 0
else countDN[1];
AddLabel(1, "Count UP = " + countUP, color.white);
AddLabel(1, "Count DN = " + countDN, color.white);
def CrossBar = if FastMA crosses SlowMa
then barNumber()
else double.nan;
input length = 50;
plot Vol = volume;
plot VolAvg = Average(volume, length);
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
haclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen
then color.green
else color.red);
AssignBackgroundColor( if Fastma > slowma and HAclose < HAopen and close > close[1] then Vol.Color("Up") else if close < close[1] then Vol.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
Alert(if Fastma > slowma and HAclose < HAopen and close > close[1] then Vol.Color("Up"), " ", Alert.Bar, Sound.Bell);
```