Custom Thinkscript - Volume Stats for ThinkOrSwim

W

wes.

New member

Hi there, I have been looking for a simple TOS chart label like the one in the pic above. Havent had much luck finding something simple like this. As you can see, the label has the average volume at current time of day and todays volume expressed as RVOL. I plan on using it on a 1 minute timeframe chart.
Can anyone here share a script with me that shows this information. It would be greatly appreciated!
 
M

ms217

New member
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?
3AMBH - This is a great script. Works well once I added to the studies. Thank you.

Friends - Was there a response to this request above? I was looking to add this as a col. in my watchlist too. Can someone help if this is not yet answered?

Thank you
 
jngy2k

jngy2k

Member
VIP
I revisited this indicator for trading and research the other day and found where there can be more value that can be added to the indicator. Most value is if we can grab average volume for the previous 180 days for the premarket and first hour of trading. Why 180 days is because thinkorswim cannot capture the intraday minutes and premarket data more than 180 days. Having premarket and first hour average volume for the previous 180 days is important because it gives the user an early signal of high relative volume during those hours of trading. A higher relative volume in those early hours will mean more price action in coming hours. Right now I use Volume avg and compare the volume for today to the avg but it is a slower signal of high relative volume because it gives daily volume instead of intraday volume. Knowing earlier if there is higher volume with the previous premarket and 1st hour volume data is a huge edge.
Anyone know how to code for the capture of previous 180 days data?
Code:
input PrestartTime = 0400;
input PreendTime = 0930;
def PreMkt = SecondsFromTime(PrestartTime) >= 0 and SecondsTillTime(PreendTime) >= 0;
def PreVolMins = if PreMkt and !PreMkt[1] then volume
                else if PreMkt then PreVolMins[1] + volume
                else PreVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0, "PreMktVol: " + Round(PreVolMins * .000001, 2) + "M", Color.YELLOW);
This is @SuryaKiranC code for Premarket.
 
S

SuryaKiranC

Member
@jngy2k Had something similar idea in my wishlist for a while. maybe I could take sometime this weekend to testout some code. done right, we should be able to do what you want and more.

-S
 
P

Praful005

New member
VIP
There are so many changes and versions... can someone please share the link for latest indicator with all the settings options.
 
S

stockscouter87

New member
WOW!!!!! SO I have been scouring the web for a relative volume indicator that i can use for information in the past to find current runners. I believe the only thing this is missing is where it can scan the whole market and if there is a say 85% jump in the daily shares traded from the past 6months and crosses VWAP on that day, IMO i believe that will help us find the next big runners!!!!!

OH yea, First post in the community and currently learning how to script but I am one heck of a copy and paste professional haha
 
zeek

zeek

Active member
2019 Donor
I revisited this indicator for trading and research the other day and found where there can be more value that can be added to the indicator. Most value is if we can grab average volume for the previous 180 days for the premarket and first hour of trading. Why 180 days is because thinkorswim cannot capture the intraday minutes and premarket data more than 180 days. Having premarket and first hour average volume for the previous 180 days is important because it gives the user an early signal of high relative volume during those hours of trading. A higher relative volume in those early hours will mean more price action in coming hours. Right now I use Volume avg and compare the volume for today to the avg but it is a slower signal of high relative volume because it gives daily volume instead of intraday volume. Knowing earlier if there is higher volume with the previous premarket and 1st hour volume data is a huge edge.
Anyone know how to code for the capture of previous 180 days data?
Code:
input PrestartTime = 0400;
input PreendTime = 0930;
def PreMkt = SecondsFromTime(PrestartTime) >= 0 and SecondsTillTime(PreendTime) >= 0;
def PreVolMins = if PreMkt and !PreMkt[1] then volume
                else if PreMkt then PreVolMins[1] + volume
                else PreVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0, "PreMktVol: " + Round(PreVolMins * .000001, 2) + "M", Color.YELLOW);
This is @SuryaKiranC code for Premarket.

I like this idea of comparing RVOL intraday data for the maximum number of days allowed and have been thinking about creating something like this too. I hope someone can help build a script for this.

I trade quite a lot smallcaps that occasionally have big volume days with a gap and it would be really useful to compare the RVOL for all these gaps/big volume days in the last 180 days.
 
C

cswu1211

