ThinkorSwim Volume Spike Alert and Scanner

Asianraisin

New member
I am trying to set up a thinkscript study alert for high (8x higher than average) intraday volume. I'm trying to do this on the 1 min time frame. The goal is to catch the beginning of large moves like with what happened with $DIS today or with $TWLO and $BA earlier this week. What I've done so far is created a study alert (MarketWatch > study alerts) and put the following code in:

Code:
def afterStart = secondsfromtime(9000)>0;
def beforeEnd = secondstilltime(1430)>0;
def conditionTrue = volume > 8*average(volume, 390);
plot alert = afterStart and beforeEnd and conditionTrue;

I am trying to get alerted for volume 8x higher than average from the hours 9am cst to 2:30pm cst.(to avoid the early morning and late afternoon vol spikes). 390 representing the 390 mins in a trading day. Does this look right? I'm not sure if I'm doing this correctly. Is there any way to backtest this through OnDemand?

Thank you very much for taking time to look at my post.

Code:
#
# Pedro Uriarte 25 Aug 2019
# /CL 2500
#

declare lower;
declare zerobase;

input lengthAvg = 50;
input volumeAlert1 = 2500;
input volumeAlert2 = 3500;
input aggregationPeriod = AggregationPeriod.MIN;
input soundType = Sound.RING;
input alertType =  Alert.BAR;
Plot dinamicAlertLine = ((GetAggregationPeriod()/60000) - 1) * volumeAlert1;

plot Vol = volume;
plot VolAvg = Average(volume, lengthAvg);
Plot AlertLine1 = volumeAlert1;
Plot AlertLine2 = volumeAlert2;

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));
AlertLine1.SetDefaultColor(GetColor(5));
AlertLine2.SetDefaultColor(GetColor(5));
dinamicAlertLine.SetDefaultColor(GetColor(5));

# def afterStart = SecondsFromTime(0800) > 0;
# def beforeEnd = SecondsTillTime(1530) > 0;
def alertCondition = GetAggregationPeriod() == aggregationPeriod and (volume >= volumeAlert1 or (volumeAlert2!= 0 and volume >= volumeAlert2));

Alert(alertCondition, "High volume Alert", alertType, soundType);
 
Last edited by a moderator:

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

@Asianraisin You are close, please note that you probably meant "0900" rather than "9000" in your start time. I have use a bracketed time, note that times are interpreted by TOS in EST so you may wish to adjust that accordingly.

Here then is your scan.

Code:
def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
plot scan = Active and volume > 8*average(volume, 390);
 
Thank you very much for your reply. I'm going to test it out today.

edit: just tried it out and after creating the alert, it immediately triggers and the alert is now registered as "triggered" instead of "active". Do you have any suggestions for how to fix it so that it operates properly? do i need to specify the aggregation period as 1 minute?
 
Last edited:
Try this @Asianraisin
  1. go to scan,
  2. select add filter,
  3. go to study,
  4. go to the tiny pencil on the right, hit delete,
  5. go to thinkscript editor on the top left,
  6. copy and paste the code above into it,
  7. change the aggregation to 1 minute at the very top left, hit okay,
  8. and scan,
nothing will come up right now because market closed but you can now save this as a scan by ... clicking the little notebook next to "no matching symbols" click alert when scan results change, name your scan and you should be able to find it under your watchlist. In the morning things should pop up if it's working correctly. You can maybe find out early before the open if it is working by turning on the EXT next to the aggregation you've chosen.

11:45 Paris: Since there is considerable interest in volume studies in recent days, here's a volume spike alert that was posted some time back.

Code:
# Volume Spike Alert
# Student
# 12.17.2016

# Fires off an alert on a 6-10X volume spike, so you can catch a rocket early

def AvgVol = Average(volume, 6);
def VolX = (volume > AvgVol[1] * 6) and (volume < AvgVol[1] * 10) and (SecondsFromTime(0930) >= 1800) and (SecondsTillTime(1600) > 900);
def VolXX = (volume > AvgVol[1] * 10) and (SecondsFromTime(0930) >= 1800) and (SecondsTillTime(1600) > 900);
def VolUP = volume > AvgVol;

Alert(VolX, GetSymbolPart() + " has a large volume spike." + volume, Alert.BAR, Sound.Bell);
Alert(VolXX, GetSymbolPart() + " has a very large volume spike." + volume, Alert.BAR, Sound.Bell);
 
