 # Compare RelativeVolumeStDev Bars

#### jphilli11

##### Member
This is probably an easy problem to solve but I'm brand new to all this so please go easy on me....
I'd like to add a condition in a scanner that confirms the current bar (on 10 min chart) is not the highest of the last 10 in RelativeVolumeStDev ( StdLevel not vol).

If curbar.StdLevel is highest(10) then false, else true.... something to that effect.

#### XeoNoX

##### Well-known member
VIP
You stated "RelativeVolumeStDev ( StdLevel not vol)."
You stated "curbar.StdLevel "

For the most part without the source code you are working with we have no clue what those syntax u mentioned above means or what you are referring to.

And 2nd of all ...the STDLEVEL syntax on the RelativeVolumeStDev is a constant that is manually inputed and does not change, so it cant be higher or lower than what you set it at input. therefore it nullifies your scan.

#### jphilli11

##### Member
Thanks Xeo, as I said I’m a dummy when it comes to this. What I’m trying to achieve is something like the following (not in thinkscript, just how the operations would work):

def curvol = standardeviation of current bar
Def uppvol = highest standard deviation over last 10 bars

if curvol >= uppvol then return false, otherwise return true.

I’m only interested in which deviation range the volume falls and not necessarily the actual volume. I.e. 1, 2, 3, 4, etc.

Does this help?

#### XeoNoX

##### Well-known member
VIP
Thanks Xeo, as I said I’m a dummy when it comes to this. What I’m trying to achieve is something like the following (not in thinkscript, just how the operations would work):

def curvol = standardeviation of current bar
Def uppvol = highest standard deviation over last 10 bars

if curvol >= uppvol then return false, otherwise return true.

I’m only interested in which deviation range the volume falls and not necessarily the actual volume. I.e. 1, 2, 3, 4, etc.

Does this help?

The following code scans as follows: the largest standard volume deviation bar over last 10 bars is less than current standard volume deviation bar

(in other words the current volume deviation bar is greater than the last 10 volume deviation bars)

You can make the scan true or false or you can inverse it with "isOut "

Remember if you found this post useful to hit the like button.

Code:
``````declare lower;
input bars_ago = 10;
input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
def StDevLevel = numDev;

def RelVol_within_x_bars =  Highest(relvol,bars_ago);

plot scan = (RelVol_within_x_bars < relvol);``````

Last edited:
• jstrandt

#### jphilli11

##### Member
Works great, thank you so much!

#### jphilli11

##### Member
Hey @XeoNoX,

How would I go about counting the number of StandardDeviation events that occur within a certain number of bars. For example, I want to know how many times the StdDev was > 4 in the last 10 bars....

Thanks for any help!

#### XeoNoX

##### Well-known member
VIP
@jphilli11

COUNTS NUMBER OF BARS ABOVE XYZ Relative VOLUME STD DEV in PAST XYZ BARS Code:
``````declare lower;
declare zerobase;
#COUNTS NUMBER OF BARS ABOVE XYZ Relative VOLUME STD DEV in PAST XYZ BARS
#BY XEONOX VIA USETHINKSCRIPT.COM

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot StDevLevel = numDev;

RelVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelVol.SetLineWeight(3);
RelVol.DefineColor("Above", GetColor(0));
RelVol.DefineColor("Below", GetColor(2));
RelVol.AssignValueColor(if RelVol >= numDev then RelVol.Color("Above") else RelVol.Color("Below"));
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);
#COUNTS BARS ABOVE XYZ REL VOL STD DEV
input count_length = 10;
def count_above = Sum(RelVol > numdev, count_length);
"No. of closes above " + numDev + " RelVol Std Dev in the past " + count_length + " bars = " + count_above,
Color.ORANGE);``````

above code counts number of bars within xyz relative volume standard deviation
Remember to hit the like button if you found this post useful

• BenTen

#### jphilli11

##### Member
Gorgeous! Thank you so much!

#### floydddd

##### Active member
i kind of love this and would also love to see it as a custom watchlist column, with numbers indicating how far back in the past the last instance of xyz rel vol stan dev took place. possible?

i've been working on it myself, not with this study but with the tape momentum one, with not a lot of luck. i'm figuring if someone can do it for this indicator, i'll be able to figure it out for the other. likely story, i know, but ya never know!

#### floydddd

##### Active member
well, i think i did it myself. didn't seem so hard ... ifn i did it right. anyone care to double check?

Code:
``````#COUNTS NUMBER OF BARS ABOVE XYZ Relative VOLUME STD DEV in PAST XYZ BARS
#BY XEONOX VIA USETHINKSCRIPT.COM

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
def StDevLevel = numDev;

#COUNTS BARS ABOVE XYZ REL VOL STD DEV
input count_length = 10;
def count_above = Sum(RelVol > numdev, count_length);

plot value = count_above;``````

Last edited:

#### XeoNoX

##### Well-known member
VIP
just try and it out and see if it works, you can always have it plot below the chart and see how it works.

#### floydddd

##### Active member
seems to be working so far. thanks for the response. btw / if you've got a moment, how would you change it to show the number of bars back the last firing of the desired state took place?