Jman Buy And Sell Volume Pressure For ThinkOrSwim

Jman831

Member
First, I'll start by saying I think someone else has posted a similar base indicator for the indicators I'm about to post here, but I didn't look into the details of their calculations.

I first started by creating an indicator that essentially separates buy volume pressure from sell volume pressure. The calculation is as follows:

Buy Volume Pressure = ((high - open) + (close - low)) / 2 / (high - low) * volume
Sell Volume Pressure = ((low - open) + (close - high)) / 2 / (high - low) * volume

Edit:
Below, I did my best to draw up a visual description using paint 3D of how my calculations of "Buying And Selling Volume Pressure" work. Also, I made the realization that I forgot to include "/ (high - low)" before "* volume" in the visual descriptions. Please forgive me for that for now until I update the image.

Buying-And-Selling-Volume-Pressure.png


The Buy Volume Pressure is always a positive number while the Sell Volume Pressure is always a negative number. I simply call this indicator "Buy And Sell Volume Pressure" since it outputs a percentage of the volume as "Buying" or "Selling" Pressure. It also includes labels for the total volume, total buy volume pressure, and total sell volume pressure. Here's the code for the Buy And Sell Volume Pressure indicator:

Edit: Because someone asked for the percentages of buying and selling volume pressure for another indicator included in this thread, I've decided to include labels for that in this indicator as well (the code below has been updated):
Code:
declare lower;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolper = buyvol / volume() * 100;
def sellvolper = absValue(sellvol) / volume() * 100;

plot Zero = 0;
plot BuyVolume = buyvol;
plot SellVolume = sellvol;

BuyVolume.setPaintingStrategy(paintingStrategy.HISTOGRAM);
BuyVolume.setDefaultColor(color.GREEN);
SellVolume.setPaintingStrategy(paintingStrategy.HISTOGRAM);
SellVolume.setDefaultColor(color.RED);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);
addLabel(yes, "BVP%: " + buyvolper, color.GREEN);
addLabel(yes, "SVP%: " + sellvolper, color.RED);

The next indicator I created is a two average indicator, an average for buy volume pressure and an average for sell volume pressure. The average types and lengths are adjustable. In this case, I used the absolute value rather than the negative number output of the sell volume pressure for the sell volume pressure average. When the buy volume pressure average crosses above the sell volume pressure average it indicates that buy volume pressure is increasing at a faster rate than sell volume pressure and vice versa, or you could say if the buy volume pressure average crosses below the sell volume pressure average buy volume pressure is decreasing at a faster rate than sell volume pressure and vice versa. Here's the code for the Buy And Sell Volume Pressure Averages indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);

plot BuyVolumeAverage = buyvolavg;
plot SellVolumeAverage = sellvolavg;

BuyVolumeAverage.setDefaultColor(color.GREEN);
SellVolumeAverage.setDefaultColor(color.RED);

Last but certainly not least, I came up with a Buy And Sell Volume Pressure Average Convergence Divergence (BSVPACD) indicator. This indicator works and looks very similar to the MACD (Moving Average Convergence Divergence) indicator, however it is based on the Buy And Sell Volume Pressure Averages, can give slightly earlier signals than the MACD indicator, and divergences are more pronounced than on the MACD indicator (I honestly don't know if this has to do with the particular default settings I picked for it). What this indicator does is it calculates the difference between the Buy Volume Pressure Average and the Sell Volume Pressure Average, plots that difference, then plots an average of the difference between the two averages (the signal line), and finally plots the difference between the difference of the Buy Volume Pressure and Sell Volume Pressure Averages and the signal line as a histogram just like MACD. The average types and lengths are all adjustable. I've also included an option that exponentially smooths the difference between the Buy And Sell Volume Pressure Averages that's toggled on by default due to the fact that the change in the difference tends to be somewhat erratic. You can also change the smoothing factor which is set to 3 by default. Here's the code for the BSVPACD indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;
input ExponentialSmoothing = yes;
input SmoothingFactor = 3;
input SignalType = averageType.EXPONENTIAL;
input SignalLength = 9;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);
def diff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(buyvolavg - sellvolavg, SmoothingFactor), SmoothingFactor), SmoothingFactor) else buyvolavg - sellvolavg;
def sigline = MovingAverage(SignalType, diff, SignalLength);
def hist = diff - sigline;

plot BSVACD = diff;
plot SignalLine = sigline;
plot Zero = 0;
plot Histogram = hist;

Histogram.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Histogram.assignValueColor(if hist > 0 and hist > hist[1] then color.GREEN else if hist > 0 and hist < hist[1] then color.DARK_GREEN else if hist < 0 and hist < hist[1] then color.RED else color.DARK_RED);

A screenshot of the indicators below a price chart of the SPY (from top to bottom, Buy And Sell Volume Pressure, Buy And Sell Volume Pressure Averages, and BSVPACD):
Buy-And-Sell-Volume-Indicators.png


A screenshot of the BSVPACD compared to the MACD (MACD up top, BSVPACD on bottom):
BSVACD-vs-MACD.png


Happy Trading!
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

First, I'll start by saying I think someone else has posted a similar base indicator for the indicators I'm about to post here, but I didn't look into the details of their calculations.

I first started by creating an indicator that essentially separates buy volume from sell volume. The calculation is as follows:

Buy Volume = ((high - open) + (close - low)) / 2 / (high - low) * volume
Sell Volume = ((low - open) + (close - high)) / 2 / (high - low) * volume


The Buy Volume is always a positive number while the Sell Volume is always a negative number. I simply call this indicator "Buy And Sell Volume" since it outputs the raw volume numbers. It also includes labels for the total volume, total buy volume, and total sell volume. Here's the code for the Buy And Sell Volume indicator:
Code:
declare lower;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);

plot Zero = 0;
plot BuyVolume = buyvol;
plot SellVolume = sellvol;

BuyVolume.setPaintingStrategy(paintingStrategy.HISTOGRAM);
BuyVolume.setDefaultColor(color.GREEN);
SellVolume.setPaintingStrategy(paintingStrategy.HISTOGRAM);
SellVolume.setDefaultColor(color.RED);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

The next indicator I created is a two average indicator, an average for buy volume and an average for sell volume. The average types and lengths are adjustable. In this case, I used the absolute value rather than the negative number output of the sell volume for the sell volume average. When the buy volume average crosses above the sell volume average it indicates that buy volume is increasing at a faster rate than sell volume and vice versa, or you could say if the buy volume average crosses below the sell volume average buy volume is decreasing at a faster rate than sell volume and vice versa. Here's the code for the Buy And Sell Volume Averages indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);

plot BuyVolumeAverage = buyvolavg;
plot SellVolumeAverage = sellvolavg;

BuyVolumeAverage.setDefaultColor(color.GREEN);
SellVolumeAverage.setDefaultColor(color.RED);

Last but certainly not least, I came up with a Buy And Sell Volume Average Convergence Divergence (BSVACD) indicator. This indicator works and looks very similar to the MACD (Moving Average Convergence Divergence) indicator, however it is based on the Buy And Sell Volume Averages, can give slightly earlier signals than the MACD indicator, and divergences are more pronounced than on the MACD indicator (I honestly don't know if this has to do with the particular default settings I picked for it). What this indicator does is it calculates the difference between the Buy Volume Average and the Sell Volume Average, plots that difference, then plots an average of the difference between the two averages (the signal line), and finally plots the difference between the difference of the Buy Volume and Sell Volume Averages and the signal line as a histogram just like MACD. The average types and lengths are all adjustable. I've also included an option that exponentially smooths the difference between the Buy And Sell Volume Averages that's toggled on by default due to the fact that the change in the difference tends to be somewhat erratic. You can also change the smoothing factor which is set to 3 by default. Here's the code for the BSVACD indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;
input ExponentialSmoothing = yes;
input SmoothingFactor = 3;
input SignalType = averageType.EXPONENTIAL;
input SignalLength = 9;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);
def diff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(buyvolavg - sellvolavg, SmoothingFactor), SmoothingFactor), SmoothingFactor) else buyvolavg - sellvolavg;
def sigline = MovingAverage(SignalType, diff, SignalLength);
def hist = diff - sigline;

plot BSVACD = diff;
plot SignalLine = sigline;
plot Zero = 0;
plot Histogram = hist;

Histogram.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Histogram.assignValueColor(if hist > 0 and hist > hist[1] then color.GREEN else if hist > 0 and hist < hist[1] then color.DARK_GREEN else if hist < 0 and hist < hist[1] then color.RED else color.DARK_RED);

A screenshot of the indicators below a price chart of the SPY (from top to bottom, Buy And Sell Volume, Buy And Sell Volume Averages, and BSVACD):
Buy-And-Sell-Volume-Indicators.png


