• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

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:

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

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

rad14733

Well-known member
VIP
Apologies for this basic question but how can I see the script for existing studies like VolumeAvg study you mention above, thanks.

We cannot view the source for most licensed Thinkscripts... However, the VolumeAvg Study shows all of the code... You can view it by clicking on the script icon to the left of the Study name or Right-Click on the name and selecting View...
 

cabe1332

Member
@tc815, I have questions about your strategy, will you message me so we can discuss?

I would like to share what I have and working well for me. Since I cannot post images directly, I'll just include and post the code below. Good luck!

Code:
# cabe1332 20210115_1700
# I have made some modifications customize to my needs and requirements.
# Credit to team TOSindicators [URL]https://tosindicators.com/indicators[/URL]
# Market Pulse, a powerful tool that lets you identify which one of the four market stages ( accumulation, distribution, acceleration) we are currently in. 
# It uses Moving Average along with Volume Weighted Moving Averages to try and identify which one of the four market stages.
# I've added Stage Label, indicator bubbles on a plotline that indicates buying increase/decrease (V+/V- bubble) with the price on which candle. 

# start of code

input price = close;
input length = 9;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);

plot VMA = asd;
VMA.setDefaultColor(GetColor(0));

def vma8 = sum(volume * close,8) / sum(volume,8);
def vma21 = sum(volume * close,21) / sum(volume,21);
def vma34 = sum(volume * close,34) / sum(volume,34);

def bullish = if vma8 > vma21 and vma21 > vma34 then 1 else 0;
def bearish = if vma8 < vma21 and vma21 < vma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;

AddLabel(yes, if bullish then "Stage: Accelerating " else if bearish then "Stage: Decelerating " else if close >= VMA then "Stage: Accumulation " else "Stage: Distribution ", if bullish then color.green else if bearish then color.red else if close >= VMA then color.yellow else color.orange);

VMA.assignValueColor(if bearish and close<= VMA then color.red else if bullish and close >= VMA then color.green else color.gray);

def accumulationtoaccelation = if (bullish and close>=VMA) then 1 else 0;
def distributiontoacceleration = if (bearish and close <= VMA) then 1 else 0;

AddChartBubble(accumulationtoaccelation and !accumulationtoaccelation[1] and close <= close[1], close, "V+ " + round(close,2), color.light_green);
AddChartBubble(distributiontoacceleration and !distributiontoacceleration[1] and close <= close[1], close, "V- " + round(close,2), color.light_orange);

def accelationtoaccumulation = if (bullish and close<=VMA) then 1 else 0;
AddChartBubble(accelationtoaccumulation and !accelationtoaccumulation[1], close, "Accum", color.light_gray);

def distributiontoaccumulationton = if (bearish and close>=VMA) then 1 else 0;
AddChartBubble(distributiontoaccumulationton and !distributiontoaccumulationton[1], close, "Dist", color.light_gray);

# end of code
 

cabe1332

Member
I would like to share what I have and working well for me. Since I cannot post images directly, I'll just include and post the code below. Good luck!

Code:
# cabe1332 20210115_1700
# I have made some modifications customize to my needs and requirements.
# Credit to team TOSindicators [URL]https://tosindicators.com/indicators[/URL]
# Market Pulse, a powerful tool that lets you identify which one of the four market stages ( accumulation, distribution, acceleration) we are currently in.
# It uses Moving Average along with Volume Weighted Moving Averages to try and identify which one of the four market stages.
# I've added Stage Label, indicator bubbles on a plotline that indicates buying increase/decrease (V+/V- bubble) with the price on which candle.

# start of code

input price = close;
input length = 9;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);

plot VMA = asd;
VMA.setDefaultColor(GetColor(0));

def vma8 = sum(volume * close,8) / sum(volume,8);
def vma21 = sum(volume * close,21) / sum(volume,21);
def vma34 = sum(volume * close,34) / sum(volume,34);

def bullish = if vma8 > vma21 and vma21 > vma34 then 1 else 0;
def bearish = if vma8 < vma21 and vma21 < vma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;

AddLabel(yes, if bullish then "Stage: Accelerating " else if bearish then "Stage: Decelerating " else if close >= VMA then "Stage: Accumulation " else "Stage: Distribution ", if bullish then color.green else if bearish then color.red else if close >= VMA then color.yellow else color.orange);

