JAT Buy/Sell Volume Pressure Indicator For ThinkOrSwim

Here is the modified revision to allow user to enter aggregation time frame

Code:
######################################################################################
# Script Name: Buy & Sell Volume Avg & Pressure
# Author: Denver Stair
# 2/15/2026
# Version 1.2
# Revision: Updated to allow user to select aggregation period time frame
######################################################################################

#wizard input: Deviation_Length
#wizard text: Inputs: VWAP Dev:
#wizard input: Audible_Alert
#wizard text: Inputs: Alert
#wizard input: Show_Arrows
#wizard text: Inputs: B/S Arrows

#Hint: This Study displays the approximate current candle buy, sell, and total volume, (added an input if you would like to see premarket volume as well) for current time frame.  It also plots the approximate volume values for the total volume | average volume | approx sell volume | and aprox buy volume of timeframe under cursor.  Note: If the result returns N/A the high = close or low = close and time frame is a doji.  Choose your inputs to see premarket, total volume, and day market total volume.  There are also arrow indicators based on VWAP for enter and exit points.  The volume histogram always shows the dominant value in back and lowest volume in front.

declare lower;
##########################
# Configurable Parameters
##########################
input Deviation_Length = 60;
input Deviate = 2;
input Show_Labels = yes;
input aggregationPeriod = AggregationPeriod.MIN; #hint aggregationPeriod: Set your chart timeframe here to use for study.  Default is the minute time frame
input Audible_Alert = yes;    #hint Audible_Alert: enable for audible alerts
input Show_Arrows = yes;    #hint Show_Arrows: enable for enter and exit arrows above
input UseVWAPFilter = yes;    #hint UseVWAPFilter: enable for VWAP filtering
input ShowTodaysVolume = yes;    #hint ShowTodaysVolume: enable to show todays total volume
input ShowTodaysPreMrktVolume = yes;     #hint ShowTodaysPreMrktVolume: enable to show todays premarket total volume
input startTime = 0400;    #hint startTime: pre and post market start time for 24 / 5 stocks starts at 4:00 EST
input endTime = 0930;    #hint endTime: pre-market end time is market open
input Volume_Ave_Length = 50; #hint Volume_Ave_Length: choose the number of candles to use for average volume

#####################################################################

def CurPer = aggregationPeriod;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume(GetSymbol(), CurPer) else if targetPeriod then volumeTotal[1] + volume(GetSymbol(), CurPer) else volumeTotal[1];

#####################################################################

##########################
# Volume Stats & Context
##########################
def volumeStDev = RelativeVolumeStDev(length = Deviation_Length);
def abovedev = volumeStDev >= Deviate;

def increase = volume(GetSymbol(), CurPer) > volume[1];
def decrease = volume(GetSymbol(), CurPer) < volume[1];
def devincrease = increase and abovedev;
def devdecrease = decrease and abovedev;

##########################
# Buying vs. Selling Volume
##########################

def O = open(GetSymbol(), CurPer);
def H = high(GetSymbol(), CurPer) + .000001;
def C = close(GetSymbol(), CurPer)+ .0000001;
def L = low(GetSymbol(), CurPer) - .000001;
def DayVol = volume(period = “DAY”);
def V = volume;

#def Buying = if H != L then V * (C - L) / (H - L) else 0;

def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);

#def Selling = if H != L then V * (H - C) / (H - L) else 0;

##########################
# VWAP Context Filter
##########################
def vwap = VWAP();
def aboveVWAP = close(GetSymbol(), CurPer) > vwap;
def belowVWAP = close(GetSymbol(), CurPer) < vwap;

##########################
# Volume Plots (Modification always puts the dominant color in back)
##########################

def BuyDominant  = Buying > Selling;
def SellDominant = Selling > Buying;


plot SellVolume =
    if BuyDominant then AbsValue(Ceil(Selling - .5)) else Double.NaN;
SellVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SellVolume.SetLineWeight(1);
SellVolume.SetDefaultColor(Color.RED);

