```
declare lower;
input Period_Start_Time = 0930;
input Period_End_Time = 0955;
input Percentage = .8;
input EOD = 01530;
def End_Time = SecondsFromTime(EOD) >= 0;
def Avg_Period = SecondsFromTime(Period_Start_Time) >= 0 and SecondsTillTime(Period_End_Time) >= 0;
def Period_StartBar = if SecondsTillTime(Period_Start_Time) == 0 then BarNumber() else Period_StartBar[1];
def Period_EndBar = fold i = 0 to AbsValue(BarNumber()) while (GetValue(Avg_Period, -i)) do GetValue(BarNumber(), -i);
def Period_Length = 1 + (Period_EndBar - Period_StartBar);
def Sum_Vol;
if SecondsTillTime(Period_Start_Time) == 0 {
Sum_Vol = volume;
}else if Avg_Period {
Sum_Vol = volume + Sum_Vol[1];
}else {
Sum_Vol = Sum_Vol[1];}
def Period_Avg_Vol = if Avg_Period[1] and !Avg_Period then Sum_Vol / Period_Length[1] else Period_Avg_Vol[1];
def Spike = volume > Period_Avg_Vol * Percentage and !End_Time and Period_Avg_Vol <> 0;
Alert(Spike and !Avg_Period and !End_Time, "Volume Spike", Alert.BAR, Sound.Bell);
plot vol = volume;
vol.setPaintingStrategy(Paintingstrategy.HISTOGRAM);
vol.assignValueColor(if Avg_Period then Color.Gray else if Spike then Color.Blue else Color.Current);
plot Period_Avg_Vol_Plot = if !Avg_Period then Period_Avg_Vol * Percentage else Double.NaN;
Period_Avg_Vol_Plot.HideBubble();
```