# Compare RelativeVolumeStDev Bars

#### XeoNoX

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

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?

@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

Gorgeous! Thank you so much!

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!

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:
just try and it out and see if it works, you can always have it plot below the chart and see how it works.

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?

87k+ Posts
389 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?