plot BuyVolume =
    if BuyDominant then Floor(Buying + 0.5) else Double.NaN;
BuyVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BuyVolume.SetLineWeight(1);
BuyVolume.SetDefaultColor(Color.GREEN);

plot BuyVo1ume =
    if SellDominant then Floor(Buying + 0.5) else Double.NaN;
BuyVo1ume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BuyVo1ume.SetLineWeight(1);
BuyVo1ume.SetDefaultColor(Color.GREEN);

plot Sel1Volume =
    if SellDominant then AbsValue(Ceil(Selling - .5)) else Double.NaN;
Sel1Volume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Sel1Volume.SetLineWeight(1);
Sel1Volume.SetDefaultColor(Color.RED);

##################################### Add average volume to the study ########################################
plot TV = volume;
TV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TV.SetLineWeight(1);
TV.SetDefaultColor(Color.BLUE);
#
plot VolAvg = Floor(Average(volume, Volume_Ave_Length));
VolAvg.SetDefaultColor(GetColor(8));
TV.Hide(); # Hide total volume plot if you only want the breakdown

##########################
# Relative Strength Calculation
##########################
def buyStrength = if Average(Buying, Deviation_Length) != 0 then Buying / Average(Buying, Deviation_Length) else 0;
def sellStrength = if Average(Selling, Deviation_Length) != 0 then Selling / Average(Selling, Deviation_Length) else 0;

def buyPct = if Buying + Selling != 0 then Buying / (Buying + Selling) else 0;
def sellPct = 1 - buyPct;

##########################
# Signal Conditions
##########################
def bigBuy = devincrease and buyPct > 0.7;
def bigSell = devdecrease and sellPct > 0.7;

def trendBuy = Buying > Buying[1] and Buying[1] > Buying[2];
def trendSell = Selling > Selling[1] and Selling[1] > Selling[2];

##########################
# Alerts
##########################
Alert(bigBuy and Audible_Alert, "Heavy Buying Surging", Alert.BAR, Sound.Ding);
Alert(bigSell and Audible_Alert, "Heavy Selling Dump", Alert.BAR, Sound.Bell);

##########################
# Arrow Signals
##########################
plot BuyArrow = Show_Arrows and bigBuy and (UseVWAPFilter == no or aboveVWAP);
BuyArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuyArrow.SetDefaultColor(Color.GREEN);

plot SellArrow = Show_Arrows and bigSell and (UseVWAPFilter == no or belowVWAP);
SellArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellArrow.SetDefaultColor(Color.RED);

##########################
# Custom Labels (Your Voice)
##########################
AddLabel(Show_Labels, "Buy Vol = " + Floor(Buying + .5) +
    (if devincrease then " 🚀 Big Surge" else ""),
    if Buying > Selling then Color.GREEN else Color.LIGHT_GREEN);

AddLabel(Show_Labels, "Buy %: " + Round(buyPct * 100, 1) + "%" +
    (if buyPct > 0.7 then " | Buyers in Control" else if buyPct < 0.3 then " | Sellers Dominating" else " | Meh"),
    if buyPct > 0.7 then Color.LIGHT_GREEN else if buyPct < 0.3 then Color.RED else Color.GRAY);

AddLabel(Show_Labels, "Sell Vol = " + AbsValue(Ceil(Selling - .5)) +
    (if devdecrease then " 🔻 Major Dump" else ""),
    if Selling > Buying then Color.RED else Color.LIGHT_RED);

AddLabel(Show_Labels, "Sell %: " + Round(sellPct * 100, 1) + "%" +
    (if sellPct > 0.7 then " | Nasty Pressure" else if sellPct < 0.3 then " | Soft Sellers" else " | Mixed Bag"),
     if sellPct > 0.7 then Color.PINK else if sellPct < 0.3 then Color.GRAY else Color.LIGHT_GRAY);

AddLabel(yes, "Cur Candle Volume: " + Floor(volume), Color.LIGHT_GRAY);
AddLabel(ShowTodaysVolume, "Day Vol Today: " + DayVol, Color.LIGHT_GRAY);
AddLabel(ShowTodaysPreMrktVolume, Concat("PreMrket Vol: ", volumeTotal), Color.VIOLET);