A screenshot of the BSVACD compared to the MACD (MACD up top, BSVACD on bottom):
BSVACD-vs-MACD.png


Happy Trading!
@Jman831

I want to see if you add add buy sell volume to the indicator below Thank you!

declare lower;
input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));
 
The next indicator I created is a two average indicator, an average for buy volume and an average for sell volume. The average types and lengths are adjustable. In this case, I used the absolute value rather than the negative number output of the sell volume for the sell volume average. When the buy volume average crosses above the sell volume average it indicates that buy volume is increasing at a faster rate than sell volume and vice versa, or you could say if the buy volume average crosses below the sell volume average buy volume is decreasing at a faster rate than sell volume and vice versa. Here's the code for the Buy And Sell Volume Averages indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);

plot BuyVolumeAverage = buyvolavg;
plot SellVolumeAverage = sellvolavg;

BuyVolumeAverage.setDefaultColor(color.GREEN);
SellVolumeAverage.setDefaultColor(color.RED);

I think number 2 is really interesting and i´ve always had this idea of an indicator showing the rate of buy & sell volume instead of just the difference. I was wondering if you can add some labels to the study as well and color code the labels depending on the rate? Something like this, when the buy vol crosses the average, paint the label green and when sell volume crosses average, paint the label red. Audio alerts for the crosses would also be useful.

Thank you for these (y)
 
@Jman831

I want to see if you add add buy sell volume to the indicator below Thank you!

declare lower;
input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));
I'll have to check out this indicator and see what you mean first but I'll give it a shot when I have a chance.
 
I think number 2 is really interesting and i´ve always had this idea of an indicator showing the rate of buy & sell volume instead of just the difference. I was wondering if you can add some labels to the study as well and color code the labels depending on the rate? Something like this, when the buy vol crosses the average, paint the label green and when sell volume crosses average, paint the label red. Audio alerts for the crosses would also be useful.

Thank you for these (y)
That should be simple enough. I don't know how to do alerts but I can add labels no problem. What would you like the label to read? I should warn though that as a candle is in process it may toggle back and forth between colors until the candle is complete if the averages are crossing because the percentage of each type of volume is determined by the structure of the candle.
 
That should be simple enough. I don't know how to do alerts but I can add labels no problem. What would you like the label to read? I should warn though that as a candle is in process it may toggle back and forth between colors until the candle is complete if the averages are crossing because the percentage of each type of volume is determined by the structure of the candle.
The label can simply read "bullish cross" and "bearish cross". I found this on the TOS learning center website, called a displacer and not sure if this will work with your study but if there´s a way to let one or two bars pass beyond the cross, that would perhaps eliminate the toggling back and forth between the painting of labels and also the alerts.
 
The label can simply read "bullish cross" and "bearish cross". I found this on the TOS learning center website, called a displacer and not sure if this will work with your study but if there´s a way to let one or two bars pass beyond the cross, that would perhaps eliminate the toggling back and forth between the painting of labels and also the alerts.
I could add a line to the study to displace it so it reads the last bar instead of the current bar but that would result in a delay of signals. I think the displacer essentially does the same thing.
 
I could add a line to the study to displace it so it reads the last bar instead of the current bar but that would result in a delay of signals. I think the displacer essentially does the same thing.
Yes, that would be good. The delay isn´t that important to me.
 
Yes, that would be good. The delay isn´t that important to me.
So, unfortunately all displacing it does is move the plot over by the number of bars you set. It doesn't change the value to the value of the previous bar for some reason.

That being said, add these two lines to the very bottom of the code to get your bullish and bearish crossover labels.
Code:
addLabel(if buyvolavg crosses above sellvolavg then yes else no, "Bullish Crossover", color.GREEN);
addLabel(if buyvolavg crosses below sellvolavg then yes else no, "Bearish Crossover", color.RED);

It's important to note these lines of code will not show a label at all unless a crossover occurs. If you want a constant label that says bullish or bearish depending on which line is above the other, simply replace "crosses above" with ">" and "crosses below" with "<".
 
Last edited:
@Jman831

I want to see if you add add buy sell volume to the indicator below Thank you!

declare lower;
input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

Ahmar, I'm not quite sure what you want me to do with the code. I like your indicator though, by the way. The best I could do without cluttering up the plot is add labels like the ones on the Buy And Sell Volume indicator. I've added those lines of code for you:

