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.1
# Revision: Updated to allow user to select aggregation period time frame; added notes
# on how to use aggregationPeriods.  First, you must select the correct type of candles
# normal candlestick or Heikin Ashi.  You must match your study timeframe to the chart 
# time frame otherwise the study will not work. 
######################################################################################

#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: Match this time frame setting to your chart time frame otherwise the study will not work and will read N/A.  Default is the minute time frame
input VWAP_Agg = AggregationPeriod.FIFTEEN_MIN; #Hint VWAP_Agg: adjust this time period for volitility.  For high volatility, select a higher timeframe, like 30 minutes to 4 hours.  For less volatile lower your 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 = 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);
 
Last edited:
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 aggregationPeriod TF settings 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/ahead of the current chart time frame. That way it always stay ahead no matter what time frame your charts on. That would be the best implementation in my opinion.

For example

input: ForwardLookingAggregation = { default "Current", "1 TF", "2 TF's", "3 TF's", "4 TF's", "5 TF's"};
How to know what time frame ForwardLookingAggregation is on or showing? ......... have a label to tell you.

Same idea for VWAP cause it will cause a N/A also.
 
Last edited:
The issue I had with the newer version is aggregationPeriod ........ if you go above the aggregationPeriod TF settings 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/ahead of the current chart time frame. That way it always stay ahead no matter what time frame your charts on. That would be the best implementation in my opinion.

For example

input: ForwardLookingAggregation = { default "Current", "1 TF", "2 TF's", "3 TF's", "4 TF's", "5 TF's"};
How to know what time frame ForwardLookingAggregation is on or showing? ......... have a label to tell you.

Same idea for VWAP cause it will cause a N/A also.
Hey Ricky, I see what is causing the arrows to not work, its going to be a tricky fix. I added notes to the code to better clarify how to use.
1.) You need to match the study candle type with your chart candle type

2.) You also need to match the study AggregationPeriod to your chart aggregation period to work correctly. This gives you the capability to use on any timeframe. I tested on all of my default timeframes and when you select your chart time frame the labels pop up.

3.) The VWAP agg period is to dial in the VWAP based on how volatile the security is being viewed. For extremely volatile, I suggest taking a larger sample set by increasing the time frame. On less volatility, lower the time as you do not need as many samples. Hope this clears up how to use it.

Let me know if you have any other questions or if something other than the arrows isn't working correctly and I will do my best to replicate and fix.

Have fun
 
Here's a version that will allow alerts on the Daily chart, using a Weekly VWAP calculation. I toggled it: a yes under "Use Weekly VWAP on Daily" (chart) will allow use on Daily, a no setting will revert indicator back to original intra-day settings

Code:
declare lower;
###############################################################################
# CONFIGURABLE PARAMETERS
###############################################################################
input Deviation_Length    = 60;
input Deviate             = 2;
input Show_Labels         = yes;
input Audible_Alert       = yes;
input Show_Arrows         = yes;
input UseVWAPFilter       = yes;

# ---------- Anchored VWAP controls ----------
input UseWeeklyVWAPonDaily = yes;   # << NEW TOGGLE (will override intraday VWAP logic on daily charts)
input UseDateAnchor       = no;     # existing
input AnchorDate          = 20250102;
input AnchorTime          = 0930;
input ResetEachSession    = yes;

# ---------- Regular-hours window ----------
input RTHOpen             = 0930;
input RTHClose            = 1600;

###############################################################################
# VOLUME CONTEXT
###############################################################################
def volumeStDev = RelativeVolumeStDev(length = Deviation_Length);
def abovedev    = volumeStDev >= Deviate;

def increase    = volume > volume[1];
def decrease    = volume < volume[1];
def devincrease = increase  and abovedev;
def devdecrease = decrease  and abovedev;

###############################################################################
# BUYING vs. SELLING VOLUME
###############################################################################
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

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

###############################################################################
# VWAP CALCULATION BLOCK — INTRADAY OR WEEKLY VWAP
###############################################################################
def isIntraday = GetAggregationPeriod() < AggregationPeriod.DAY;

# regular session only (used for intraday VWAP)
def RTH = if isIntraday
          then SecondsFromTime(RTHOpen) >= 0 and SecondsTillTime(RTHClose) > 0
          else 1;

# logic to determine reset points
def dateHit     = GetYYYYMMDD() == AnchorDate;
def timeHit     = SecondsFromTime(AnchorTime) == 0;
def barIsAnchor = (UseDateAnchor and dateHit and timeHit) or (!UseDateAnchor and timeHit);
def newSession  = GetDay() <> GetDay()[1];

