Scanning for historical volume spikes?

taldan

New member
Hi all. So I have an idea I'd like to test out, but I'm not sure how to put it together into a working thing.

I basically want to scan for volume spikes that have happened say up to 30 days ago. I want the scanner to return the list of tickers and some basic info (how many days back the volume spike was, how big was it compared to 14 prior day avg, etc).

I know you can use the UNUSUAL_VOLUME study to scan intraday or current daily vs historical, but how would you go about scanning historical vs historical?
 
Scans only return symbols. For the other data you'd need to create custom watchlist columns. If you want to find volume more than 4 times 14-day average volume in the last 30 bars you can do something like this... (Please forgive any typos. I'm just typing this in here not in TOS and I'm overdue for sleep.) Adjust the 4 however you need.

Scan
Ruby:
volume > Average(volume, 14) * 4 within 30 bars

For a column that tells you how big the last spike was you can do something like...
Ruby:
def pct = volume / Average(volume, 14);
def spike = if pct > 4 then pct else spike[1];
plot s = Round(spike * 100, 1);

For how long ago the spike was...
Ruby:
def pct = volume / Average(volume, 14);
def days = if pct > 4 then 0 else days[1] + 1;
plot d = days;

Or, if you don't care about sorting that column you could use AddLabel() instead of the two plots and combine them into a single column.
Ruby:
def pct = volume / Average(volume, 14);
def spike = if pct > 4 then pct else spike[1];
def days = if pct > 4 then 0 else days[1] + 1;
AddLabel(1, Round(spike * 100, 1)  + "% " + days + " ago" , Color.LIGHT_GRAY);

If there's multiple consecutive days 4x over the average this will get the last of them. If you want the first or the biggest you'd have to add more logic for that.
 
Scans only return symbols. For the other data you'd need to create custom watchlist columns. If you want to find volume more than 4 times 14-day average volume in the last 30 bars you can do something like this... (Please forgive any typos. I'm just typing this in here not in TOS and I'm overdue for sleep.) Adjust the 4 however you need.

Scan
Ruby:
volume > Average(volume, 14) * 4 within 30 bars

For a column that tells you how big the last spike was you can do something like...
Ruby:
def pct = volume / Average(volume, 14);
def spike = if pct > 4 then pct else spike[1];
plot s = Round(spike * 100, 1);

For how long ago the spike was...
Ruby:
def pct = volume / Average(volume, 14);
def days = if pct > 4 then 0 else days[1] + 1;
plot d = days;

Or, if you don't care about sorting that column you could use AddLabel() instead of the two plots and combine them into a single column.
Ruby:
def pct = volume / Average(volume, 14);
def spike = if pct > 4 then pct else spike[1];
def days = if pct > 4 then 0 else days[1] + 1;
AddLabel(1, Round(spike * 100, 1)  + "% " + days + " ago" , Color.LIGHT_GRAY);

If there's multiple consecutive days 4x over the average this will get the last of them. If you want the first or the biggest you'd have to add more logic for that.
Thank you, this was very helpful. Never imagined it would be that clean of a solution.

For the scan I changed the integers to input variables, but it just shows text instead of input options on the scan. Did I mess it up?

Code:
#Wizard text: Enter volume multiplier
#Wizard input: mymult
#Wizard text: Historical days to check?
#Wizard input: mydays
#Wizard text: Days of volume to average?
#Wizard input: myvolavg

input mymult = 5;
input mydays = 30;
input myvolavg = 14;

plot scan;
scan = volume > Average(volume, myvolavg) * mymult within mydays bars;
 
Thank you, this was very helpful. Never imagined it would be that clean of a solution.

For the scan I changed the integers to input variables, but it just shows text instead of input options on the scan. Did I mess it up?

Code:
#Wizard text: Enter volume multiplier
#Wizard input: mymult
#Wizard text: Historical days to check?
#Wizard input: mydays
#Wizard text: Days of volume to average?
#Wizard input: myvolavg

input mymult = 5;
input mydays = 30;
input myvolavg = 14;

plot scan;
scan = volume > Average(volume, myvolavg) * mymult within mydays bars;

No, you didn't mess up. For some reason TOS doesn't wizard-ize those in scans like we'd expect.
 

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
293 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