AddLabel(Show_Labels and trendBuy, "3-Bar Buy Momentum Building 📈", Color.CYAN);
AddLabel(Show_Labels and trendSell, "3-Bar Sell Pressure Mounting 📉", Color.ORANGE);

AddLabel(Show_Labels, "VWAP: " + Round(vwap, 2) + (if aboveVWAP then " | Above VWAP" else " | Below VWAP"),
    if aboveVWAP then Color.GREEN else Color.RED);
 
Last edited:

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

Hope ya like the enhancements.

Code:
######################################################################################
# Script Name: Buy & Sell Volume Avg & Pressure
# Author: Denver Stair
# 2/24/2026
# Version 1.4
# Revision: Updated to allow user to select aggregation period time frame
######################################################################################

#wizard input: Deviation_Length
#wizard text: Inputs: VWAP Dev:
#wizard input: Audible_Alert
#wizard text: Inputs: Alert
#wizard input: Show_Arrows
#wizard text: Inputs: B/S Arrows

#Hint: This Study displays the approximate current candle buy, sell, and total volume, with trend reversal warnings for current time frame.  (added an input if you would like to see premarket volume as well).  Works with both candle typse so choose the correct candle type in the input settings under Chart Type.  Furthermore, you must select your correct candle type, candle or HEIKIN_ASHI to get the most accurate approximation for buys and sales numbers.   The indicator also plots the approximate volume values for the total trading day volume | average volume | approx sell volume | and aprox buy volume of timeframe under cursor.  Note: If the result returns N/A the high = close or low = close and time frame is a doji.  Choose your inputs to see premarket, total volume, and day market total volume.  There are also arrow indicators based on VWAP for enter and exit points.  The volume histogram always shows the dominant value in back and lowest volume in front.  Use the VWAP agg time to adjust / dial in your VWAP for more volatile charts and better accuracy. 

declare lower;
##########################
# Configurable Parameters
##########################
input Deviation_Length = 60;
input Deviate = 2;
input Show_Labels = yes;
input Chart_Type = ChartType.HEIKIN_ASHI;    #hint Chart_Type: Select the type of candles you are using, normal candlesticks or Heikin Ashi
input aggregationPeriod = AggregationPeriod.MIN; #hint aggregationPeriod: Set your chart timeframe here to use for study.  Default is the minute time frame
input VWAP_Agg = AggregationPeriod.FIFTEEN_MIN;
input Audible_Alert = yes;    #hint Audible_Alert: enable for audible alerts
input Show_Arrows = yes;    #hint Show_Arrows: enable for enter and exit arrows above
input UseVWAPFilter = yes;    #hint UseVWAPFilter: enable for VWAP filtering
input ShowTodaysVolume = yes;    #hint ShowTodaysVolume: enable to show todays total volume
input ShowTodaysPreMrktVolume = yes;     #hint ShowTodaysPreMrktVolume: enable to show todays premarket total volume
input startTime = 0000;    #hint startTime: pre and post market start time for 24 / 5 stocks starts at 4:00 EST
input endTime = 0930;    #hint endTime: pre-market end time is market open
input Volume_Ave_Length = 50; #hint Volume_Ave_Length: choose the number of candles to use for average volume

#####################################################################

def CurPer = aggregationPeriod;
def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def targetPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec volumeTotal = if targetPeriod and !targetPeriod[1] then volume(GetSymbol(), CurPer) else if targetPeriod then volumeTotal[1] + volume(GetSymbol(), CurPer) else volumeTotal[1];

#####################################################################

##########################
# Volume Stats & Context
##########################
def volumeStDev = RelativeVolumeStDev(length = Deviation_Length);
def abovedev = volumeStDev >= Deviate;

###### Define candlestick price parameters for buy and sell Volume ###############