Code:
declare lower;
input smoothingLength = 3;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

If this isn't what you're looking for, let me know what it is you are looking for.
 
Mod Note:
The indicator in the above post is another great contribution from @Jman831.
We have
several of these types of indicators on the forum.

It is highly recommended that they be part of every chart setup.


CAVEAT:
Members will sometimes mistake these indicators as defining Buyers and Sellers.
Buyers and Sellers information is NOT available from the ToS data feeds.
These scripts are representative of the upticks and downticks of PRICE on the trading chart not volume.

These types of indicators describe buying and selling pressure by using a candlestick pattern.
Volume Pressure identifies the size of the candle when aggregated against volume it is used to define momentum not actual buyers and sellers.

You can't apply the momentum percentage to the volume number and declare that to be the number of buyers and sellers.
nOnSBvp.png
uwFHET6.png

Buying / Selling Volume Pre
Yes, thank you for clarifying. I probably should have mentioned it's not really a "true" representation of buying and selling volume as that data isn't available. Technically, for every buyer there is a seller or for every "share bought" there is a "share sold". It essentially takes a percentage of the total volume and labels it "buy" or "sell volume" based on the structure of the candle/bar. If you actually watch it in progress both the "buy" and "sell volume" fluctuate until the candle is completed. For example, if the candle's close - open is equal to the candle's high - low, it would label 100% of the volume as "buy volume" since there are no wicks and the candle "only" moved up in price. Obviously the candle didn't "only" move up in price, there were fluctuations up and down on the way up (both buying and selling). It doesn't account for these up and down movements, the movements up and down simply shift the percentage of the total volume being labeled buy vs sell "volume". I apologize for the confusion.
 

Attachments

  • nOnSBvp.png
    nOnSBvp.png
    18.9 KB · Views: 1,373
I apologize for the confusion.

No apologies necessary. You used the standard verbiage for these types of indicators.
History has shown that the 'standard verbiage' can be confusing for members who have not been exposed to these types of indicators previously.
Therefore, all Buy Sell Pressure Indicators are given the above 'standard explanation'.

Actually your definition is clearer and more concise than what we have been using. The Forum blurb will be updated.
Thank you for sharing this.
 
Ahmar, I'm not quite sure what you want me to do with the code. I like your indicator though, by the way. The best I could do without cluttering up the plot is add labels like the ones on the Buy And Sell Volume indicator. I've added those lines of code for you:

Code:
declare lower;
input smoothingLength = 3;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

If this isn't what you're looking for, let me know what it is you are looking for.
Thank you for adding the labels!
If you can try to make that on the upper price chart.
See that indicator is pretty simple if it's below the zero line it's in the downtrend once it gets above the zero line it's in the uptrend.
 
Last edited by a moderator:
Okay, so I finally figured it out after looking at another indicator that paints bars. I experimented a little with it but found I could only use 4 colors effectively. I chose the colors I did so that you can still tell if the close is above or below the open.

Green = Trend Up (diff is above 0), Close Above Open
Dark Red = Trend Up, Close Below Open
Red = Trend Down (diff is below 0), Close Below Open
Dark Green = Trend Down, Close Above Open

Here's the code:

Code:
input smoothingLength = 3;
input paintBars = yes;


def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;
def Avg = Average(diff, smoothingLength);

plot TUBU = close > open and diff > 0;
plot TUBD = close < open and diff > 0;
plot TDBD = close < open and diff < 0;
plot TDBU = close > open and diff < 0;

TUBU.hide();
TUBD.hide();
TDBD.hide();
TDBU.hide();

DefineGlobalColor("TUBU", Color.GREEN);
DefineGlobalColor("TUBD", Color.DARK_RED);
DefineGlobalColor("TDBD", Color.RED);
DefineGlobalColor("TDBU", Color.DARK_GREEN);

AssignPriceColor(if !paintBars then Color.CURRENT
else if TUBU then GlobalColor("TUBU")
else if TUBD then GlobalColor("TUBD")
else if TDBD then GlobalColor("TDBD")
else if TDBU then GlobalColor("TDBU")
else Color.Current);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

Hopefully this is satisfying enough, it's the best I could do for now.
 
Last edited by a moderator:
Okay, so I finally figured it out after looking at another indicator that paints bars. I experimented a little with it but found I could only use 4 colors effectively. I chose the colors I did so that you can still tell if the close is above or below the open.

