# ThinkorSwim Volume Spike Alert and Scanner

@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...
Thanks tons. Your comment helped me figure it out.

Hello, was hoping for some quick assistance. I am new to scripting.

I want to return results in TOS for the following.

1 minute chart
if looking at 2 volume bars, I want results returned if the 2nd volume bar is 400% higher than the 1st volume bar.

Thanks so much for any assistance!

JB

Hello, was hoping for some quick assistance. I am new to scripting.

I want to return results in TOS for the following.

1 minute chart
if looking at 2 volume bars, I want results returned if the 2nd volume bar is 400% higher than the 1st volume bar.

Thanks so much for any assistance!

JB
@offscript Let's break down what it is that you want to do in a mathematically logical fashion and go from there... What is the simplest method you know to check to see of one number is 4x as big as the previous number...??? You would divide the second number by the first number, right...??? So how would you do this with volume...??? It would be volume / volume[1] > 4... So your code would resemble the following scanner code... Both variants should work...

Ruby:
``````plot volumeX4 = volume / volume[1] >= 4;

--OR--

plot volumeX4 = if volume / volume[1] is greater than or equal to 4 then 1 else Double.NaN;``````

@offscript Let's break down what it is that you want to do in a mathematically logical fashion and go from there... What is the simplest method you know to check to see of one number is 4x as big as the previous number...??? You would divide the second number by the first number, right...??? So how would you do this with volume...??? It would be volume / volume[1] > 4... So your code would resemble the following scanner code... Both variants should work...

Ruby:
``````plot volumeX4 = volume / volume[1] >= 4;

--OR--

plot volumeX4 = if volume / volume[1] is greater than or equal to 4 then 1 else Double.NaN;``````

Many thanks! I will throw this into the TOS script editor and see what it produces.

Many thanks! I will throw this into the TOS script editor and see what it produces.

Good luck... And if you get too many results you could narrow them with the following...

Ruby:
``````def lowLimit = 4;
def highLimit = 5;
def volDivAmt = volume / volume[1];

plot volumeX4 = if Between(volDivAmt, lowLimit, highLimit) then 1 else Double.NaN;``````

Here are filtered results for the previous code...

And here are the filtered results of the code in this post...

Last edited:
Kaz
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 everyone. Despite alerts with this study are great, I would like to know what would you suggest in order to have a record of the alerts triggered. If I´m in a trade and I miss the alert message, then I no longer have a chance to know what was alerted. Another useful thing would be to see some pop-ups on the charts, especially for the stocks on my watchlist. Thanks in advance for the support.

@mng84 How long are you away between checks...??? Are you aware that the Message Center (Messages in the top of your main panel) stores all of the days alerts which can be exported...??? It can also be detached into its own window...

@mng84 How long are you away between checks...??? Are you aware that the Message Center (Messages in the top of your main panel) stores all of the days alerts which can be exported...??? It can also be detached into its own window...
Thank you. I´m not away too long but I have to switch screens and sometimes I lose the alert. Honestly didn´t know about the message center. Too much to learn!!! Thanks again!

Hello everyone. Despite alerts with this study are great, I would like to know what would you suggest in order to have a record of the alerts triggered. If I´m in a trade and I miss the alert message, then I no longer have a chance to know what was alerted. Another useful thing would be to see some pop-ups on the charts, especially for the stocks on my watchlist. Thanks in advance for the support.

You can add alerts on scans to notify you when symbols are added and/or removed. You can set those alerts to notify you via mobile push (if you have TOS mobile on your devices) or email. I'm not feeling like typing the steps to do it but I'm sure you can find it in the help or via search engine.

If you want to treat your watchlist differently than other random symbols you can create a duplicate of the scan and set the Scan In at the top to your watchlist instead of whatever you currently use, then set up whatever alerts you want on that scan.

The best you could do for "pop-ups on the charts" is write a study that shows a label when the alert condition is currently met on the stock that is already loaded in the chart. You could also have it play a sound and/or change the background color of the chart if you think the label might not get your attention. Nothing on a chart will have any knowledge of other symbols in your watchlist.

Hello All,

I modified little bit of code posted by XeoNoX please let me know your opinions on this
Code:
``````#Unusual volume scanner by XeoNoX
#Via usethinkscript.com
#Volume in the last 5 minutes is atleast 2000% of the average 50 bars
#set for 5 minute agreggation
#raw percent value
#def percentage = 2000;
#percent in decimal format
def percent_as_decimal = 2000*.01;
#average of last 50 bars
def avgvol =  average(volume,50);
#total volume of last bar
def lastmins = volume;
#average volume multiplied by desired percentage
def percent_of_avg = avgvol*percent_as_decimal;
# scans for volume is greater than than then 50 minute average by over 2000%
def afterStart = secondsfromtime(0945)>=0;
def beforeEnd = secondstilltime(1545)>=0;
def conditionTrue = lastmins>percent_of_avg;

plot alert = afterStart and beforeEnd and conditionTrue;``````

@prap4trading The code looks fine to me. I played with scans for high volume breakouts last year and I would recommend a few things. I'd share what I created but I nuked it when I switched from day trading to swing trading.

