Join useThinkScript to post your question to a community of 21,000+ developers and traders.
copied the code and paste it in my TOS. I'm missing the volume bars.How to enable ?
Price Subgraph is the actual Chart... Volume Subgraph can be enabled or disabled under the proper instrument type, whether Equities, Options, or Futures...Can you go to your TOS Settings and see, if you have "Show Price Subgraph" enabled?
BTW there is a higher version of the code available with more knobs, incase you ever managed to get 1.2.1 working.copied the code and paste it in my TOS. I'm missing the volume bars.How to enable ?
## Volume Labels
# Version 1.5.3
# Created: 06/23/20 # Modified on 08/26/20
# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input. ## Additionally Pre-Market, 1Hr Volume, AfterHour, 5 Day Volume labels are added.
# Version 1.5 Changes
# Change 1) Higher Time Frame Buying Vs Selling, Please make sure to configure VolPeriod higher than typical chart frame used.
# Change 2) Added 30Day Average White Line to VolumeBar, for 1Y 1D, and a 30BarAvg line for lower timeframes, Just to indicate if the current bar is above or below Average line.
# Version 1.5.1 Changes.
# Minor, Higher timeframe has labels indicating the timeframe.
# Version 1.5.2 Changes.
# Change 1) Minor, Daily and Previous day volumes converted to Millions with round(2), easier to read than counting the digits on running volume during trading hours.
# Change 2) Fixed color code issue with previous DayVolume, now we code Day/previousDay volumes to lime if they are less then corrospondant previous day and higher than 30DAvg.
#Version 1.5.3 Changes
# Added Avg % of Buying selling for 30Bar
# Added New 6 Bar stats for comaprision against 30Bar
declare on_volume; # Declared on_volume, if you need to use only labels as a top study comment # Selling Volume # & # Buying Volume # along with this line.
input length = 30;
input Barlength = 6;
input ShowTodayVolume = yes;
input PreviousDayVolume = yes;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowVol = yes;
def VolStatsPeriod = (if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.WEEK else AggregationPeriod.DAY);
def VolDayAvg = Average(volume(period = "Day")[1], length);
def AvgBars = Average(volume[1], length);
def AvgBars2 = Average(volume[1], Barlength);
def Vol1 = volume(period = "DAY")[1];
def Vol2 = volume(period = "DAY")[2];
def Vol3 = volume(period = "DAY")[3];
def Vol4 = volume(period = "DAY")[4];
def Vol5 = volume(period = "DAY")[5];
def VolDayAvg1 = VolDayAvg[1];
def VolDayAvg2 = VolDayAvg[2];
def VolDayAvg3 = VolDayAvg[3];
def VolDayAvg4 = VolDayAvg[4];
def VolDayAvg5 = VolDayAvg[5];
def Vol = volume(period = "DAY");
def DollarVolume = hl2 * Vol;
def AvgHL2 = Average(hl2 * Vol , length);
def DaysDollarVol = VolDayAvg * AvgHL2;
def rVol = Vol / VolDayAvg;
def PercentOfDayAvg = Round((rVol * 100), 2);
############### Buying and Selling Volume Study
#DPL CRITERIA #
###############
input Audible_Alert = yes;
def Deviation_Length = 60;
def Deviate = 2;
def volumestdev = RelativeVolumeStDev(length = Deviation_Length);
def abovedev = volumestdev >= Deviate;
def belowdev = volumestdev <= Deviate;
############
# DPL BARS #
############
def increase = volume > volume[1];
def devincrease = increase and abovedev;
def decrease = volume < volume[1];
def devdecrease = decrease and abovedev;
##############################
# UPTICK / DOWNTICK CRITERIA #
##############################
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
################################
# 6BAR #
################################
def HH6 = Average(high[1], Barlength);
def HC6 = Average(close[1], Barlength);
def HL6 = Average(low[1], Barlength);
def HV6 = Average(volume[1], Barlength);
def Buy6 = HV6 * (HC6 - HL6) / (HH6 - HL6);
def Sell6 = HV6 * (HH6 - HC6) / (HH6 - HL6);
################################
# 30BAR #
################################
#def HH30 = (fold B30H = 1 to length + 1 with i30H = 0 do (i30H + high[B30H]));
#def HC30 = (fold B30C = 1 to length + 1 with i30C = 0 do (i30C + close[B30C]));
#def HL30 = (fold B30L = 1 to length + 1 with i30L = 0 do (i30L + low[B30L]));
#def HV30 = (fold B30V = 1 to length + 1 with i30V = 0 do (i30V + volume[B30V]));
def HH30 = Average(high[1], length);
def HC30 = Average(close[1], length);
def HL30 = Average(low[1], length);
def HV30 = Average(volume[1], length);
def Buy30 = HV30 * (HC30 - HL30) / (HH30 - HL30);
def Sell30 = HV30 * (HH30 - HC30) / (HH30 - HL30);
###############################################
# For Higher Frame UPTICK / DOWNTICK CRITERIA #
###############################################
def HH = high (period = VolStatsPeriod);
def HC = close (period = VolStatsPeriod);
def HL = low (period = VolStatsPeriod);
def HV = volume (period = VolStatsPeriod);
def HBuying = HV * (HC - HL) / (HH - HL);
def HSelling = HV * (HH - HC) / (HH - HL);
##################
# Selling Volume #
##################
plot SVol = Selling;
SVol.DefineColor("Decrease", Color.DARK_RED);
SVol.DefineColor("DevDecrease", Color.LIGHT_RED);
SVol.AssignValueColor(if devdecrease then SVol.Color("DevDecrease") else SVol.Color("Decrease"));
SVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SVol.HideTitle();
SVol.HideBubble();
SVol.SetLineWeight(5);
#################
# Buying Volume #
#################
plot BVol = Buying;
BVol.DefineColor("Increase", Color.DARK_GREEN);
BVol.DefineColor("DevIncrease", Color.GREEN);
BVol.AssignValueColor(if devincrease then BVol.Color("DevIncrease") else BVol.Color("Increase"));
BVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BVol.HideTitle();
BVol.HideBubble();
BVol.SetLineWeight(5);
#################
# Volume % #
#################
def totVol = Round(Buying, 0) + Round(Selling, 0) ;
def buyPercent = ( Round(Buying, 0) / totVol ) * 100;
def sellPercent = ( Round(Selling, 0) / totVol ) * 100;
#####################
# Higher Volume % #
#####################
def HtotVol = Round(HBuying, 0) + Round(HSelling, 0) ;
def HbuyPercent = ( Round(HBuying, 0) / HtotVol ) * 100;
def HsellPercent = ( Round(HSelling, 0) / HtotVol ) * 100;
#####################
# 6Bar Volume % #
#####################
def H6Vol = Round(Buy6, 0) + Round(Sell6, 0) ;
def H6buyPercent = ( Round(Buy6, 0) / H6Vol ) * 100;
def H6sellPercent = ( Round(Sell6, 0) / H6Vol ) * 100;
#####################
# 30Bar Volume % #
#####################
def H30Vol = Round(Buy30, 0) + Round(Sell30, 0) ;
def H30buyPercent = (Round(Buy30, 0) / H30Vol) * 100;
def H30sellPercent = (Round(Sell30, 0) / H30Vol) * 100;
########################
# Adding Volume Labels #
########################
#Higher Time Frame Buying & Selling Volumes#
input ShowHigherVolStats = yes;
AddLabel(if GetAggregationPeriod() >= VolStatsPeriod and !ShowHigherVolStats then 0 else 1, (if VolStatsPeriod == AggregationPeriod.MONTH then "M" else if VolStatsPeriod == AggregationPeriod.WEEK then "W" else if VolStatsPeriod == AggregationPeriod.FOUR_DAYS then "4D" else if VolStatsPeriod == AggregationPeriod.THREE_DAYS then "3D" else if VolStatsPeriod == AggregationPeriod.TWO_DAYS then "2D" else if VolStatsPeriod == AggregationPeriod.DAY then "D" else if VolStatsPeriod == AggregationPeriod.FOUR_HOURS then "4H" else if VolStatsPeriod == AggregationPeriod.TWO_HOURS then "2H" else if VolStatsPeriod == AggregationPeriod.HOUR then "60m" else if VolStatsPeriod == AggregationPeriod.THIRTY_MIN then "30m" else if VolStatsPeriod == AggregationPeriod.TWENTY_MIN then "20m" else if VolStatsPeriod == AggregationPeriod.FIFTEEN_MIN then "15m" else if VolStatsPeriod == AggregationPeriod.TEN_MIN then "10m" else if VolStatsPeriod == AggregationPeriod.FIVE_MIN then "5m" else if VolStatsPeriod == AggregationPeriod.FOUR_MIN then "4m" else if VolStatsPeriod == AggregationPeriod.THREE_MIN then "3m" else if VolStatsPeriod == AggregationPeriod.TWO_MIN then "2m" else if VolStatsPeriod == AggregationPeriod.MIN then "1m" else "") + " Buy: " + Round(HBuying * .000001, 2) + "M " + Round(HbuyPercent, 2) + "% ", (if HBuying > HSelling then Color.GREEN else Color.RED)) ;
AddLabel(if GetAggregationPeriod() >= VolStatsPeriod and !ShowHigherVolStats then 0 else 1, (if VolStatsPeriod == AggregationPeriod.MONTH then "M" else if VolStatsPeriod == AggregationPeriod.WEEK then "W" else if VolStatsPeriod == AggregationPeriod.FOUR_DAYS then "4D" else if VolStatsPeriod == AggregationPeriod.THREE_DAYS then "3D" else if VolStatsPeriod == AggregationPeriod.TWO_DAYS then "2D" else if VolStatsPeriod == AggregationPeriod.DAY then "D" else if VolStatsPeriod == AggregationPeriod.FOUR_HOURS then "4H" else if VolStatsPeriod == AggregationPeriod.TWO_HOURS then "2H" else if VolStatsPeriod == AggregationPeriod.HOUR then "60m" else if VolStatsPeriod == AggregationPeriod.THIRTY_MIN then "30m" else if VolStatsPeriod == AggregationPeriod.TWENTY_MIN then "20m" else if VolStatsPeriod == AggregationPeriod.FIFTEEN_MIN then "15m" else if VolStatsPeriod == AggregationPeriod.TEN_MIN then "10m" else if VolStatsPeriod == AggregationPeriod.FIVE_MIN then "5m" else if VolStatsPeriod == AggregationPeriod.FOUR_MIN then "4m" else if VolStatsPeriod == AggregationPeriod.THREE_MIN then "3m" else if VolStatsPeriod == AggregationPeriod.TWO_MIN then "2m" else if VolStatsPeriod == AggregationPeriod.MIN then "1m" else "") + " Sell: " + Round(HSelling * .000001, 2) + "M " + Round(HsellPercent, 2) + "% ", (if HSelling > HBuying then Color.GREEN else Color.RED)) ;
#AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else 1, "WBuy: " + Round(HBuying * .000001, 2) + "M " + Round(HbuyPercent, 2) + "% ", (if HBuying > HSelling then Color.GREEN else Color.RED));
#AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else 1, "WSell: " + Round(HSelling * .000001, 2) + "M " + Round(HsellPercent, 2) + "% ", (if HSelling > HBuying then Color.GREEN else Color.RED));
#######################################Chart Time Frame Buying & Selling Volumes#######################################
input Show_Labels = yes;
AddLabel(Show_Labels, "Buy: " + Round(Buying, 2) + " " + Round(buyPercent, 2) + "% ", if Buying > Selling then Color.GREEN else Color.RED);
AddLabel(Show_Labels, "Sell: " + Round(Selling, 2) + " " + Round(sellPercent, 2) + "% ", if Selling > Buying then Color.GREEN else Color.RED);
############################################ End of Buying & Selling Labels Study ####################################
input ShowDayAvg = yes;
AddLabel(ShowDayAvg, length + "DAvg: " + Round(VolDayAvg * .000001, 2) + " M ", Color.LIGHT_GRAY);
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D4: " + Round(Vol4 * .000001, 2) + " M ", (if Vol4 >= VolDayAvg4 and Vol4 >= Vol5 then Color.GREEN else if Vol4 <= Vol5 and Vol4 >= VolDayAvg4 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D3: " + Round(Vol3 * .000001, 2) + " M ", (if Vol3 >= VolDayAvg3 and Vol3 >= Vol4 then Color.GREEN else if Vol3 <= Vol4 and Vol3 >= VolDayAvg3 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D2: " + Round(Vol2 * .000001, 2) + " M ", (if Vol2 >= VolDayAvg2 and Vol2 >= Vol3 then Color.GREEN else if Vol2 <= Vol3 and Vol2 >= VolDayAvg2 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D1: " + Round(Vol1 * .000001, 2) + " M ", (if Vol1 >= VolDayAvg1 and Vol1 >= Vol2 then Color.GREEN else if Vol1 <= Vol2 and Vol1 >= VolDayAvg1 then Color.LIME else Color.RED));
AddLabel(ShowTodayVolume, "D: " + Round(Vol * .000001, 2) + " M ", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.LIME else Color.RED));
AddLabel(ShowPercentOfDayAvg, PercentOfDayAvg + "%", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.LIME else Color.WHITE) );
############################################ 30 Bar Stats ############################################
input Show30Bar = yes;
AddLabel(Show30Bar, "A" + length + "Bars: "+ Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(Show30Bar, "B" + length + ":" + Round(Buy30, 0) + " " + Round(H30buyPercent, 2) + "% ", if Buy30 > Sell30 then Color.GREEN else Color.RED);
AddLabel(Show30Bar, "S" + length + ":" + Round(Sell30, 0) + " " + Round(H30sellPercent, 2) + "% ", if Sell30 > Buy30 then Color.GREEN else Color.RED);
############################################ 6 Bar Stats ############################################
input Show6Bar = yes;
AddLabel(Show6Bar, "A" + Barlength + "Bars: "+ Round(AvgBars2, 0) + " ",Color.LIGHT_GRAY);
AddLabel(Show6Bar, "B" + Barlength + ":" + Round(Buy6, 0) + " " + Round(H6buyPercent, 2) + "% ", if Buy6 > Sell6 then Color.GREEN else Color.RED);
AddLabel(Show6Bar, "S" + Barlength + ":" + Round(Sell6, 0) + " " + Round(H6sellPercent, 2) + "% ", if Sell6 > Buy6 then Color.GREEN else Color.RED);
###############################Current Bar, rVol, DollerTraded, 30D Traded ################################
input ShowRvol = no;
input ShowDollarTraded = yes;
input ShowDaysDollarTraded = yes;
AddLabel(ShowRvol, "rVol :" + Round(rVol, 2), (if rVol >= 2 then Color.GREEN else if rVol > 1 then Color.LIME else Color.WHITE));
AddLabel(ShowDollarTraded, "Traded : " + AsDollars(Round(DollarVolume * .000001, 2)) + "M ", Color.WHITE);
AddLabel(ShowDaysDollarTraded, length + "DayTraded : " + AsDollars(Round(DaysDollarVol * .0000000001, 2)) + "B ", Color.WHITE);
########################## Add Horizantal Line at 30DAvgVolume level or 30BarAvgVolume level on intraday #######################
def AvgLine = VolDayAvg[0];
plot line = (if GetAggregationPeriod() >= AggregationPeriod.DAY then AvgLine else AvgBars);
line.SetDefaultColor(Color.WHITE);
line.SetLineWeight(2);
############################## Pre, 1Hr RTH, AfterHours Volumes ###########################################
input ShowPreMktVol = yes;
input ShowRTH1HrVol = yes;
input ShowPostMktVol = yes;
def PreMkt = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PreVol = if PreMkt and !PreMkt[1] then volume else if PreMkt then PreVol[1] + volume else PreVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowPreMktVol then 0 else 1, "PreMktVol = " + Round(PreVol * .000001, 2) + "M ", Color.YELLOW);
# End Volume PreMarket
def RTH1HrstartTime = 0930;
input RTH1HrendTime = 1030;
def RTH1Hr = SecondsFromTime(RTH1HrstartTime) >= 0 and SecondsTillTime(RTH1HrendTime) > 0;
def RTH1HrVol = if RTH1Hr and !RTH1Hr[1] then volume else if RTH1Hr then RTH1HrVol[1] + volume else RTH1HrVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowRTH1HrVol then 0 else 1, "RTH1HrVol = " + Round(RTH1HrVol * .000001, 2) + "M ", Color.YELLOW);
AddVerticalLine(if GetDay() == GetLastDay() and RTH1Hr == 0 and RTH1Hr[1] == 1 then yes else no, "First Hour Mark", color = Color.WHITE);
#End Volume RTH First 60 Mins
def PostMkt = RegularTradingEnd (GetYYYYMMDD()) < GetTime();
def PostVol = if PostMkt and !PostMkt[1] then volume else if PostMkt then PostVol[1] + volume else PostVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowPostMktVol then 0 else 1, "PostMktVol = " + Round(PostVol * .000001, 2) + "M ", Color.YELLOW);
# End Volume PostMarket
input limit = 0.09;
def price = close(priceType = PriceType.LAST);
AddLabel(yes, Concat("PRICE: ", price), if price > price[1] then Color.LIGHT_GREEN else if price < price[1] then Color.RED else Color.CURRENT);
AddLabel (yes,"Vol:" + volume, colour.white);
AddLabel (yes,"Vol:" + volume(period = "DAY"), colour.white);
The way I am reading it is he wants current price and todays total volume... Relatively sure @Stockleed knows there is a volume but not how to get todays volume... I went to get a script I have but his question got moved and then I discovered I had butchered my script and it now has errors... Grrr...!!! One more thing to fix...Though that was the ask, he's trying to determine what volume was traded at that price line. I could be wrong.
#TodaysVolume
#Created by rad14733 from usethinkscript.com
#v1.0 2021-01-07
def volAgg = if GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.DAY else GetAggregationPeriod();
def TodaysVolume = volume("period" = volAgg);
AddLabel(yes, " Todays Volume: " + TodaysVolume + " ", Color.WHITE);
Alright !! Updated the code, back in the same post. Please check it and let me know if that works for you.@SuryaKiranC Thanks! I put the script on ToS. I'm having some issues getting it to work. The numbers for the Avg30Bars and Avg6Bars are large and not a percent of selling over those periods. I think the labels are just showing the average volume across 30 bars or 6 bars and not the percent of selling over those periods. In the previous script, that last label was current bar sell % which shows the percentage of selling (presumably using the IBS method) during the current bar. What I'm hoping to add to that is the sell % over the last 6 bars and the sell % over that last 30 bars (similar to how you coded the sell % for the current bar in the original script just in addition a label for the sell % over the last 6 bars and a label for the sell % over the last 30 bars). Thanks again!!
Start a new thread and receive assistance from our community.
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.
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.