def resetVWAPIntraday = barIsAnchor or (!UseDateAnchor and ResetEachSession and newSession);
def isNewWeek         = GetWeek() != GetWeek()[1];
def useWeekly         = !isIntraday and UseWeeklyVWAPonDaily;

# main VWAP reset flag based on mode
def resetVWAP = if useWeekly then isNewWeek else resetVWAPIntraday;

# cumulative values
def cumPV = CompoundValue(
             1,
             if resetVWAP then C * V else cumPV[1] + C * V,
             C * V);

def cumVol = CompoundValue(
             1,
             if resetVWAP then V else cumVol[1] + V,
             V);

def anchoredVWAP = if cumVol != 0 then cumPV / cumVol else Double.NaN;

def aboveVWAP = C > anchoredVWAP;
def belowVWAP = C < anchoredVWAP;

###############################################################################
# VOLUME PLOTS
###############################################################################
plot SV = Selling;
SV.AssignValueColor(if devdecrease then Color.PINK else Color.RED);
SV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SV.SetLineWeight(5);

plot BV = Buying;
BV.AssignValueColor(if devincrease then Color.LIGHT_GREEN else CreateColor(0,165,0));
BV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV.SetLineWeight(5);

###############################################################################
# RELATIVE STRENGTH METRICS
###############################################################################
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;

###############################################################################
# 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);

###############################################################################
# LABELS
###############################################################################
AddLabel(Show_Labels,
         "Buy Vol = " + Round(Buying, 0) +
         (if devincrease then " 🚀 Big Surge" else ""),
         if Buying > Selling then Color.GREEN else Color.DARK_GRAY);

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 " | Neutral"),
         if buyPct > 0.7 then Color.LIGHT_GREEN
         else if buyPct < 0.3 then Color.RED
         else Color.GRAY);

AddLabel(Show_Labels,
         "Sell Vol = " + Round(Selling, 0) +
         (if devdecrease then " 🔻 Major Dump" else ""),
         if Selling > Buying then Color.RED else Color.DARK_GRAY);

AddLabel(Show_Labels,
         "Sell %: " + Round(sellPct * 100, 1) + "%" +
         (if sellPct > 0.7 then " | Heavy Selling"
          else if sellPct < 0.3 then " | Light Selling"
          else " | Mixed"),
         if sellPct > 0.7 then Color.PINK
         else if sellPct < 0.3 then Color.GRAY
         else Color.LIGHT_GRAY);

AddLabel(Show_Labels,
         "VWAP = " + Round(anchoredVWAP, 2) +
         (if aboveVWAP then " | Above" else " | Below") +
         (if useWeekly then " (Weekly)" else " (Intraday)"),
         if aboveVWAP then Color.GREEN else Color.RED);

plot Bottom = -average(volume)/8;
bottom.setdefaultColor(color.black);

##########################
# Average Volume Line
##########################
plot avgVol = Average(volume, 20);
avgVol.SetDefaultColor(Color.YELLOW);
avgVol.SetLineWeight(2);
avgVol.SetStyle(Curve.SHORT_DASH);
Thanks goes out to justAnotherTrader
Nice addon mcswa

Added true stack Histo option which should not be a option but I set it up as such so you can see the difference. It shows the true volume height profile of histogram, can now view all buy sell on histo & Spacers for labels. Still more polishing to be done with the study. But here is another improved version until I have time to polish it up more.

Code:
declare lower;
###############################################################################
# CONFIGURABLE PARAMETERS
###############################################################################
input Deviation_Length    = 60;
input Deviate             = 2;
input Show_Labels         = yes;
input StackHistosToTrueVolume = yes;
input Audible_Alert       = yes;
input Show_Arrows         = yes;
input UseVWAPFilter       = yes;

# ---------- Anchored VWAP controls ----------
input UseWeeklyVWAPonDaily = yes;   # << NEW TOGGLE (will override intraday VWAP logic on daily charts)
input UseDateAnchor       = no;     # existing
input AnchorDate          = 20250102;
input AnchorTime          = 0930;
input ResetEachSession    = yes;

# ---------- Regular-hours window ----------
input RTHOpen             = 0930;
input RTHClose            = 1600;



DefineGlobalColor("LabelSpacer", CreateColor(15,15,15));


###############################################################################
# VOLUME CONTEXT
###############################################################################
def volumeStDev = RelativeVolumeStDev(length = Deviation_Length);
def abovedev    = volumeStDev >= Deviate;

def increase    = volume > volume[1];
def decrease    = volume < volume[1];
def devincrease = increase  and abovedev;
def devdecrease = decrease  and abovedev;

