# Calculate Avg of Volume Bars

#### hboogie

##### Member
Plus
Hi,

Came across this really cool study from @Svanoy https://usethinkscript.com/threads/...volume-rvol-for-thinkorswim.16051/post-130478

And wanted to ask if there was a way to provide the code needed to sum up and derive the average volume over either 10 or 15 bars and use that as a trigger point for the remainder of the session.

In this case, looking at this chart, I'd like to sum up the average of the first 10 or 15 bars from the cash open and then carry that number forward to signal when a single bar exceeds that average.

Example here would to be sum up the total volume from these 1m volume bars that span 15m from 9:30am (open) and then set triggers when volume bars exceed that avg volume summed up from the first 15m bars combined. The next step would be to set triggers for 25% 50% , 100% and 300% above the number derived from the first 15 volume bars.

H

Last edited:
Bump

Hi,

Came across this really cool study from @Svanoy https://usethinkscript.com/threads/...volume-rvol-for-thinkorswim.16051/post-130478

And wanted to ask if there was a way to provide the code needed to sum up and derive the average volume over either 10 or 15 bars and use that as a trigger point for the remainder of the session.

In this case, looking at this chart, I'd like to sum up the average of the first 10 or 15 bars from the cash open and then carry that number forward to signal when a single bar exceeds that average.

View attachment 21617
Example here would to be sum up the total volume from these 1m volume bars that span 15m from 9:30am (open) and then set triggers when volume bars exceed that avg volume summed up from the first 15m bars combined. The next step would be to set triggers for 25% 50% , 100% and 300% above the number derived from the first 15 volume bars.

H

sum up the average of the first 10...
your words are confusing. you keep saying sum and average? which one do you want? do you want to add up some volume bars ? or average them? or average a sum of an average of ....?
if you want an average, just say average.
don't confuse things by guessing at a procedure and saying sum.

your picture shows a positive histogram and a negative one. what formulas did you use to create them?

sum up the average of the first 10...
your words are confusing. you keep saying sum and average? which one do you want? do you want to add up some volume bars ? or average them? or average a sum of an average of ....?
if you want an average, just say average.
don't confuse things by guessing at a procedure and saying sum.

your picture shows a positive histogram and a negative one. what formulas did you use to create them?
The link has logic that looks like it calculates the average across the number of bars. I reference it only as a helpful guide.

In order to obtain an average, you'd have to sum up the bars. Apologies for the confusion. I'd like to SUM up the bars to obtain the AVERAGE and use that average throughout the session to identify when volume bars exceed that average.

In an effort of being detailed I may have caused confusion. Apologies.

The histogram is showing volume and was meant only as a visual reference of what I'm attempting to describe. The AVERAGE of the highlighted area (depending on user selection e.g. 10 bars, 15 bars, 5 bars) would then be used to trigger the arrows where single volume bars exceeded that average calculated.

H

The link has logic that looks like it calculates the average across the number of bars. I reference it only as a helpful guide.

In order to obtain an average, you'd have to sum up the bars. Apologies for the confusion. I'd like to SUM up the bars to obtain the AVERAGE and use that average throughout the session to identify when volume bars exceed that average.

In an effort of being detailed I may have caused confusion. Apologies.

The histogram is showing volume and was meant only as a visual reference of what I'm attempting to describe. The AVERAGE of the highlighted area (depending on user selection e.g. 10 bars, 15 bars, 5 bars) would then be used to trigger the arrows where single volume bars exceeded that average calculated.

H

no need for apologies. sometimes i say things to get people to try to understand the situation so they can ask better questions.

that study only shows a line at 1 hour, so it doesn't help

reread my post again and read this. when asking for help , don't tell others how to do something.
if you want an average, just say , i want the average of the first x bars in a day '
don't say , you have to use this method. (sum). there are usually several ways to do something.

-------------------------

this will find the average , for the first x bars (default 15) of a day.
draws a yellow line over those bars at the average level.
asks for 4 % levels , default 25, 50, 100, 300%) and draw lines for them
if volume crosses one of the 2 higher % lines, it draws a white dot.

Code:
``````# or_vol_avg

def na = Double.NaN;
def bn = barnumber();
def v = volume;

input avg_bar_qty = 15;
input per1 = 25;
input per2 = 50;
input per3 = 100;
input per4 = 300;

