• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Buy and Sell Volume Pressure Indicator for ThinkorSwim

Paul Bunion

New member
Here is a volume indicator that I like to use in everyday trading. it really helps with identifying who is in control.

Code:
# Original author: Unknown
# Modified by 7of9

declare lower;

#Inputs

input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf30BarAvg = yes;
input ShowSellVolumePercent = yes;

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 SellVol = selling;
SellVol.setPaintingStrategy(PaintingStrategy.Histogram);
SellVol.SetDefaultColor(Color.Red);
SellVol.HideTitle();
SellVol.HideBubble();
SellVol.SetLineWeight(5);

# Total Volume

Plot BuyVol = volume;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.Dark_Green);
BuyVol.HideTitle();
BuyVol.HideBubble();
BuyVol.SetLineWeight(5);

#Volume Data

def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;
def percentOf30Bar = Round((curVolume / avg30Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);

# Labels

AddLabel(Show30DayAvg, "Avg 30 Days: " + 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));

AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );

AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);

AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if percentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

AddLabel(ShowPercentOf30BarAvg, PercentOf30Bar + "%", (if PercentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.WHITE) );

AddLabel(ShowSellVolumePercent, "Cur Bar Sell %: " + SellVolPercent, (if SellVolPercent > 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.ORANGE));

input length = 50;

plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.color("Up") else if close < close[1] then Vol.color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));

Video Tutorial


Here is another volume pressure created by Mobius, "this is a pretty popular study and not on the TOS included studies."

Code:
# Volume Pressure
# Mobius
# Mobius at MyTrade
# V01.02.2010

declare lower;

input nVP = 21;
input VPdelta = 21;

  plot VP = Sum(((close - open) / (high - low)) * volume, nVP);
  def VPup = Average(VP, VPdelta)  >  Average(VP, VPdelta)[1];
  def VPdn = Average(VP, VPdelta)  <  Average(VP, VPdelta)[1];;
          VP.SetPaintingStrategy(PaintingStrategy.Histogram);
          VP.SetLineWeight(3);
          VP.AssignValueColor(if VP < 0 and VPup
                                            then Color.Light_GREEN
                                            else if VP > 0 and VPup
                                            then Color.Green
                                            else if VP > 0 and VPdn
                                            then Color.Yellow
                                            else  Color.RED);

  plot zerobase = If isNaN(volume) then Double.NaN else 0;
          zerobase.SetPaintingStrategy(PaintingStrategy.Line);
          zerobase.SetLineWeight(1);
          zerobase.AssignValueColor(if IsAscending(VP, nVP)
                                                        then Color.GREEN
                                                        else  Color.RED);

  plot TrendLine = Inertia(VP, 55);
          TrendLine.SetLineWeight(1);
          TrendLine.AssignValueColor(if Sum(TrendLine > TrendLine[1], 3) == 3
                                                          then Color.Blue
                                                          else  Color.White);

It works on all time frames.
 
Last edited by a moderator:

Shinthus

Member
2019 Donor
Thanks for sharing! I'm trying to figure out a way to numerically show the % of volume pressure and have color change with direction.
 

devnoir

New member
2019 Donor
Can we take this down? Or at least modify the comment up top so it doesn't credit 7of9. This is just a slightly modified study thats been available on the web for a while. 7of9 is a known code thief.

The original author is unknown.
 
Last edited by a moderator:

bsizzle101

New member
Can anyone help me with this Volume Stat Indicator I found? I would like it to show me the percentage of the current bar against the 30 bar avg.
ie: if the avg 30 bar is 6000 and the current bar is 1500 it would show 25% ect..ect..

Code:
declare lower;

#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")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 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));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));
 

astrokjackk1

New member
Hi everyone, I am no coder and I don’t really know how to set up a decent scan on tos so I want to ask the community to see if I can get some help.
the scan needs to include the following:
AVG daily volume (preferably of the past 180 days)
- this will let us know how much volume is traded on an average basis.
Volume % (how much volume has been traded in the premarket)
- this will let us know how much volume has been accumulated in the premarket in % correlation to average daily volume
Gap % (this will allow us to determine if we should expect volatility intraday)
- high percentage gaps usually coincide with high volatility intraday