###############################################################################
# BUYING vs. SELLING VOLUME
###############################################################################
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;

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

###############################################################################
# VWAP CALCULATION BLOCK — INTRADAY OR WEEKLY VWAP
###############################################################################
def isIntraday = GetAggregationPeriod() < AggregationPeriod.DAY;

# regular session only (used for intraday VWAP)
def RTH = if isIntraday
          then SecondsFromTime(RTHOpen) >= 0 and SecondsTillTime(RTHClose) > 0
          else 1;

# logic to determine reset points
def dateHit     = GetYYYYMMDD() == AnchorDate;
def timeHit     = SecondsFromTime(AnchorTime) == 0;
def barIsAnchor = (UseDateAnchor and dateHit and timeHit) or (!UseDateAnchor and timeHit);
def newSession  = GetDay() <> GetDay()[1];

def resetVWAPIntraday = barIsAnchor or (!UseDateAnchor and ResetEachSession and newSession);
def isNewWeek         = GetWeek() != GetWeek()[1];
def useWeekly         = !isIntraday and UseWeeklyVWAPonDaily;

# main VWAP reset flag based on mode
def resetVWAP = if useWeekly then isNewWeek else resetVWAPIntraday;

# cumulative values
def cumPV = CompoundValue(
             1,
             if resetVWAP then C * V else cumPV[1] + C * V,
             C * V);

def cumVol = CompoundValue(
             1,
             if resetVWAP then V else cumVol[1] + V,
             V);

def anchoredVWAP = if cumVol != 0 then cumPV / cumVol else Double.NaN;

def aboveVWAP = C > anchoredVWAP;
def belowVWAP = C < anchoredVWAP;


##########################
# Average Volume Line
##########################
plot avgVol = Average(volume, 20);
avgVol.SetDefaultColor(Color.ORANGE);
avgVol.SetLineWeight(1);
avgVol.SetStyle(Curve.SHORT_DASH);

###############################################################################
# VOLUME PLOTS (DISPLAY MODE TOGGLE)
###############################################################################

# total volume represented by the split
def TV = Buying + Selling;

# display values (only affects histograms)
def SV_plot = if StackHistosToTrueVolume then Selling else Selling;
def BV_plot = if StackHistosToTrueVolume then TV      else Buying;

plot SV = SV_plot;
SV.AssignValueColor(if devdecrease then Color.PINK else Color.RED);
SV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SV.SetLineWeight(5);

plot BV = BV_plot;
BV.AssignValueColor(if devincrease then Color.LIGHT_GREEN else CreateColor(0,165,0));
BV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV.SetLineWeight(5);

###############################################################################
# RELATIVE STRENGTH METRICS
###############################################################################
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;

###############################################################################
# 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);

###############################################################################
# LABELS
###############################################################################
AddLabel(Show_Labels,
         " Buy Vol | " + Round(Buying, 0) + " " +
         (if devincrease then " 🚀 Big Surge " else ""),
         if Buying > Selling then Color.GREEN else Color.LIGHT_GRAY);

AddLabel(Show_Labels,
         " " + Round(buyPct * 100, 0) + " %" +
         (if buyPct > 0.7 then " | In Control "
          else if buyPct < 0.3 then " | Sellers Dominating "
          else " | Neutral"),
         if buyPct > 0.7 then Color.LIGHT_GREEN
         else if buyPct < 0.3 then Color.RED
         else Color.LIGHT_GRAY);

AddLabel(Show_Labels, " ", GlobalColor("LabelSpacer"));

AddLabel(Show_Labels,
         " Sell Vol | " + Round(Selling, 0) + " " +
         (if devdecrease then " 🔻 Major Dump" else ""),
         if Selling > Buying then Color.RED else Color.LIGHT_GRAY);

AddLabel(Show_Labels,
         " " + Round(sellPct * 100, 1) + " %" +
         (if sellPct > 0.7 then " | Heavy Selling "
          else if sellPct < 0.3 then " | Light Selling "
          else " | Mixed"),
         if sellPct > 0.7 then Color.RED
         else if sellPct < 0.3 then Color.PINK
         else Color.LIGHT_GRAY);

AddLabel(Show_Labels, " ", GlobalColor("LabelSpacer"));

AddLabel(Show_Labels,
         "VWAP = " + Round(anchoredVWAP, 2) +
         (if aboveVWAP then " | Above" else " | Below") +
         (if useWeekly then " (Weekly)" else " (Intraday)"),
         if aboveVWAP then Color.GREEN else Color.RED);




#plot Bottom = -average(volume)/8;
#bottom.setdefaultColor(color.black);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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