Green = Trend Up (diff is above 0), Close Above Open
Dark Red = Trend Up, Close Below Open
Red = Trend Down (diff is below 0), Close Below Open
Dark Green = Trend Down, Close Above Open

Here's the code:

Code:
input smoothingLength = 3;
input paintBars = yes;


def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;
def Avg = Average(diff, smoothingLength);

plot TUBU = close > open and diff > 0;
plot TUBD = close < open and diff > 0;
plot TDBD = close < open and diff < 0;
plot TDBU = close > open and diff < 0;

TUBU.hide();
TUBD.hide();
TDBD.hide();
TDBU.hide();

DefineGlobalColor("TUBU", Color.GREEN);
DefineGlobalColor("TUBD", Color.DARK_RED);
DefineGlobalColor("TDBD", Color.RED);
DefineGlobalColor("TDBU", Color.DARK_GREEN);

AssignPriceColor(if !paintBars then Color.CURRENT
else if TUBU then GlobalColor("TUBU")
else if TUBD then GlobalColor("TUBD")
else if TDBD then GlobalColor("TDBD")
else if TDBU then GlobalColor("TDBU")
else Color.Current);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

Hopefully this is satisfying enough, it's the best I could do for now.
InshAllah I will look at it tomorrow, if you come up with other indicators please let me know thank you!
 
Okay, so I finally figured it out after looking at another indicator that paints bars. I experimented a little with it but found I could only use 4 colors effectively. I chose the colors I did so that you can still tell if the close is above or below the open.

Green = Trend Up (diff is above 0), Close Above Open
Dark Red = Trend Up, Close Below Open
Red = Trend Down (diff is below 0), Close Below Open
Dark Green = Trend Down, Close Above Open

Here's the code:

Code:
input smoothingLength = 3;
input paintBars = yes;


def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;
def Avg = Average(diff, smoothingLength);

plot TUBU = close > open and diff > 0;
plot TUBD = close < open and diff > 0;
plot TDBD = close < open and diff < 0;
plot TDBU = close > open and diff < 0;

TUBU.hide();
TUBD.hide();
TDBD.hide();
TDBU.hide();

DefineGlobalColor("TUBU", Color.GREEN);
DefineGlobalColor("TUBD", Color.DARK_RED);
DefineGlobalColor("TDBD", Color.RED);
DefineGlobalColor("TDBU", Color.DARK_GREEN);

AssignPriceColor(if !paintBars then Color.CURRENT
else if TUBU then GlobalColor("TUBU")
else if TUBD then GlobalColor("TUBD")
else if TDBD then GlobalColor("TDBD")
else if TDBU then GlobalColor("TDBU")
else Color.Current);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

Hopefully this is satisfying enough, it's the best I could do for now.
looks great to me! I tried to insert pic. but cant do it maybe you can. can you look at the monthly chart for /ES and /NQ and see how the indicator shows you to exit long. also if you can post it that be great!
 
Last edited:
looks great to me! I tried to insert pic. but cant do it maybe you can. can you look at the monthly chart for /ES and /NQ and see how the indicator shows you to exit long. also if you can post it that be great!
I mean no indicator is going to tell you exactly when to get in or out but a rule of thumb would be to get in on a dark green bar or if it goes from bright red on one bar to bright green on the next bar and get out on a dark red bar or if it goes from bright green on one bar to bright red on the next bar. I would suggest using an average or two along with your indicator though. That's my two cents and just as a disclosure, this isn't financial advice.
 
Okay, so I finally figured it out after looking at another indicator that paints bars. I experimented a little with it but found I could only use 4 colors effectively. I chose the colors I did so that you can still tell if the close is above or below the open.

Green = Trend Up (diff is above 0), Close Above Open
Dark Red = Trend Up, Close Below Open
Red = Trend Down (diff is below 0), Close Below Open
Dark Green = Trend Down, Close Above Open

Here's the code:

Code:
input smoothingLength = 3;
input paintBars = yes;


def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;
def Avg = Average(diff, smoothingLength);

plot TUBU = close > open and diff > 0;
plot TUBD = close < open and diff > 0;
plot TDBD = close < open and diff < 0;
plot TDBU = close > open and diff < 0;

TUBU.hide();
TUBD.hide();
TDBD.hide();
TDBU.hide();

