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: