# Mixed Volume Average

#### anty

##### New member
I added volume average to the Mixed Volume indicator to plot the average Buy and average Sell volume. Would it be possible to combine the Buy and Sell averages into one line that changes colors based on whether the dominant average is a Buy or Sell?

Code:
``````declare on_volume;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V*(C-L)/(H-L);
def Selling = V*(H-C)/(H-L);

# Selling Volume
Plot SV = selling;
SV.setPaintingStrategy(PaintingStrategy.Histogram);
SV.SetDefaultColor(Color.Red);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);

# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
Plot BV = volume;
BV.setPaintingStrategy(PaintingStrategy.Histogram);
BV.SetDefaultColor(Color.Dark_Green);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);

input length = 50;

plot VolAvg = Average(sv, length);
plot VolAvg2 = Average(bv, length);
VolAvg.SetDefaultColor(GetColor(8));
VolAvg.SetDefaultColor(GetColor(7));``````

#### horserider

##### Well-known member
VIP
@anty

I think there is an error in your calculations. VolAvg2 is plotting total volume.

#### anty

##### New member
@anty

I think there is an error in your calculations. VolAvg2 is plotting total volume.
Thanks for pointing that out! I quickly copied and pasted it together. Hopefully it is fixed now.

Code:
``````declare on_volume;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V*(C-L)/(H-L);
def Selling = V*(H-C)/(H-L);

# Selling Volume
Plot SV = selling;
SV.setPaintingStrategy(PaintingStrategy.Histogram);
SV.SetDefaultColor(Color.Red);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);

# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
Plot BV = volume;
BV.setPaintingStrategy(PaintingStrategy.Histogram);
BV.SetDefaultColor(Color.Dark_Green);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);

input length = 26;
plot VolAvg = Average(selling, length);
plot VolAvg2 = Average(buying, length);
VolAvg.SetDefaultColor(GetColor(2));
VolAvg2.SetDefaultColor(GetColor(6));``````

#### horserider

##### Well-known member
VIP
Not sure those plots are going to help. I am betting they will not separate enough to be useful.

I hope everyone is interpreting this indicator correctly. The histogram is showing total volume in dark green and selling volume in red. So to see buying vs selling you will need to judge how high the selling bar is compared to total volume bar.

@anty Updated this same study I posted a while ago. See if it suits you.

#### avaughan323

##### New member
Hi all this volume indicator can be a good source of information for when reversals are about to happen, is there a way to code it so that an alert pops up when there is a sold green or red bar?

#This study color codes volume by amount of volume on up-tick versus amount of volume on down-tick

declare lower;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V*(C-L)/(H-L);
def Selling = V*(H-C)/(H-L);

# Selling Volume
Plot SV = selling;
SV.setPaintingStrategy(PaintingStrategy.Histogram);
SV.SetDefaultColor(Color.Red);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);

# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
Plot BV = volume;
BV.setPaintingStrategy(PaintingStrategy.Histogram);
BV.SetDefaultColor(Color.Dark_Green);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);

#Inputs
input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;

#Volume Data
def volLast30DayAvg = (volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY")) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume) / 30;
def curVolume = volume;

# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

#### MerryDay

Staff member
Staff
VIP
Hi all this volume indicator can be a good source of information for when reversals are about to happen, is there a way to code it so that an alert pops up when there is a sold green or red bar?

#This study color codes volume by amount of volume on up-tick versus amount of volume on down-tick

declare lower;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V*(C-L)/(H-L);
def Selling = V*(H-C)/(H-L);

# Selling Volume
Plot SV = selling;
SV.setPaintingStrategy(PaintingStrategy.Histogram);
SV.SetDefaultColor(Color.Red);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);

# Plot BV = Buying;
# Note that Selling + Buying Volume = Volume.
Plot BV = volume;
BV.setPaintingStrategy(PaintingStrategy.Histogram);
BV.SetDefaultColor(Color.Dark_Green);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);

#Inputs
input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;

#Volume Data
def volLast30DayAvg = (volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY") + volume(period = "DAY")) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume + volume) / 30;
def curVolume = volume;

# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY)); ## 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
• Add-ons and resources
• 1 full year of unlimited support

### Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.