thank you to anyone in advance who helps out.
 
Last edited:

Regalo

New member
@BenTen (or whoever can help me ) , can you help me by making a small modification to the script?

I'm trying to get it to show me the histogram as follows: https://ibb.co/qyBLsHb
(i cant insert images, i got this: "Something went grong. Please try again or contact the administrator.")


The logic would be:

If the current candle is larger than the previous one and "Buying" volume (according to the code published in this post) is greater than 60% of the total volume, then paint the candle green, otherwise it's gray.

The same for the Red candle.
If the current candle is Larger than the previous one and "Selling" volume (according to the code published in this post) is greater than 60% of the total volume, then paint the candle red, otherwise it's grey.

Thanks you!
 

horserider

Well-known member
VIP
@Regalo First understand in the study posted at top of the thread what is being defined as "Buying" volume. It is also plotting volume twice.
 

spm009

Member
I have a slight issue with this indicator, which is otherwise great. Basically this indicator overlaps the standard volume indicator. For some reason it seems to have an offset where the custom indicator starts at 25 instead of zero, so you see a little bit of the standard volume indicator below/behind it. How can I fix this?

Screen-Shot-2020-03-10-at-11-15-46-PM.png
 

BenTen

Administrative
Staff
VIP
@spm009 Drag the custom indicator to the lower study section. Don’t overlap them. If you need to remove the default volume section, then go to Settings > Equities > Disable Volume.
 

solaris

Member
I use a Volume Label on my chart that tells me how much Volume is on the Buy versus the sell side. For instance in order for me see how much volume the equity has i have to add up the buy and sell side to get a running total. I was wondering if there's a better way to use this code. Any help you could provide would be greatly appreciated.

Code:
#declare lower;
input overBought = 400;
input OverSold = 200;
input period = AggregationPeriod.Day;

def O = open(period = period);
def H = high(period = period);
def C = close(period = period);
def L = low(period = period);
def V = volume(period = period);



# Selling Volume
def SV = -V * (H - C) / (H - L);



def O1 = open(period = period);
def H1 = high(period = period);
def C1 = close(period = period);
def L1 = low(period = period);
def V1 = volume(period = period);

# Buying Volume
def BV = V1 * (C1 - L1) / (H1 - L1);

plot VolAvg = Average(volume(period = period));


VolAvg.SetPaintingStrategy(PaintingStrategy.LINE);
VolAvg.SetLineWeight(2);
VolAvg.DefineColor("Up", Color.UPTICK);
VolAvg.DefineColor("Down", Color.DOWNTICK);
VolAvg.AssignValueColor(if close > close[1] then VolAvg.Color("Up") else if close < close[1] then VolAvg.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
plot OB = overBought;
plot OS = OverSold;
AddLabel(yes, "DailyBuyVolume " + BV, color.green);
AddLabel(yes, "DailySellVolume " + SV, Color.white);


#AddLabel(yes, "DailyVolume " + BV, if BV > SV then #Color.green else
#Color.GRAY);
#AddLabel(yes, "DailySellVolume " + SV, if SV < BV #then Color.White else
#Color.GRAY);


#lash
 
Last edited by a moderator:

mckenzieatix

New member
VIP
@Paul Bunion Cool I use a different version of this. I actually found it from a guy called Enigma from Enhanced Investors Discord Community. I see it updated from mine however and going to look through the new code. WATCH ME

If anyone ever gets a hold of him let me know.
 

Alex

Active member
VIP
I've been thinking if it would be possible to come up with some sort of strategy that is based on the volume pressure indicator posted here.

maybe combining a couple time frames and the confluence of buying vs selling pressure? Unfortunately I'm not much knowledgeable in coding but anyways just thought i would share the idea.
 

Similar threads

Top