VMA.assignValueColor(if bearish and close<= VMA then color.red else if bullish and close >= VMA then color.green else color.gray);

def accumulationtoaccelation = if (bullish and close>=VMA) then 1 else 0;
def distributiontoacceleration = if (bearish and close <= VMA) then 1 else 0;

AddChartBubble(accumulationtoaccelation and !accumulationtoaccelation[1] and close <= close[1], close, "V+ " + round(close,2), color.light_green);
AddChartBubble(distributiontoacceleration and !distributiontoacceleration[1] and close <= close[1], close, "V- " + round(close,2), color.light_orange);

def accelationtoaccumulation = if (bullish and close<=VMA) then 1 else 0;
AddChartBubble(accelationtoaccumulation and !accelationtoaccumulation[1], close, "Accum", color.light_gray);

def distributiontoaccumulationton = if (bearish and close>=VMA) then 1 else 0;
AddChartBubble(distributiontoaccumulationton and !distributiontoaccumulationton[1], close, "Dist", color.light_gray);

# end of code
Thank you @rad14733 for the reference. I have attached a sample image of what my daily chart looks like. Good luck again.

82IcyRG.png


J6AxHgb.png
 
Last edited:

gravity2726

New member
VIP
# cabe1332 20210115_1700 # I have made some modifications customize to my needs and requirements. # Credit to team TOSindicators https://tosindicators.com/indicators # Market Pulse, a powerful tool that lets you identify which one of the four market stages ( accumulation, distribution, acceleration) we are currently in. # It uses Moving Average along with Volume Weighted Moving Averages to try and identify which one of the four market stages. # I've added Stage Label, indicator bubbles on a plotline that indicates buying increase/decrease (V+/V- bubble) with the price on which candle. # start of code input price = close; input length = 9; def tmp1 = if price > price[1] then price - price[1] else 0; def tmp2 = if price[1] > price then price[1] - price else 0; def d2 = sum(tmp1, length); def d4 = sum(tmp2, length); def cond = d2 + d4 == 0; def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100; def coeff = 2 / (length + 1) * AbsValue(ad3) / 100; def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price); plot VMA = asd; VMA.setDefaultColor(GetColor(0)); def vma8 = sum(volume * close,8) / sum(volume,8); def vma21 = sum(volume * close,21) / sum(volume,21); def vma34 = sum(volume * close,34) / sum(volume,34); def bullish = if vma8 > vma21 and vma21 > vma34 then 1 else 0; def bearish = if vma8 < vma21 and vma21 < vma34 then 1 else 0; def distribution = if !bullish and !bearish then 1 else 0; AddLabel(yes, if bullish then "Stage: Accelerating " else if bearish then "Stage: Decelerating " else if close >= VMA then "Stage: Accumulation " else "Stage: Distribution ", if bullish then color.green else if bearish then color.red else if close >= VMA then color.yellow else color.orange); VMA.assignValueColor(if bearish and close<= VMA then color.red else if bullish and close >= VMA then color.green else color.gray); def accumulationtoaccelation = if (bullish and close>=VMA) then 1 else 0; def distributiontoacceleration = if (bearish and close <= VMA) then 1 else 0; AddChartBubble(accumulationtoaccelation and !accumulationtoaccelation[1] and close <= close[1], close, "V+ " + round(close,2), color.light_green); AddChartBubble(distributiontoacceleration and !distributiontoacceleration[1] and close <= close[1], close, "V- " + round(close,2), color.light_orange); def accelationtoaccumulation = if (bullish and close<=VMA) then 1 else 0; AddChartBubble(accelationtoaccumulation and !accelationtoaccumulation[1], close, "Accum", color.light_gray); def distributiontoaccumulationton = if (bearish and close>=VMA) then 1 else 0; AddChartBubble(distributiontoaccumulationton and !distributiontoaccumulationton[1], close, "Dist", color.light_gray); # end of code
Hello Caleb, I like the setup you posted in the images below, Can you please share the setup or code , how to create one. Thanks for your help
 

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

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
 

cabe1332

Member
Hello Caleb, I like the setup you posted in the images below, Can you please share the setup or code , how to create one. Thanks for your help

Hi @gravity2726 and @PlsHelpTheNeewbieee36 , I am glad you approved of my setup. It is months and hours learning to code and backtesting TOS language and application. I thank and credit this site for the shared codes, strategy, and knowledge of @BenTen and the rest of the usethinkscript.com team.