input start = 0930;
input end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def first = SecondsFromTime(start) == 0;

def vavg;
def firstbn;
if bn == 1 then {
vavg = 0;
firstbn = 0;
} else if first then {
vavg = (fold i = 0 to avg_bar_qty
with p
do p + getvalue(v, -i))/ avg_bar_qty;
firstbn = bn;
} else {
vavg = vavg[1];
firstbn = firstbn[1];
}

def avgbars = if bn >= firstbn and bn <= (firstbn + avg_bar_qty - 1) then 1 else 0;

plot z0 = if avgbars then vavg else na;
z0.setdefaultcolor(color.yellow);
z0.hidebubble();

plot z1 = if (!avgbars and daytime and per1 > 0) then (per1/100)*vavg else na;
plot z2 = if (!avgbars and daytime and per2 > 0) then (per2/100)*vavg else na;
plot z3 = if (!avgbars and daytime and per3 > 0) then (per3/100)*vavg else na;
plot z4 = if (!avgbars and daytime and per4 > 0) then (per4/100)*vavg else na;
z1.setdefaultcolor(color.light_gray);
z2.setdefaultcolor(color.light_gray);
z3.setdefaultcolor(color.light_gray);
z4.setdefaultcolor(color.light_gray);
z1.hidebubble();
z2.hidebubble();
z3.hidebubble();
z4.hidebubble();

input show_per3_dots = yes;
plot d3 = if show_per3_dots and !avgbars and daytime and per3 > 0 and (v > (per3/100)*vavg) then (per3/100)*vavg else na;
d3.SetPaintingStrategy(PaintingStrategy.POINTS);
d3.SetDefaultColor(Color.white);
d3.setlineweight(1);
d3.hidebubble();

plot d4 = if show_per3_dots and !avgbars and daytime and per4 > 0 and (v > (per4/100)*vavg) then (per4/100)*vavg else na;
d4.SetPaintingStrategy(PaintingStrategy.POINTS);
d4.SetDefaultColor(Color.white);
d4.setlineweight(1);
d4.hidebubble();
#``````

#### Attachments

• 00b-img1.JPG
64.2 KB · Views: 66
You’re a treasure. I absolutely had zero intention on telling anyone how to do something I clearly can’t. I’ve never done that and if it came off that way, I apologize (for the last time)

This looks wonderful. Will report back.

Hi @halcyonguy

Can't thank you enough for this excellent indicator. I wanted to ask if it were
possible to add a feature to it that I can't quite describe with words but can show you visually.

Lots of times throughout the day, the vol dries up, as indicated by these boxes.

The feature/add-on would (for lack of the proper technical/coding term) add a cloud over the volume bars such that they follows the direction of price. So if price is decreasing, the clouds print red even when volume expands. If price is increasing, the cloud would print green.

The idea would be that these clouds (green/red) follow the price action as it moves throughout the session. During periods of low volume/consolidation it would give visual clues that a potential move is incoming. Directionality is always a combination of context and more art than science. So the purpose is to provide visual clues for both conditions -- contraction and expansion.

I'll defer to you if you think something else would work in place of these "clouds".

Thanks again for your time and work.

H

Hi @halcyonguy

Can't thank you enough for this excellent indicator. I wanted to ask if it were
possible to add a feature to it that I can't quite describe with words but can show you visually.

Lots of times throughout the day, the vol dries up, as indicated by these boxes.
View attachment 21771View attachment 21772View attachment 21773

The feature/add-on would (for lack of the proper technical/coding term) add a cloud over the volume bars such that they follows the direction of price. So if price is decreasing, the clouds print red even when volume expands. If price is increasing, the cloud would print green.View attachment 21774

The idea would be that these clouds (green/red) follow the price action as it moves throughout the session. During periods of low volume/consolidation it would give visual clues that a potential move is incoming. Directionality is always a combination of context and more art than science. So the purpose is to provide visual clues for both conditions -- contraction and expansion.

I'll defer to you if you think something else would work in place of these "clouds".

Thanks again for your time and work.

H
@halcyonguy

Would it be possible to implement a feature related to low rvol condition that paints the candles a color (white) starting with the 2nd consecutive volume bar (perhaps adjustable to increase hitrate of condition) that prints below the lowest rvol threshold, as indicated here:

Thank you!

Last edited:

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