Don't look for a single bar with high volume. Most of the signals you'll get will be worthless -- a single big order that hit a low volume stock and then nothing else happened. Instead, look for 2 or more consecutive bars. Reduce the time period if you're worried about how late that brings you to the party (3m instead of 5m).

Add a price component. True Range some multiple of Average True Range on the same bars as the increased volume. Or even ATR(3) > ATR()*3 or something like that to make the code simple.

I'd also recommend using the 3 minute timeframe due to the general understanding around the ThinkOrSwim community that 3 minutes is the soonest TOS servers will refresh your scan results.

Lastly, while you're testing/tweaking it helps to set an alert on the scan to email you when a symbol is added to the results. That way when you're finished trading for the day you can look at all of them to identify any adjustments you want to make. The email timestamps will tell you what times to look at on the charts.

@prap4trading The code looks fine to me. I played with scans for high volume breakouts last year and I would recommend a few things. I'd share what I created but I nuked it when I switched from day trading to swing trading.

Don't look for a single bar with high volume. Most of the signals you'll get will be worthless -- a single big order that hit a low volume stock and then nothing else happened. Instead, look for 2 or more consecutive bars. Reduce the time period if you're worried about how late that brings you to the party (3m instead of 5m).

Add a price component. True Range some multiple of Average True Range on the same bars as the increased volume. Or even ATR(3) > ATR()*3 or something like that to make the code simple.

I'd also recommend using the 3 minute timeframe due to the general understanding around the ThinkOrSwim community that 3 minutes is the soonest TOS servers will refresh your scan results.

Lastly, while you're testing/tweaking it helps to set an alert on the scan to email you when a symbol is added to the results. That way when you're finished trading for the day you can look at all of them to identify any adjustments you want to make. The email timestamps will tell you what times to look at on the charts.
Thanks and would be great if you can point some sample scripts to start with.

Thanks and would be great if you can point some sample scripts to start with.

Here's an example you could start with and tweak as desired. With the code you already posted, you can change the last line to this:

Ruby:
``````plot alert =
afterStart and beforeEnd # it's the right time of day
and conditionTrue and conditionTrue[1] # volume increase
and ATR(2) > ATR() * 2 # price range increase
;``````

If you want 3 qualifying candles instead of 2 you can add `and conditionTrue[2]` and change `ATR(2) to ATR(3)`.

You can play with `ATR() * 2` and make it `ATR() * 1.5` or less or `ATR() * 3` or higher depending on how strict it needs to be for it to be useful to you.

My experience has been it's better to start with looser criteria and tighten if needed. If it's too strict at the start you won't see any results and it's hard to adjust from there when you have multiple criteria.

Putting the conditions on separate lines like I did here has a few advantages.
1. Can easily comment out a single condition in the middle of the statement while debugging
2. Can place comments behind individual conditions within the overall statement
3. More readable, in my opinion

Here's an example you could start with and tweak as desired. With the code you already posted, you can change the last line to this:

Ruby:
``````plot alert =
afterStart and beforeEnd # it's the right time of day
and conditionTrue and conditionTrue[1] # volume increase
and ATR(2) > ATR() * 2 # price range increase
;``````

If you want 3 qualifying candles instead of 2 you can add `and conditionTrue[2]` and change `ATR(2) to ATR(3)`.

You can play with `ATR() * 2` and make it `ATR() * 1.5` or less or `ATR() * 3` or higher depending on how strict it needs to be for it to be useful to you.

My experience has been it's better to start with looser criteria and tighten if needed. If it's too strict at the start you won't see any results and it's hard to adjust from there when you have multiple criteria.

Putting the conditions on separate lines like I did here has a few advantages.
1. Can easily comment out a single condition in the middle of the statement while debugging
2. Can place comments behind individual conditions within the overall statement
3. More readable, in my opinion
Thanks, will try this out following code. Please let me know your thoughts'

P.S: I am in PST zone and my time on TOS is also set to PST so i believe 0645 and 1245
should take care of first 15 and last 15 minutes noise.

Code:
``````def afterStart = secondsfromtime(0645)>=0;
def beforeEnd = secondstilltime(1245)>=0;
def vol_length = 30;
def AVGV = Average(volume, vol_length);
def lastNmins = (volume);
# scans for volume is greater than 500% of  average volume
def conditionTrue = lastNmins >  (AVGV * 5);

plot alert = afterStart and beforeEnd and
conditionTrue and conditionTrue[1] # volume increase
and ATR(2) > ATR() * 2; # price range increase``````

Last edited:
@prap4trading The code looks fine to me. I played with scans for high volume breakouts last year and I would recommend a few things. I'd share what I created but I nuked it when I switched from day trading to swing trading.

Don't look for a single bar with high volume. Most of the signals you'll get will be worthless -- a single big order that hit a low volume stock and then nothing else happened. Instead, look for 2 or more consecutive bars. Reduce the time period if you're worried about how late that brings you to the party (3m instead of 5m).

Add a price component. True Range some multiple of Average True Range on the same bars as the increased volume. Or even ATR(3) > ATR()*3 or something like that to make the code simple.

