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:

tomsk

Well-known member
VIP
@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);
 

Asianraisin

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

MBF

Active member
2019 Donor
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);
 

Asianraisin

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

tomsk

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

MBF

Active member
2019 Donor
@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.
 

Playstation

Active member
VIP
I found this online, but couldn't figure out how to plot an up or down arrows when the crossover with volume spike. Help? Conditions to trigger alert is:

CloseAbove and VolX and strongEup = arrow up
CloseBelow and Volx and strongEdn = arrow down

These are found at the bottom of the script.

Code:
# 3 moving averages crossover signals

input SMA_short = 5;
input SMA_medium = 20;
input SMA_long = 50;

def AvgS = Average(close, SMA_short);
def AvgM = Average(close, SMA_medium);
def AvgL = Average(close, SMA_long);
def Candle_White = close > open;
def Candle_Red = close < open;

def Eup = (AvgS > AvgM and AvgM > AvgL);
def Edn = (AvgS < AvgM and AvgM < AvgL);
def CrossUp = Eup and !Eup[1] and close > AvgM;
def CrossDn = Edn and !Edn[1] and close < AvgM;

def BuySignalUp = if (Eup and Candle_White and CrossUp[0] and close > (if Candle_White[1] then close[1] else open[1])) then 1
        else
            if (Eup and Candle_White and CrossUp[1] and close[1] < (if Candle_White[2] then close[2] else open[2]) and close > (if Candle_White[2] then close[2] else open[2])) then 1
        else
            Double.NaN;

def BuySignalDn = if (Edn and Candle_Red and CrossDn[0] and close < (if Candle_Red[1] then close[1] else open[1])) then 1
        else
            if (Edn and Candle_Red and CrossDn[1] and close[1] > (if Candle_Red[2] then close[2] else open[2]) and close < (if Candle_Red[2] then close[2] else open[2])) then 1
        else
            Double.NaN;

def strongEup = Eup and close > AvgS;
def strongEdn = Edn and close < AvgS;

def Long = BuySignalup;
plot bullish = Long;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(3);

def Short = BuySignalDn;
plot Bearish = Short;
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
Bearish.SetDefaultColor(Color.CYAN);
Bearish.SetLineWeight(3);

#VOLUME SPIKE
input AverageLength = 10;
input VolumeMultiplier = 3;
input MinutesAfterOpen = 1;

def AvgVol = average(volume, AverageLength);
def VolX = (volume > AvgVol * VolumeMultiplier) and (secondsfromtime(0930) >= 60 * MinutesAfterOpen);

#Out of Bounds
def sDev = StDev(close, 21);
def MidLine = Average(close, 21);
def UpperBand = MidLine + 2 * sDev;
def LowerBand = MidLine - 2 * sDev;
def CloseAbove = if close > UpperBand then 1 else Double.NaN;
def CloseBelow = if close < LowerBand then 1 else Double.NaN;


Alert(CloseAbove and VolX and strongEup , Concat(GetSymbolPart(), " Above Upper Band." ), Alert.BAR, Sound.Bell);

Alert(CloseBelow and Volx and strongEdn , Concat(GetSymbolPart(), " Below Lower Band" ), Alert.BAR, Sound.Bell);
 
Last edited by a moderator:

ggabriel76

New member
VIP
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?
 

BenTen

Administrative
Staff member
Staff
VIP
@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);
 

BenTen

Administrative
Staff member
Staff
VIP
@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;
 

jackbarnes

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

Slippage

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

CrunchTheMarket

New member
VIP
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.
 

cabe1332

Active member
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
 

azakusa

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

azakusa

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

rad14733

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

sasank

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

Similar threads

Top