DefineGlobalColor("TUBU", Color.GREEN);
DefineGlobalColor("TUBD", Color.DARK_RED);
DefineGlobalColor("TDBD", Color.RED);
DefineGlobalColor("TDBU", Color.DARK_GREEN);

AssignPriceColor(if !paintBars then Color.CURRENT
else if TUBU then GlobalColor("TUBU")
else if TUBD then GlobalColor("TUBD")
else if TDBD then GlobalColor("TDBD")
else if TDBU then GlobalColor("TDBU")
else Color.Current);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

Hopefully this is satisfying enough, it's the best I could do for now.
@Jman831
Ahmar, I'm not quite sure what you want me to do with the code. I like your indicator though, by the way. The best I could do without cluttering up the plot is add labels like the ones on the Buy And Sell Volume indicator. I've added those lines of code for you:

Code:
declare lower;
input smoothingLength = 3;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);

If this isn't what you're looking for, let me know what it is you are looking for.
@Jman831 Can you add buy/sell percentage to this, for a quick glance of what percentage are buying or selling?
 
@Jman831

@Jman831 Can you add buy/sell percentage to this, for a quick glance of what percentage are buying or selling?
Again, this is not a representation of how many people are buying and selling, for every buyer there is a seller. When you look at total volume, that's how many shares were bought and sold as you can't have a buyer without a seller. But, to answer your question, I've added what you're looking for which is a percentage of buying pressure vs a percentage of selling pressure. I've added the labels for that in the code below:

Code:
input smoothingLength = 3;
input paintBars = yes;


def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;
def Avg = Average(diff, smoothingLength);
def buyvolper = buyvol / volume() * 100;
def sellvolper = absValue(sellvol) / volume() * 100;

plot TUBU = close > open and diff > 0;
plot TUBD = close < open and diff > 0;
plot TDBD = close < open and diff < 0;
plot TDBU = close > open and diff < 0;

TUBU.hide();
TUBD.hide();
TDBD.hide();
TDBU.hide();

DefineGlobalColor("TUBU", Color.GREEN);
DefineGlobalColor("TUBD", Color.DARK_RED);
DefineGlobalColor("TDBD", Color.RED);
DefineGlobalColor("TDBU", Color.DARK_GREEN);

AssignPriceColor(if !paintBars then Color.CURRENT
else if TUBU then GlobalColor("TUBU")
else if TUBD then GlobalColor("TUBD")
else if TDBD then GlobalColor("TDBD")
else if TDBU then GlobalColor("TDBU")
else Color.Current);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);
addLabel(yes, "BVP%: " + buyvolper, color.GREEN);
addLabel(yes, "SVP%: " + sellvolper, color.RED);

BVP% = Buying Volume Pressure Percentage.
SVP% = Selling Volume Pressure Percentage.
Note that these will fluctuate when a candle is in progress as the percentage changes based on the candle structure.
 
First, I'll start by saying I think someone else has posted a similar base indicator for the indicators I'm about to post here, but I didn't look into the details of their calculations.

I first started by creating an indicator that essentially separates buy volume pressure from sell volume pressure. The calculation is as follows:

Buy Volume Pressure = ((high - open) + (close - low)) / 2 / (high - low) * volume
Sell Volume Pressure = ((low - open) + (close - high)) / 2 / (high - low) * volume

Edit:
Below, I did my best to draw up a visual description using paint 3D of how my calculations of "Buying And Selling Volume Pressure" work. Also, I made the realization that I forgot to include "/ (high - low)" before "* volume" in the visual descriptions. Please forgive me for that for now until I update the image.

View attachment 3238

The Buy Volume Pressure is always a positive number while the Sell Volume Pressure is always a negative number. I simply call this indicator "Buy And Sell Volume Pressure" since it outputs a percentage of the volume as "Buying" or "Selling" Pressure. It also includes labels for the total volume, total buy volume pressure, and total sell volume pressure. Here's the code for the Buy And Sell Volume Pressure indicator:

Edit: Because someone asked for the percentages of buying and selling volume pressure for another indicator included in this thread, I've decided to include labels for that in this indicator as well (the code below has been updated):
Code:
declare lower;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolper = buyvol / volume() * 100;
def sellvolper = absValue(sellvol) / volume() * 100;

plot Zero = 0;
plot BuyVolume = buyvol;
plot SellVolume = sellvol;