Last edited by a moderator:
Awesome, I appreciate you walking me through this. would you suggest I add this as a scanner rather than as a study alert? I suppose one major advantage to adding as a scanner as opposed to a study alert is you don't have to create an alert for each individual ticker.
 
Last edited:
@Asianraisin Use a dynamic Watchlist wand you'll get SMS, emails and audible alerts if you select them all. From the scanner - use the function "Alert when scan results change"

Contact TOS support for a walkthrough of this feature if you're not familiar.
 
@Asianraisin I usually only use alerts when price crosses support or resistance. This is better as a scan but I would use it only on your favorite stocks, until you get used to it, TOS I mean. For instance if I were to use this scan I would have a CORE list that I have scanners for in the morning and at night so at the top of the scan you will see "Scan in" I put in my Core list and then leave the intersect with blank. It will only scan those and pop those up as they follow your scan inputs.
 
Can someone help me find a volume indicator on the price bar that would indicate a spike in volume (spike in volume can be 50% over normal volume or volume over a period of time) indication could be a dot on the price bar to show the bar with spike in volume. Do we have something like this?
 
@ggabriel76 The code below will highlight any candlestick with volume above its 50 simple moving average.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

declare lower;
declare zerobase;

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));

AssignPriceColor(if volume > VolAvg then color.white else color.current);
 
@ggabriel76 What do you mean by "adjustable"? Changing the value of the simple moving average? If so, you can change that within the code.

Code:
input length = 50;
 
Hey guys, I'm trying to create an indicator that changes the color of the plotline of the volume of the stock is above the daily volume average by 10%. I can't figure out how to do this.

Thank You!
 
Hey guys, I'm trying to create an indicator that changes the color of the plotline of the volume of the stock is above the daily volume average by 10%. I can't figure out how to do this.
The simplest way would be to steal the code from the built in VolumeAvg study and modify the line that has Vol.AssignValueColor to have different color when it's 10% above average.
 
Trying to find the swings like SLDB for 2/23/21. Up $2 from 7-9 at 3:30pm. Volume runs from 50k all day to 200k to 1M to 400K and 500K. Puts a LOT of Pricing Pressure on a stock that is $7. Looking at the 1min Scan and using study that has "volume > Average(volume, 180) * 8".
So that means current 1 minute candle is greater than the Average (of the last 180 1 minute candles) * 8.
So if the Average of the past 180 candles equates to 50k that would be current volume is > 400,000.
But that doesn't seem to work as it doesn't show SLDB in the scan.
I did run this after hours just now and did not have EXT checked.
Does that formula work for any time frame?
If it's on a 1 Minute is that 180 minutes for the Average?
If it's 5 Minute is that 180 5 minute bars it's looking at?
Inquiring Minds want to know.
 
Trying to find the swings like SLDB for 2/23/21. Up $2 from 7-9 at 3:30pm. Volume runs from 50k all day to 200k to 1M to 400K and 500K. Puts a LOT of Pricing Pressure on a stock that is $7. Looking at the 1min Scan and using study that has "volume > Average(volume, 180) * 8".
So that means current 1 minute candle is greater than the Average (of the last 180 1 minute candles) * 8.
So if the Average of the past 180 candles equates to 50k that would be current volume is > 400,000.
But that doesn't seem to work as it doesn't show SLDB in the scan.
I did run this after hours just now and did not have EXT checked.
Does that formula work for any time frame?
If it's on a 1 Minute is that 180 minutes for the Average?
If it's 5 Minute is that 180 5 minute bars it's looking at?
Inquiring Minds want to know.

Hey @CrunchTheMarket, I am not sure precisely what your trying to do, but I can share my AH Volume scanner code and screenshot what it looks like. You will see that SLDB is included.

Code filter you c AH Volume below. Use 1 min. Then you can add the other filters as they look on the screenshot. Make sure you use 1 hour on the study "Price_Change" and don't forget to check on EXT. You will get a list for sure from your scanner. Good luck!

# AH Volume code
# cabe1332
def PostMkt = SecondsFromTime(1600) >= 0 and SecondsTillTime(2000) >= 0;
def PostVolMins = if PostMkt and !PostMkt[1] then volume
else if PostMkt then PostVolMins[1] + volume
else PostVolMins[1];
plot data = PostVolMins >250000;

RY23mXv.png
 