def haClose = ohlc4;
def haOpen = (haclose[1]+haopen[1])/2;
def thaHigh = Max(haOpen, haClose);       
def haHigh = Max(high, thaHigh);
def thaLow = Min(haOpen, haClose);
def haLow = Min(low, thaLow);

def O = if Chart_Type == ChartType.CANDLE then open else if Chart_Type == ChartType.HEIKIN_ASHI then haOpen else Double.NaN;
def C = if Chart_Type == ChartType.CANDLE then close(GetSymbol(), CurPer)+ .0000001 else if Chart_Type == ChartType.HEIKIN_ASHI then haClose else Double.NaN;
def H = if Chart_Type == ChartType.CANDLE then high(GetSymbol(), CurPer) + .000001 else if Chart_Type == ChartType.HEIKIN_ASHI then haHigh else Double.NaN;
def L = if Chart_Type == ChartType.CANDLE then low(GetSymbol(), CurPer) - .000001 else if Chart_Type == ChartType.HEIKIN_ASHI then haLow else Double.NaN;

def DayVol = round(volume(period = “DAY”),0);
def V = volume;

def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);


##########################
# VWAP Context Filter
##########################
def vwap = VWAP(GetSymbol(), VWAP_Agg);
def aboveVWAP = close(GetSymbol(), CurPer) > vwap;
def belowVWAP = close(GetSymbol(), CurPer) < vwap;

##########################
# Volume Plots (Modification always puts the dominant color in back)
##########################

def BuyDominant  = Buying > Selling;
def SellDominant = Selling > Buying;

plot SoldVolume =
    if BuyDominant then AbsValue(Ceil(Selling - .5)) else Double.NaN;
SoldVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SoldVolume.SetLineWeight(1);
SoldVolume.SetDefaultColor(Color.RED);

plot BoughtVolume =
    if BuyDominant then Floor(Buying + 0.5) else Double.NaN;
BoughtVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BoughtVolume.SetLineWeight(1);
BoughtVolume.SetDefaultColor(Color.GREEN);

plot BoughtVo1ume =
    if SellDominant then Floor(Buying + 0.5) else Double.NaN;
BoughtVo1ume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BoughtVo1ume.SetLineWeight(1);
BoughtVo1ume.SetDefaultColor(Color.GREEN);

plot So1dVolume =
    if SellDominant then AbsValue(Ceil(Selling - .5)) else Double.NaN;
So1dVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
So1dVolume.SetLineWeight(1);
So1dVolume.SetDefaultColor(Color.RED);

##################################### Add average volume to the study ########################################
plot TV = volume;
TV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TV.SetLineWeight(1);
TV.SetDefaultColor(Color.BLUE);
#
plot VolAvg = Floor(Average(volume, Volume_Ave_Length));
VolAvg.SetDefaultColor(GetColor(8));
TV.Hide(); # Hide total volume plot if you only want the breakdown

##########################
# Relative Strength Calculation
##########################
def buyStrength = if Average(Buying, Deviation_Length) != 0 then Buying / Average(Buying, Deviation_Length) else 0;
def sellStrength = if Average(Selling, Deviation_Length) != 0 then Selling / Average(Selling, Deviation_Length) else 0;

def buyPct = if Buying + Selling != 0 then Buying / (Buying + Selling) else 0;
def sellPct = 1 - buyPct;

##########################
# Signal Conditions
##########################

def trendBuy = Buying > Buying[1] and Buying[1] > Buying[2] and Buying[2] > Buying[3];
def trendSell = Selling > Selling[1] and Selling[1] > Selling[2] and Selling[2] > Selling[3];
#add the buy volume summation to indicate strong buy trend and not give false indicators for similar priced candles
def buySum = (Buying + Buying[1] + Buying[2] + Buying[3] + Buying[4])/5;
def StrongtrendBuy = Buying > buySum and Buying > Buying[1] and Buying[1] > Buying[2] and Buying[2] >Buying[3];
#add the sell volume summation to indicate strong buy trend and not give false indicators for similar priced candles
def sellSum = (selling +Selling[1] + Selling[2] + Selling[3] + Selling[4])/5;
def StrongtrendSell = Selling > sellSum and Selling > Selling[1] and Selling[1] > Selling[2] and Selling[2] > Selling[3];