BuyVolume.setPaintingStrategy(paintingStrategy.HISTOGRAM);
BuyVolume.setDefaultColor(color.GREEN);
SellVolume.setPaintingStrategy(paintingStrategy.HISTOGRAM);
SellVolume.setDefaultColor(color.RED);
addLabel(yes, "Total Volume: " + volume(), color.LIGHT_GRAY);
addLabel(yes, "Buy Volume: " + buyvol, color.GREEN);
addLabel(yes, "Sell Volume: " + absValue(sellvol), color.RED);
addLabel(yes, "BVP%: " + buyvolper, color.GREEN);
addLabel(yes, "SVP%: " + sellvolper, color.RED);

The next indicator I created is a two average indicator, an average for buy volume pressure and an average for sell volume pressure. The average types and lengths are adjustable. In this case, I used the absolute value rather than the negative number output of the sell volume pressure for the sell volume pressure average. When the buy volume pressure average crosses above the sell volume pressure average it indicates that buy volume pressure is increasing at a faster rate than sell volume pressure and vice versa, or you could say if the buy volume pressure average crosses below the sell volume pressure average buy volume pressure is decreasing at a faster rate than sell volume pressure and vice versa. Here's the code for the Buy And Sell Volume Pressure Averages indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);

plot BuyVolumeAverage = buyvolavg;
plot SellVolumeAverage = sellvolavg;

BuyVolumeAverage.setDefaultColor(color.GREEN);
SellVolumeAverage.setDefaultColor(color.RED);

Last but certainly not least, I came up with a Buy And Sell Volume Pressure Average Convergence Divergence (BSVPACD) indicator. This indicator works and looks very similar to the MACD (Moving Average Convergence Divergence) indicator, however it is based on the Buy And Sell Volume Pressure Averages, can give slightly earlier signals than the MACD indicator, and divergences are more pronounced than on the MACD indicator (I honestly don't know if this has to do with the particular default settings I picked for it). What this indicator does is it calculates the difference between the Buy Volume Pressure Average and the Sell Volume Pressure Average, plots that difference, then plots an average of the difference between the two averages (the signal line), and finally plots the difference between the difference of the Buy Volume Pressure and Sell Volume Pressure Averages and the signal line as a histogram just like MACD. The average types and lengths are all adjustable. I've also included an option that exponentially smooths the difference between the Buy And Sell Volume Pressure Averages that's toggled on by default due to the fact that the change in the difference tends to be somewhat erratic. You can also change the smoothing factor which is set to 3 by default. Here's the code for the BSVPACD indicator:
Code:
declare lower;

input AvgTypes = averageType.EXPONENTIAL;
input BuyVolumeAvgLength = 18;
input SellVolumeAvgLength = 18;
input ExponentialSmoothing = yes;
input SmoothingFactor = 3;
input SignalType = averageType.EXPONENTIAL;
input SignalLength = 9;

def buyvol = Round(((high - open) + (close - low)) / 2 / (high - low) * volume(), 0);
def sellvol = Round(((low - open) + (close - high)) / 2 / (high - low) * volume(), 0);
def buyvolavg = MovingAverage(AvgTypes, buyvol, BuyVolumeAvgLength);
def sellvolavg = MovingAverage(AvgTypes, absValue(sellvol), SellVolumeAvgLength);
def diff = if ExponentialSmoothing == yes then ExpAverage(ExpAverage(ExpAverage(buyvolavg - sellvolavg, SmoothingFactor), SmoothingFactor), SmoothingFactor) else buyvolavg - sellvolavg;
def sigline = MovingAverage(SignalType, diff, SignalLength);
def hist = diff - sigline;

plot BSVACD = diff;
plot SignalLine = sigline;
plot Zero = 0;
plot Histogram = hist;

Histogram.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Histogram.assignValueColor(if hist > 0 and hist > hist[1] then color.GREEN else if hist > 0 and hist < hist[1] then color.DARK_GREEN else if hist < 0 and hist < hist[1] then color.RED else color.DARK_RED);

A screenshot of the indicators below a price chart of the SPY (from top to bottom, Buy And Sell Volume Pressure, Buy And Sell Volume Pressure Averages, and BSVPACD):
View attachment 3239

A screenshot of the BSVPACD compared to the MACD (MACD up top, BSVPACD on bottom):
View attachment 3240

Happy Trading!
Is there a way to shade the chart region when you have agreement of the bottom two indicators. Shade green when buy average (green) is above red on middle indicator AND blue average is on top on the bottom indicator.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
495 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • 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.
Back
Top