Try this @Asianraisin go to scan, select add filter, go to study, go to the tiny pencil on the right, hit delete, go to thinkscript editor on the top left, copy and paste the code above into it, change the aggregation to 1 minute at the very top left, hit okay, and scan, nothing will come up right now because market closed but you can now save this as a scan by ... clicking the little notebook next to "no matching symbols" click alert when scan results change, name your scan and you should be able to find it under your watchlist. In the morning things should pop up if it's working correctly. You can maybe find out early before the open if it is working by turning on the EXT next to the aggregation you've chosen.

11:45 Paris: Since there is considerable interest in volume studies in recent days, here's a volume spike alert that was posted some time back.

Code:
# Volume Spike Alert
# Student
# 12.17.2016

# Fires off an alert on a 6-10X volume spike, so you can catch a rocket early

def AvgVol = Average(volume, 6);
def VolX = (volume > AvgVol[1] * 6) and (volume < AvgVol[1] * 10) and (SecondsFromTime(0930) >= 1800) and (SecondsTillTime(1600) > 900);
def VolXX = (volume > AvgVol[1] * 10) and (SecondsFromTime(0930) >= 1800) and (SecondsTillTime(1600) > 900);
def VolUP = volume > AvgVol;

Alert(VolX, GetSymbolPart() + " has a large volume spike." + volume, Alert.BAR, Sound.Bell);
Alert(VolXX, GetSymbolPart() + " has a very large volume spike." + volume, Alert.BAR, Sound.Bell);
Hello everybody.

Just an FYI.

This didnt work for me. Get "Exactly one plot expected" error.
Here is a screenshot for reference.

spike-error.png
 
@rad14733

Many thanks.

Here it is. Just a piece of code that was posted at the top of this thread.

Code:
# Volume Spike Alert
# Student
# 12.17.2016

# Fires off an alert on a 6-10X volume spike, so you can catch a rocket early

def AvgVol = Average(volume, 6);
def VolX = (volume > AvgVol[1] * 6) and (volume < AvgVol[1] * 10) and (SecondsFromTime(0930) >= 1800) and (SecondsTillTime(1600) > 900);
def VolXX = (volume > AvgVol[1] * 10) and (SecondsFromTime(0930) >= 1800) and (SecondsTillTime(1600) > 900);
def VolUP = volume > AvgVol;

Alert(VolX, GetSymbolPart() + " has a large volume spike." + volume, Alert.BAR, Sound.Bell);
Alert(VolXX, GetSymbolPart() + " has a very large volume spike." + volume, Alert.BAR, Sound.Bell);
 
@azakusa What a hodgepodge of a topic... I can see what you are confused... The code you posted is not scanner code end the text that corresponds with it is not what should be there... After reviewing the entire topic, the only posts in this topic that address scans are the top portion of Post #1, which is incorrect, Post #2, Post #15, and Post #34...
 
Is there a way to run a scanner to list stocks from my watchlist whose current volume bar is greater than last 2 volume bars. I'd like to run this scanner at 10:45am est.Which means the 10:30 to 10:45 volume bar should be greater than the volume bars from 10 to 10:15 and 10:15 to 10:30 (I'd like to ignore the 1st 2 volume bars from 9:30 to 10).would like to use 15 mins timeframe to run the scan.

When ever i run the scan im only expecting to see results only if current volume bar is greater than no of periods we select. if not there shouldn't be a any results

i have tried unusual volume scan where current volume bar increased by % than 6 periods with time frame as 15 mins.

Thank You
 
Last edited:
Is there a way to run a scanner to list stocks from my watchlist whose current volume bar is greater than last 2 volume bars. I'd like to run this scanner at 10:45am est.Which means the 10:30 to 10:45 volume bar should be greater than the volume bars from 10 to 10:15 and 10:15 to 10:30 (I'd like to ignore the 1st 2 volume bars from 9:30 to 10).would like to use 15 mins timeframe to run the scan.

When ever i run the scan im only expecting to see results only if current volume bar is greater than no of periods we select. if not there shouldn't be a any results

i have tried unusual volume scan where current volume bar increased by % than 6 periods with time frame as 15 mins.

Thank You


volume bar is greater than last 2 volume bars
Code:
plot greaterthanprev2 = volume > volume[1] and volume[2];

the rest is up to you
you stated:
"I'd like to run this scanner at 10:45am"
that is up to you to run the scan at this time
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
414 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