Volume Spike Alert

bsp2710

New member
I would like to set up an alert for a specific type of volume spike. I think this is rather basic, however I have a limited knowledge of thinkscript and would greatly appreciate any advice.

I would like the alert to trigger when any 5 minute bar after the first 6 bars has volume 80% or higher to the first 6 bars average volume. So basically you would average the volume per bar of the opening half hour; then any bar throughout the day that exceeds 80% of that average would trigger the alert. I have attached an image as an example.

I appreciate anyone taking the time to help out. Thank you


xqwRw3P.png
 
Solution
@bsp2710

ylBxKhw.png

Ruby:
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...
@bsp2710

ylBxKhw.png

Ruby:
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();
 
Last edited:
Solution
Thanks a lot! This works exactly how I wanted. The volume chart you’ve added is very helpful as well. One thing I didn't consider is the closing volume spikes sending me alerts that I wont need. Is it possible to add a line of code to stop the alert trigger an hour before market close?
Again thank you for taking the time.
 
@Svanoy

Thank you for all the insights on this thread. You're a true champion. I was hoping you could please help me:

Would you know how to build an indicator that alerts volume spikes within a certain timeframe?

So for example, for a stock, my timeframe is 5 minutes and I would like an alert if within that 5 minutes, volume is greater than 3 million. Meaning, I would not get another alert again until volume spiked over 3 million again on the 5 minute timeframe. Here is a link of a screenshot for reference. Apologies as the insert image function is not working for me.

Thank you in advance. I truly appreciate the help.
 
@Svanoy

Thank you for the response. Means a lot. I spent the past couple of days using the resources you provided and realized that the Volume Spike Alert indicator works perfectly for my goal. Where I am having trouble is creating a scan for it. So far, I have

Code:
"VolumeSpikeAlert("percentage" = .8)."vol" crosses above VolumeSpikeAlert("percentage" = .8)."Period_Avg_Vol_Plot" within 1 bars"

but that is not working. I tried "within 60 bars" and I received partial results. I chose 60 because that is how many bars there are between 10 AM and 3 PM. As always, I would be grateful for your help.
 
@trashcompactor just add a plot for volume to the Volume Spike Alert indicator and then set up your scan to reference that plot being greater than (don't use crosses above) your threshold value within 60 bars. Make sure to set the scan aggregation to 5 min.
 
Hello @Svanoy.

I need your help fixing the scan for your VolumeSpikeAlert Indicator.

I cannot get a scan for this indicator to work to save my life. I am am having trouble scanning for both the trigger and the average.
So far, this is what I have for the scan and it is not working:

VolumeSpikeAlert()."vol" is greater than or equal to VolumeSpikeAlert()."Period_Avg_Vol_Plot"

Even when I try to scan for simply "Period_Avg_Vol_Plot" being greater than or equal to a number so I can focus on the higher averages, I still get nothing.

Your expertise would be greatly appreciated as I'm sure you'd get farther in a day than I have in the entire month of December.
 
Last edited:
@bsp2710

ylBxKhw.png

Ruby:
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();

Can this be made into upper chart indicator, in which, there is a arrow for positive/green volume on the candle stick and negative/red volume on the candle stick?
Thanks
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
378 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top