What you see on my daily chart are collections of customized scripts that work with my trading style. I am a trend trader, short/long positions, and recently scalping near 52Wk Highs. The setup and strategy I have will take a boatload of explaining. If you can tell me what you see that you like, I maybe can share portions at a time.

I have a full-time job, but currently working at home due to a pandemic. I am building my account, at this time, small ($10K), and hope someday I will say goodbye to PDT to fully utilize the tools I've setup. I like it very much and it's effective (trading ratio on average 80-90%).

Good luck and happy trading!

cabe1332
 

BannonMan85

New member
VIP
Hi @gravity2726 and @PlsHelpTheNeewbieee36 , I am glad you approved of my setup. It is months and hours learning to code and backtesting TOS language and application. I thank and credit this site for the shared codes, strategy, and knowledge of @BenTen and the rest of the usethinkscript.com team.

What you see on my daily chart are collections of customized scripts that work with my trading style. I am a trend trader, short/long positions, and recently scalping near 52Wk Highs. The setup and strategy I have will take a boatload of explaining. If you can tell me what you see that you like, I maybe can share portions at a time.

I have a full-time job, but currently working at home due to a pandemic. I am building my account, at this time, small ($10K), and hope someday I will say goodbye to PDT to fully utilize the tools I've setup. I like it very much and it's effective (trading ratio on average 80-90%).

Good luck and happy trading!

cabe1332
Hey cabe1332, I know that I wasn't one of the ones that originally asked but I would like to know what you are using to get the buy and sell signals on what looks like the market pulse indicator or whatever indicator that is. I have recently began scalping and I have been looking for something that would yield consistency to my entries. Also, my preference is to play momentum and trend so any indicator advice on that front would be very useful as well.

Thanks for all you guys here do. I have been watching from a distance and been trying different indicators here on the forums for a while but this is my first(hopefully of many) post. thank you once again for any help
 

cabe1332

Member
Hey cabe1332, I know that I wasn't one of the ones that originally asked but I would like to know what you are using to get the buy and sell signals on what looks like the market pulse indicator or whatever indicator that is. I have recently began scalping and I have been looking for something that would yield consistency to my entries. Also, my preference is to play momentum and trend so any indicator advice on that front would be very useful as well.

Thanks for all you guys here do. I have been watching from a distance and been trying different indicators here on the forums for a while but this is my first(hopefully of many) post. thank you once again for any help

Hi @BannonMan85, I am using Trend Reversal for the Buy/Sell signal. The original code is available here. But, I have modified it a bit to work for my trading style and cut down on the signals to just show bubbles. I have added the volume average signal as a condition.

The market pulse is another indicator plotted that provides you with stages of the market. Helpful indicator for momentum/trending when to go long with your trade.

I am not a full scalper but scalp good setups. I recently added to my strategy Near 52 Wk High. I created a scan/watchlist that gives me range stocks that are within 10% of 52 Wk High. The scan includes EMAstack (full set of EMAs = bullish script) so all you do is select which stocks you think will make the move, but when it starts to momo (use TT_Squeeze or SqueezePro indicator) buy on the second candle and watch it rip. I then set my limit sell order a little above the 52 Wk High for a scalping profit usually 10-15%.

I find a must have and very useful is the Hull Moving Average Concavity and Turning Points (Author: Seth Urion (Mahsume) Version: 2020-02-21 Initial Public). You can search for it on this site. It is very accurate and it is a magic 8 ball. You'll need to play with the settings, but it is worth it.

Having custom labels is also worthwhile. It can help with choosing a stock, entry, exit, and shortcut indicators that not need to be a real state on your chart like the VWAP (just need to know above or below price). I like to see all info readily avail.

I would suggest indicators are:

Hull Moving Average Concavity and Turning Points
Trend Reversal
TT_Squeeze
RSI
9 and 21 EMA - watch youtube for scalping strategy (entry/exit)
Volume
Some labels

Take your time, learn, and enjoy it. Don't let bad days or trade get to you cause we all have them. Patience and good set ups is rewarding.

Been trading since August 2020, a little over six months. I spent hours learning and setting up what works for me. You will find yours too.

Good luck!

cabe1332
 

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
 

Similar threads

Top