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?
 

Slippage

Well-known member
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.
 

taldan

New member
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;
 

Slippage

Well-known member
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.
 

Similar threads

Top