# 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 , 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...

#### halcyonguy

##### Well-known member
VIP

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 , 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:
• ##### New member

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 , 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!

#### Drmoh1800

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

#### coolcat7fl

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

#### charlie2598

##### Member
VIP

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

#### halcyonguy

##### Well-known member
VIP
• 