Custom Thinkscript - Volume Stats for ThinkOrSwim

3AMBH

Member
2019 Donor
This custom Thinkscript indicator shows you important volume data on your ThinkOrSwim charts. This includes Current Volume, Average 30 Day Volume, Percentage of Current Volume to Average Daily Volume, Average 30 Bar Volume and Current Bar Volume. Volume stats change colors to indicate when the volume reaches the average daily volume level as well as a customizable unusual volume level. This allows you to easily see critical changes in volume levels which are important for all types of trading.

The Script:

Code:
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17

declare lower;

#Inputs
input Show30DayAvg = yes;
input ShowTodayVolume =  yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;


#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;


# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));

Shared link: https://tos.mx/rSGwbW

YouTube

 
Last edited by a moderator:

przinho

New member
Hi, im newbie with coding.
Can somebody help me with label that shows first 30 min volume of today session?
Thank you for your time.
 

tomsk

Well-known member
VIP
@przinho Here's a label for the first 30 mins of volume as requested. Run this on an intraday chart

Code:
# Volume RTH First 30 Mins
# tomsk
# 11.5.2019

declare hide_on_daily;

input startTime = 0930;
input endTime = 1000;

def Active = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
def Vol30Mins = if Active and !Active[1] then volume
                else if Active then Vol30Mins[1] + volume
                else Vol30Mins[1];
AddLabel(1, "Volume First 30 Mins = " + Vol30Mins, Color.YELLOW);
# End Volume RTH First 30 Mins
 
Last edited:

tenacity11

Active member
2019 Donor
@tomsk Is there a way to have the Volume Stats on the top left corner of the chart without having the actual volume box?
TIA
 

tomsk

Well-known member
VIP
Your request is incomplete. What volume stats are you looking for? Not sure I understand what you mean by "actual volume box". Like I always tell people - you'll need to be real clear and explicit with your requests or it won't be easily understood
 

tenacity11

Active member
2019 Donor
Your request is incomplete. What volume stats are you looking for? Not sure I understand what you mean by "actual volume box". Like I always tell people - you'll need to be real clear and explicit with your requests or it won't be easily understood
Apologies. As it stands now the volume stats populate the same box as volume in the lower part of the chart. What I want is to have the volume stats at the top of the chart under the area where the chart name, date, O-H_L_C is. I don't want to have the volume box on. Hope that helps explain.
 

tomsk

Well-known member
VIP
Gotcha, from your decription, you'd like to turn off the volume subgraph on your chart and display the volume as a label. This is real simple. To disable the volume subgraph on your chart, go to Chart Settings > Equities. Then unclick the checkbox "Show volume subgraoh" Here is a very simple label that displays the volume as a chart label

Code:
addLabel(1, "Volume = " + volume, color.Yellow);
 
Last edited:

tenacity11

Active member
2019 Donor
Gotcha, from your decription, you'd like to turn off the volume subgraph on your chart and display the volume as a label. This is real simple. To disable the volume subgraph on your chart, go to Chart Settings > Equities. Then unclick the checkbox "Show bolume subgraoh" Here is a very simple label that displays the volume as a chart label

Code:
addLabel(1, "Volume = " + volume, color.Yellow);
Once again thanks. Perfect
 

gregoryK

New member
VIP
Hello. Completely new to scripting but I'm wondering is there a way to take this excellent code and apply it to my watchlist so that I can see when volume reaches the Gold and Green status ? I tried directly pasting it into a custom column but that didn't work. Any thoughts?
 

C4men

Member
Newbie here as well. Is there code to have a box/label for each of these two:
  • Buy volume
  • Sell volume

Hoping to see which side has the most volume (or just imbalances in general) for the day.

Maybe like: Buy Vol - 1,024 / Sell Vol - 32,860
 

IfeelFrank

New member
Hey guys, just joined the forum.
I wanted to know if there is a script for giving me the volume/price value. I want to organize my watchlists by volume relative to the price of the asset.
 

mansor

Member
this label shows daily avg volume, today avg volume, % change, avg 30 bars, & current bar. It works fine during rths. During pre market it just shows daily avg vol, avg 30 bars and current bar. It doesn't show today's avg nor % change. Is there someone here who can enable today's volume in pre-market? thanks in advance
 

vensonom

New member
Is it possible to plot the "Shares Per Trade" on a Volume chart ? the brief description of this indicator from another website is pasted below.

A relative shares per trade indicator for intraday charts that shows you the average number of shares per trade for the current bar and whether or not it is an unusual amount. This is key. When you see this number jump you know the big boys have joined the party!
 

NathanJames

New member
Hello everyone, @markos,@BenTen With regard to the code above,is there any possibility that you can convert this code to use it as a scanner with the label showing only " Today Volume and Percentage?. thanks for your help
 
Last edited:
Custom Thinkscript - Volume Stats for ThinkOrSwim found on YouTube

This custom Thinkscript indicator shows you important volume data on your ThinkOrSwim charts. This includes Current Volume, Average 30 Day Volume, Percentage of Current Volume to Average Daily Volume, Average 30 Bar Volume and Current Bar Volume. Volume stats change colors to indicate when the volume reaches the average daily volume level as well as a customizable unusual volume level. This allows you to easily see critical changes in volume levels which are important for all types of trading.

YouTube


https://tos.mx/rSGwbW

The Script:
Code:
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17

declare lower;

#Inputs
input Show30DayAvg = yes;
input ShowTodayVolume =  yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;


#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;


# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));
Can you make this indicator which is on chart to daily watchlist ? I need similar type of indicator where i can sort the stocks which are trading in high unusual volume currently. This way I can buy right away if volume picks up showing in my watchlist. Thanks.
 

SuryaKiranC

Well-known member
Hi All,

Been here and checking out some scripts for few months. Though about time I start contributing.

My first ever post ever. I am trying to improve this script and include, rVolume as well in the labels. Intended changes are listed.
  • Change the number of days for average calculation to be an input, instead of fixed 30 days.
  • Include rVolume Label.
I think I got the calculations right, however when I give 30 Days as an input for the modified script, it's slightly off in 30DayAvg Calculations.

Was wondering, if somebody here can take a look at this and see what am I missing. Please see the attached screenshot, the one on the left is using original code and the one on the right is using the modified code.

gGUYCGO.png


Code:
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17
# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input.

declare on_volume;

input length = 30;
input ShowDayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowCurrentBar = yes;

def VolDayAvg = (fold index = 1 to length with Avg do Avg + (volume(period = "DAY")[index])) / length ;
def Today = volume(period =  "DAY");
def PercentOfDayAvg = Round((Today / VolDayAvg) * 100, 0);
def AvgBars = (fold index2 = 1 to length with Bar do Bar + (volume[index2])) / length;
def CurVol = volume;

def offset = 1;
def ADV = Average(volume, length)[offset];
def rVol = volume / ADV;

# Labels
AddLabel(yes, Round(rVol, 2));
AddLabel(yes, "ADV :" + ADV);
#AddLabel(yes, asPercent(rVol)); # remove "#" infront of Addlabels to select prefer choice
#AssignPriceColor(if rVol >= 1 then color.dark_red else if rVol <=.5 then Color.black else color.Gray);
AddLabel(ShowDayAvg, "Daily Avg: " + Round(VolDayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + Today + " ", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOfDayAvg, PercentOfDayAvg + "%", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowBarAvg, "Avg 30 Bars: " + Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + CurVol + " ", (if CurVol >= AvgBars then Color.GREEN else Color.ORANGE));
 

Similar threads

Top