New member
VIP
I think I fixed it. While at it tried to fold Pre-Market, 1H Market and Post-Market volumes added to the labels, must work Equity, if not with futures.

Code:
# Box Volume Stats
# Version 1.2
# Created by: Enigma
# Created: 05/18/17
# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input. ## Additionally Pre-Market, 1Hr Volume, AfterHour Volume labels are added.


declare on_volume;

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

input PreMktVol = yes;
input RTH1HrVol = yes;
input PostMktVol = yes;


def VolDayAvg = (fold index = 1 to length + 1  with Avg = 0 do (Avg + volume(period = "DAY")[index])) / length;
def AvgBars = (fold index2 = 1 to length + 1 with Bar = 0  do (Bar + volume[index2])) / length;

def Today = volume(period =  "DAY");
def PercentOfDayAvg = Round((Today / VolDayAvg) * 100, 0);

def CurVol = volume;


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

# Labels

#if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if 1HrRTHVol then 1 else 0,

AddLabel(ShowDayAvg, length + "Day 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" + length  + "Bars: " + Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + CurVol + " ", (if CurVol >= AvgBars then Color.GREEN else Color.ORANGE));

AddLabel(yes, "rVol :" + 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);

#Pre, 1Hr RTH, AfterHours Volumes.
##if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0

input PrestartTime = 0400;
input PreendTime = 0929;

def PreMkt = SecondsFromTime(PrestartTime) >= 0 and SecondsTillTime(PreendTime) >= 0;
def PreVolMins = if PreMkt and !PreMkt[1] then volume
                else if PreMkt then PreVolMins[1] + volume
                else PreVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0, "PreMktVol = " + PreVolMins + "  ", Color.YELLOW);
# End Volume PreMarket

input RTH1HrstartTime = 0930;
input RTH1HrendTime = 1029;

def RTH1Hr = SecondsFromTime(RTH1HrstartTime) >= 0 and SecondsTillTime(RTH1HrendTime) >= 0;
def RTH1HrMins = if RTH1Hr and !RTH1Hr[1] then volume
                else if RTH1Hr then RTH1HrMins[1] + volume
                else RTH1HrMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if RTH1HrVol then 1 else 0, "RTH1HrVol = " + RTH1HrMins + "  ", Color.YELLOW);
#End Volume RTH First 60 Mins

input PoststartTime = 1600;
input PostendTime = 1959;

def PostMkt = SecondsFromTime(PoststartTime) >= 0 and SecondsTillTime(PostendTime) >= 0;
def PostVolMins = if PostMkt and !PostMkt[1] then volume
                else if PostMkt then PostVolMins[1] + volume
                else PostVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PostMktVol then 1 else 0, "PostMktVol = " + PostVolMins + "  ", Color.YELLOW);
# End Volume PostMarket
Please advise why I can't get the line shown on volume graph?!

it seems no way to change/show color of the vol change line
 
D

DoQtorNo

New member
Howdy and good afternoon,

Does anyone know how I can capture the volume of each bar on a given timeframe chart (lower timeframe), and place a chartbubble on the bar for the total volume of the bar? Just for the current days trading.
 
S

SuryaKiranC

Member
@cswu1211 What, version of the code you grabbed? and I am assuming you are referring to Buy/Sell Color coding in the Volume area. If not please explain what Lines are you referring to.
 
jngy2k

jngy2k

Member
VIP
i'm practicing trying to edit some of the code
what would be an example of simple define for the highest price within the past period (period willl be defined as afterarket closed and before open)
i could'nt use highestall[] because i want to only use 1min chart and highestall[] returns price before the market closed at 1600 as well

example:
input closing_time = 1600;
input open_time = 0930;
def time_until_open = SecondsTillTime(open_time);
def time_until_close = SecondsTillTime(closing_time);
def after_closing_bell = time_until_close <= 0;
def before_opening_bell = time_until_open >= 0 ;
plot scan = (after_closing_bell or before_opening_bell) AND highest price of premarket somehow;


@3AMBH @tomsk @SuryaKiranC @rad14733

would this work in retaining the highest high for the period?
or will it give me the high of the previous 1minbar only but not the overall high for the chart?
rec high_price = CompoundValue(1, high, high[1]);
i want the high price to always be the highest price for the period
 
Last edited:

Similar threads

Top