I'd also recommend using the 3 minute timeframe due to the general understanding around the ThinkOrSwim community that 3 minutes is the soonest TOS servers will refresh your scan results.

Lastly, while you're testing/tweaking it helps to set an alert on the scan to email you when a symbol is added to the results. That way when you're finished trading for the day you can look at all of them to identify any adjustments you want to make. The email timestamps will tell you what times to look at on the charts.
@Slippage you seem to be a seasoned hand, could you talk about your chart setup, how, and why? What do you pay attention to most? What are the most important lessons in swing trading? Thank you.

Thanks, will try this out following code. Please let me know your thoughts'

P.S: I am in PST zone and my time on TOS is also set to PST so i believe 0645 and 1245
should take care of first 15 and last 15 minutes noise.

Code:
``````def afterStart = secondsfromtime(0645)>=0;
def beforeEnd = secondstilltime(1245)>=0;
def vol_length = 30;
def AVGV = Average(volume, vol_length);
def lastNmins = (volume);
# scans for volume is greater than 500% of  average volume
def conditionTrue = lastNmins >  (AVGV * 5);

plot alert = afterStart and beforeEnd and
conditionTrue and conditionTrue[1] # volume increase
and ATR(2) > ATR() * 2; # price range increase``````
why do you think the first and last 15 min are noise?

Generally First 15 and last 15 volume will spike and i dont want to catch that . What i am looking for
volume spike due to some event or news so avoiding the usual suspects for now.

@Slippage you seem to be a seasoned hand, could you talk about your chart setup, how, and why? What do you pay attention to most? What are the most important lessons in swing trading? Thank you.

A complete response to that would be be off topic and probably long winded. I'm not really seasoned. I just have a couple of advantages. I'm an early retired software engineer so using ThinkScript and figuring out software features both come easily to me. Not to mention having a systematic approach to things. No longer having a job ****ing most of my life away allows me to focus as much time as I want on trading and quite often it's 16+ hours a day while I'm in a learning or scripting/testing phase.

I'm working on a new strategy that takes elements from Raghee Horner's 34 ema wave strategy and combines it with multiple timeframes of MACD, which I got into because of Moxie. I'll probably post everything here once it's complete if it has good results. It's been working great the two weeks I've been using it while still developing the code.

Nice! so you are with simpler trading? are you on discord?

No, I'm not with ST or anyone else. Nor would I ever want to be since that would be having job. I'm just a trader with a bit more than a year of experience day trading whatever stocks were in play each day, or sometimes index ETFs, and then transitioned to swing trading a few months ago. I've put a ridiculous amount of time into ThinkScript experiments so things like this volume scan are roads I've already been down. I'd say I'm still getting a handle on swings since I haven't settled on a strategy yet.

My focus on ST strategies is mainly because they're accessible. My day trading strategies are mostly not applicable to swings, though one, maybe two, of them can be adapted. Squeeze seems to be the most used swing strategy on YouTube. Where else can we get proven strategies that enough people are executing to give us some confidence we're not wasting our time on marketing hype with no results? I didn't really care for squeeze while trading it as described in John Carter's book so I started looking at ST's other stuff. I'd probably like squeeze more now that I know other criteria to couple it with.

The Moxie strategy appealed to me so I decided to pursue that. Once I got into it further I realized it's not as objective as I'd prefer. I want a strategy with little enough subjectivity it's relatively easy to define it in code. It enables scripting back tests. It enables writing chart studies and scans that do most of the work. For the main strategy I used for day trading I was able to script a test and then use the script to test variations of the rules. That gave me data for literally hundreds of thousands of trades covering 50 stocks over a 180 day period (longest period for which TOS will give you a 5m chart). That gave me a lot of confidence in the strategy which made it easy to follow the rules.

My goal is to spend 1 to 2 hours to review my swing positions, move stops or place exit orders, scan for new setups, place a couple of entry orders and then forget about the market until I repeat the routine the next day or a day or two later. My willingness to put so much time and effort in up front is to hopefully reach that goal sooner.

Yes, you can find me on useThinkScript's Discord if you want to discuss something there.

Here is simple snnipet to find Relative volume of previous 5 candles, may be this can be used in scanning volume spikes

Code:
``````#rVol
input  vol_length =30;
def above_average = 200;
def avgVol = Average(volume , vol_length);
def last = volume;
def rVol = Round((last / avgVol) * 100, 0);
AddLabel(yes,"V4:" +rVol[4] +"%", if rVOl[4] > above_average then color.DARK_GREEN else color.ORANGE);
AddLabel(yes,"V3:" +rVol[3] +"%", if rVOl[3] > above_average then color.DARK_GREEN else color.ORANGE);
AddLabel(yes,"V2:" +rVol[2] +"%", if rVOl[2] > above_average then color.DARK_GREEN else color.ORANGE);
AddLabel(yes,"V1:" +rVol[1] +"%", if rVOl[1] > above_average then color.DARK_GREEN else color.ORANGE);
AddLabel(yes,"V:" +rVol +"%", if rVOl > above_average then color.DARK_GREEN else color.ORANGE);``````

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
395 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?