• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

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.
 

tc815

New member
Hello everyone!!! Today i would like to share what has made me profitable in the stock market Smalls caps to Mid caps... I have had entire months green NOT a single red day if you follow what i will tell you...

1. Whole and half numbers are key areas like 1.50 2 2.50 $3 these are physiological areas where stocks top tick or go over just a bit and then come back down where you can then cover for the wash...

2. This is a SCALPING strategy NOT trend trading you are in and out short the pop cover the drop or buy the dip sell the rip.

3. We use whole and half numbers with a nice spike or huge up move within 1-2 BIG candles with volume low floats... into these areas NOT GRINDS we short then cover into the wash for 10-20 cents maybe more

4. I also use Time/Sales and level 2 you MUST have a fast tape/time & sales we must see speed on the time and sales with green green green prints then once it runs out of fuel you will see the tape pause and will see red/white prints coming through this is what we want to see along with big sellers on the level 2 again we short the pop cover the drop vise versa for long we want a huge drop and want to see the time/sales pause and want to see it speed up with green prints along with big buyers on the level 2 if you short at 5.50 and it goes past we will look to add the same share size at $6 that will give us a 5.75 average if i add to the trade i will look to cut it off for break even or a small loss YOU MUST have a big enough account to add or just get in small size...

5. I promise you if you follow this to the T the right way you will have a 90% + win rate because i do this has what worked for me i can not trade trends so i trade the pops and the drops quick in and out you short at 5.50 and it drops to 5.25 1000 shares that is $250 easy money trading does not have to be hard people make it hard..

6. What to do if the trade goes against you? I follow what i call the 3 minute rule if the stock does not do what i want in 3 min i cut it off...

7. Hope some of you can follow this and start becoming consistent i have tested so many strategy's and they did not work for me anddd i did not have a high win rate this is what works for me any questions please ask also i will post a really good script below to go with this strategy as confirmation

SCRIPT NO REPAINT PS: DO NOT USE WITH GRINDS ONLY POPS.

Code:
def agg=aggregationPeriod.FIVE_MIN;
def na = Double.NaN;
input ORBegin = 930;
input OREnd = 1600;
def ORActive = if SecondsTillTime(OREnd) > 0 and SecondsTillTime(ORBegin) <= 0 then 1 else 0;
def today = GetDay() == GetLastDay();
def numDevDn = -2.0;
def numDevUp = 2.0;
def timeFrame = 3 ;

def cap = getAggregationPeriod();
def errorInAggregation =
    timeFrame == 3 and cap >= AggregationPeriod.WEEK or
    timeFrame == 3 and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
#switch (timeFrame) {
#case DAY:
    periodIndx = yyyyMmDd;
#}
#def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

#if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);

def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

input filterfrom_1_20= 10;
def Sover_bought = 80;
def Sover_sold = 20;
def SKPeriod = 14;
def SDPeriod = 3;
def SpriceH = high;
def SpriceL = low;
def SpriceC = close;
def SaverageType = AverageType.SIMPLE;

def SlowK = reference StochasticFull(Sover_bought, Sover_sold, SKPeriod, SDPeriod, SpriceH, SpriceL, SpriceC, 3, if (SaverageType == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD = reference StochasticFull(Sover_bought, Sover_sold, SKPeriod, SDPeriod, SpriceH, SpriceL, SpriceC, 3, if (SaverageType == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;
def SOverBought = Sover_bought;
def SOverSold = Sover_sold;

#-----------------------------------------------------MACD--------------------------------
def MfastLength = 12;
def MslowLength = 26;
def MACDLength = 9;
def MaverageType = AverageType.EXPONENTIAL;
def MshowBreakoutSignals = no;

def Value = MovingAverage(MaverageType, close, MfastLength) - MovingAverage(MaverageType, close, MslowLength);
def Avg = MovingAverage(MaverageType, Value, MACDLength);

def Diff = Value - Avg;
def ZeroLine = 0;
def hod = if today and hod[1] == 0  then Value else if ORActive and today and Value > hod[1] then Value else hod[1];
def lod = if today and lod[1] == 0  then Value else if ORActive and today and Value < lod[1] then Value else lod[1];

def prctcalc = (filterfrom_1_20/ 100);
def separation = (hod - lod) * prctcalc;
#addlabel(yes,separation,color.green);
#addlabel(yes,prctcalc);
def conditionlong1 = SlowK crosses above SlowD and SlowK < Sover_sold and SlowD < Sover_sold;
def conditionlong2 = Value < 0 and Avg < 0 and Value - Avg > separation or Value < 0 and Avg < 0 and Value - Avg < -separation;

def conditionshort1 = SlowK crosses below SlowD and SlowK > Sover_bought and SlowD > Sover_bought;
def conditionshort2 = Value > 0 and Avg > 0 and Value - Avg > separation or Value > 0 and Avg > 0 and Value - Avg < -separation;
def confirmation = Value crosses below Avg;
plot long = if SecondsFromTime(ORBegin) > 0  and SecondsFromTime(OREnd) < 0 and conditionlong1 and conditionlong2 then low else  Double.NaN;
long.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
long.SetDefaultColor(Color.GREEN);
plot short =  if SecondsFromTime(ORBegin) > 0  and SecondsFromTime(OREnd) < 0 and  conditionshort1 and conditionshort2 then high else Double.NaN;
short.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
short.SetDefaultColor(Color.RED);
 
Last edited by a moderator:

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:

Z3VON

New member
VIP
Is there any Volume Surge Algos for TOS. Really interested to know how to use and learn more. I Have seen people using Volume Surge Algos on Tradingview.
 

Nikola

Member
I am trying to find spikes in the previous 25min.... trying to avoid the first and last 30min of trading..... is this correct?

Code:
def Active = SecondsFromTime(1000) > 0 and SecondsTillTime(1530) >= 0;
plot scan = Active and volume > 5*average(volume, 25);

i was actually trying to find stocks on the 5min with a volume bar that hit 75% higher then the 50day avg....i used the built in stuff on ToS but it was picking up a bunch of stocks, or stocks that hit this criteria just after open. so im hoping this code above will workout
 

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

Similar threads

Top