# Unusual Volume Scan within last 10 bars rather than just current bar

##### New member
Hi, I noticed on ThinkorSwim you can only find unusual volume based scan based on current candle volume. I wanted to find Unusual volume greater than 40 % last 50 periods in last 10 periods. So I can see the volume spikes on stocks several days ago as well. Appreciate if anyone on here can help me, Thank you.

Solution

EDIT: --- fixed code

this looks back 50 bars to find the highest volume, starting from the previous bar.
multiplies that number by 1.4 ( 40% + 100%)
then checks if current volume is > it. if it is, then 1 else 0.
then check if at least 1 bar in the last 10, found higher volume.

Code:
``````def dat = volume;
def lookback1 = 50;
def hivol = highest( dat[1] , lookback1);
def per = 40;
def hi_per_value = (1+ ( per/100))*hivol;
def isvol_bigger = if (dat > hi_per_value) then 1 else 0;
def within_xbars = 10;
plot z = if sum(isvol_bigger, within_xbars) >= 1 then 1 else 0;``````

when there is a big volume bar, it will cause hivol to be true for the next 50 bars.
z will be true on that bar...

EDIT: --- fixed code

this looks back 50 bars to find the highest volume, starting from the previous bar.
multiplies that number by 1.4 ( 40% + 100%)
then checks if current volume is > it. if it is, then 1 else 0.
then check if at least 1 bar in the last 10, found higher volume.

Code:
``````def dat = volume;
def lookback1 = 50;
def hivol = highest( dat[1] , lookback1);
def per = 40;
def hi_per_value = (1+ ( per/100))*hivol;
def isvol_bigger = if (dat > hi_per_value) then 1 else 0;
def within_xbars = 10;
plot z = if sum(isvol_bigger, within_xbars) >= 1 then 1 else 0;``````

when there is a big volume bar, it will cause hivol to be true for the next 50 bars.
z will be true on that bar and 9 bars after it. so when 1 big volume bar happens, there will be a trigger every bar , for 59 bars.

Last edited:

this looks back 50 bars to find the highest volume, starting from the previous bar.
multiplies that number by 1.4 ( 40% + 100%)
then checks if current volume is > it. if it is, then 1 else 0.
then check if at least 1 bar in the last 10, found higher volume.

Code:
``````dat = volume;
def lookback1 = 50;
def hivol = highest( dat[1] , lookback1);
def per = 40;
def hi_per_value = (1+ ( per/100))*hivol;
def isvol_ bigger = if (dat > hi_per_value) then 1 else 0;
def within_xbars = 10;
plot z = if sum(isvol_ bigger, within_xbars) >= 1 then 1 else 0;``````

when there is a big volume bar, it will cause hivol to be true for the next 50 bars.
z will be true on that bar and 9 bars after it. so when 1 big volume bar happens, there will be a trigger every bar , for 59 bars.
Thank you for the speedy response, appreciate it!

If i want to increase to 200%
Change 40 to 200

when i copy the code i get this error-
Invalid statement: def at 6:1
Invalid statement: plot at 8:1

this looks back 50 bars to find the highest volume, starting from the previous bar.
multiplies that number by 1.4 ( 40% + 100%)
then checks if current volume is > it. if it is, then 1 else 0.
then check if at least 1 bar in the last 10, found higher volume.

Code:
``````dat = volume;
def lookback1 = 50;
def hivol = highest( dat[1] , lookback1);
def per = 40;
def hi_per_value = (1+ ( per/100))*hivol;
def isvol_ bigger = if (dat > hi_per_value) then 1 else 0;
def within_xbars = 10;
plot z = if sum(isvol_ bigger, within_xbars) >= 1 then 1 else 0;``````

when there is a big volume bar, it will cause hivol to be true for the next 50 bars.
z will be true on that bar and 9 bars after it. so when 1 big volume bar happens, there will be a trigger every bar , for 59 bars.
can we add more condition as volume can increase to short the stock to.
like how much stock move in last 50 day and last 10 day we can put that label on upper chart.dollar amount and percentage amount.

when i copy the code i get this error-
Invalid statement: def at 6:1
Invalid statement: plot at 8:1

sorry about that. i fixed it. i have a bad habit of trying to answer questions when i am away from my computer, meaning i type them up on my cell...

Hello @halcyonguy,

Thank you for building this indicator. Could you please use this same concept to build the version below? I would greatly appreciate it.

Criteria:
• Looks back 50 bars to find single bar volume greater than X amount (say 5,000,000).
• When current bar volume or previous 50 bars is ≥ X volume, then 1, else 0 for every bar after that within the trading day.
It has been hard to scan for a current or previous candle breaking a specific volume threshold. I know it is possible but I lack your skillset. I believe tweaking your Volume Lookback to scan for when that threshold has been breeched would be the solution--especially when quickly combing through a watchlist for that "z" value of 1 or 0 depending on which tickers meet criteria.

Here is an example. Say SPY traded 80,000,000 on a given day. This indicator would look back 50 bars to find a single bar volume greater than or equal to 5,000,000. When this criteria is met for the current bar or 50 bars back, "z" will be true for every bar after it until market close. This way, the criteria can be scanned for or quickly identified since any stock that meets criteria will have a "z" value of 1.

Thank you very much for your help.

sorry about that. i fixed it. i have a bad habit of trying to answer questions when i am away from my computer, meaning i type them up on my cell...
Hello halcyonguy, I am trying to use this scan you made but i am also getting a Invalid statement as the other user, I see your comments that this error was fixed but I don't see the newer corrections. Can you help with this? Thanks for yur help

scan for stocks with unusual buying volume Questions 4
Unusual Volume Moving Average Scan & Watchlist Questions 1
Unusual Volume over past 30 days Questions 2
highest volume labels Questions 4
These 3 Volume Labels Questions 0

87k+ Posts
378 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
• 1 full year of unlimited support

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?