def devincrease = StrongtrendBuy and abovedev;
def devdecrease = StrongtrendSell and abovedev;

def bigBuy =  devincrease and buyPct > 0.75;
def bigSell = devdecrease and sellPct > 0.75;

##########################
# Alerts
##########################
Alert(bigBuy and Audible_Alert, "Heavy Buying Surging", Alert.BAR, Sound.Ding);
Alert(bigSell and Audible_Alert, "Heavy Selling Dump", Alert.BAR, Sound.Bell);

##########################
# Arrow Signals
##########################
plot BuyArrow = Show_Arrows and bigBuy and (UseVWAPFilter == no or aboveVWAP);
BuyArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuyArrow.SetDefaultColor(Color.GREEN);

plot SellArrow = Show_Arrows and bigSell and (UseVWAPFilter == no or belowVWAP);
SellArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellArrow.SetDefaultColor(Color.RED);

##########################
# Custom Labels (Your Voice)
##########################
AddLabel(Show_Labels, "Shares Bought = " + Floor(Buying + .5) +
    (if devincrease then " 🚀 Big Surge" else ""),
    if Buying > Selling then Color.GREEN else Color.LIGHT_GREEN);

AddLabel(Show_Labels, "Buy %: " + Round(buyPct * 100, 1) + "%" +
    (if buyPct > 0.75 then " | Buyers in Control" else if buyPct < 0.25 then " | Sellers Dominating" else " | Meh"),
    if buyPct > 0.75 then Color.LIGHT_GREEN else if buyPct < 0.25 then Color.RED else Color.GRAY);

AddLabel(Show_Labels, "Shares Sold = " + AbsValue(Ceil(Selling - .5)) +
    (if devdecrease then " 🔻 Major Dump" else ""),
    if Selling > Buying then Color.RED else Color.LIGHT_RED);

AddLabel(Show_Labels, "Sell %: " + Round(sellPct * 100, 1) + "%" +
    (if sellPct > 0.75 then " | Nasty Pressure" else if sellPct < 0.25 then " | Soft Sellers" else " | Mixed Bag"),
     if sellPct > 0.75 then Color.PINK else if sellPct < 0.3 then Color.GRAY else Color.LIGHT_GRAY);

AddLabel(yes, "Cur Candle Volume: " + Round(volume,0), Color.LIGHT_GRAY);
AddLabel(ShowTodaysVolume, "Day Vol Today: " + Round(DayVol,0), Color.LIGHT_GRAY);
AddLabel(ShowTodaysPreMrktVolume, Concat("PreMrket Vol: ", volumeTotal), Color.VIOLET);

AddLabel(Show_Labels and trendBuy, "3-Bar Buy Momentum Building 📈", Color.CYAN);
AddLabel(Show_Labels and trendSell, "3-Bar Sell Pressure Mounting 📉", Color.ORANGE);

AddLabel(Show_Labels, "VWAP: " + Round(vwap, 2) + (if aboveVWAP then " | Above VWAP" else " | Below VWAP"),
    if aboveVWAP then Color.GREEN else Color.RED);
######## Trend Reversal Warnings ################
AddLabel(Show_Labels and C > O and Selling > Buying,"Trend Reversal Likely", Color.LIGHT_RED);
AddLabel(Show_Labels and O > C and Buying > Selling, "Trend Reversal Likely",Color.LIGHT_GREEN);
 
I will troubleshoot tomorrow. I just noticed myself. Will update soon
The issue I had with the newer version is aggregationPeriod ........ if you go above the tf setting the entire study goes N/A.... a better approach is to have a toggle in which you would set how many aggregationPeriods to stay above the current chart timeframe no matter what it may be would be best implementation.

For example

input: ForwardLookingAggregation = { default "Current", "1 TF", "2 TF's", "3 TF's", "4 TF's", "5 TF's" };
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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