Volume Stats Format, Watchlist, Scan, Label for ThinkOrSwim

@jake438899 Here you go.


# 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.Gray);
# 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.Gray);
#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.Gray);
# End Volume PostMarket
 
appreciated
At risk of sounding redundant - In my experience, Rvol is relevant to the time frame its being used in. In other words, an Rvol length that provides good signal on a daily chart may not be as good on the 30m, and vice versa. You have to play with the lengths and look at different charts to find RVOL levels that capture the signal you're looking for based on time frames you use for charting.
 
@SuryaKiranC : Notice this $SPY 07/23 2D : 5m chart vol stats

Notice the bars @ 11 EST and 11:30 and @14::00 EST and 14:05. I am wondering why the 1st bar is taller than the 2nd bar and why is 3rd bar shorter than the 4th bar?

Also, I can probably go through the pages to find the color meaning, but if you know off the top of your head, what are the differences between different shades of both colors? (bight vs dark green for example)?

c3Tolaj.jpg
 
@SuryaKiranC : Notice this $SPY 07/23 2D : 5m chart vol stats

Notice the bars @ 11 EST and 11:30 and @14::00 EST and 14:05. I am wondering why the 1st bar is taller than the 2nd bar and why is 3rd bar shorter than the 4th bar?

Also, I can probably go through the pages to find the color meaning, but if you know off the top of your head, what are the differences between different shades of both colors? (bight vs dark green for example)?

c3Tolaj.jpg
Is that placed in the Volume area, or as a lower study? I use it in the volume area, not sure if that is the case. this is only plotting the Selling/Buying pressure on top of Volume when in volume area, that might be the issue you are facing.
-S
 
#Volume Data
plot 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;


Can someone assist me in rounding up the volume here? It shows volume in a column as a value (820545.07) instead of 820,545 (ticker: xbio). Thanks in advance
 
Code:
round(volume,0);
I have tried round (volume,0); and roundup (volume,0); & the background turns red & it reads below "useless function invocation". This is for a column (I am trying to have 30D average volume column, instead of plugging tickers in chart & looking up 30d average volume). Thanks @SuryaKiranC
 
Replace the whole thing with this, worry about the colors later.

plot 30DAvg = round(average(volume[1],30),0);
I tried this, it reads invalid statement plot at 2:1. This is for again for a custom column, I am trying to set custom column to show 30d average volume.
 
I tried this, it reads invalid statement plot at 2:1. This is for again for a custom column, I am trying to set custom column to show 30d average volume.
fine, Try this. you can add color condition, if you must with if statements.

AddLabel(yes,(round(average(Volume[1],30),0)));
 
Is there any way to know at what 'market price' the current volume bar exceeds the previous volume bar?
It's important to know this as it can trigger an entry...
You may need to look at something more than Volume Bar stat, Such as Volume Profiles, that can point out where the support/resistance are based of Volume. Not that I have anything to point you towards, but there is plenty of information available on Volume Profile Analysis. Start with some Youtube Videos.

-S
 
You may need to look at something more than Volume Bar stat, Such as Volume Profiles, that can point out where the support/resistance are based of Volume. Not that I have anything to point you towards, but there is plenty of information available on Volume Profile Analysis. Start with some Youtube Videos.

-S
Thanks Suryan I know everything about volume profile, but what I really need is a way to know the 'price' at the moment an study alert is triggered, is that possible?

E.g. If I set this ---> Alert(volume>volume[1], "VOLUME", Alert.BAR, Sound.Ring);

How could I know the market price when the 'Ring' is triggered? That's is key for any backtesting.
 
Thanks Suryan I know everything about volume profile, but what I really need is a way to know the 'price' at the moment an study alert is triggered, is that possible?

E.g. If I set this ---> Alert(volume>volume[1], "VOLUME", Alert.BAR, Sound.Ring);

How could I know the market price when the 'Ring' is triggered? That's is key for any backtesting.
Print the difference between Bid & Ask in the same alert, not sure how you will be able to trigger at the exact second you got the alert, but if information is all you are looking for that should give you what you are looking for.

Market price at the time of alert.
 
Print the difference between Bid & Ask in the same alert. Market price at the time of alert.
def Long = close>close[1] and volume>volume[1]; #Condition
def buySig = Long;
def buyPrice = if open[-1] and Long then open[-1] else close[-1]; #Here is where I need the market price instead of close[-1]

AddOrder(OrderType.BUY_TO_OPEN, buySig[-1], price = buyPrice, tradeSize = 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Buy");
 
def Long = close>close[1] and volume>volume[1]; #Condition
def buySig = Long;
def buyPrice = if open[-1] and Long then open[-1] else close[-1]; #Here is where I need the market price instead of close[-1]

AddOrder(OrderType.BUY_TO_OPEN, buySig[-1], price = buyPrice, tradeSize = 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Buy");
Yeah, that would be market difference between BID and ASK.
 
Thanks, but I can't see how and where should I insert that difference Bid-Ask formula?
Instead of close[-1] I've to write Bid[-1]-Ask[-1] ??

Note: you cannot reference historical data using this function, e.g. bid[1] is an invalid expression.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/bid
Here is an example from Buy_Auto. you would have to substitute with your own condition of-course.

AddOrder(OrderType.BUY_AUTO, close > close[1], open[-1], 50, Color.ORANGE, Color.ORANGE, "Sample buy @ " + open[-1]);

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder -s
 
Very nice script, thank you so much. I'd love to have the ability to set a specific timeframe for the volume stats instead of getting stats for the timeframe that is currently displayed on the chart. For example, I normally monitor 15m charts for setups but look for volume bursts on the 1m chart as one of the triggers - how can I display volume box stats for the 1m chart across charts of any timeframe?

Thanks in advance for your help, I really appreciate it.
 
Very nice script, thank you so much. I'd love to have the ability to set a specific timeframe for the volume stats instead of getting stats for the timeframe that is currently displayed on the chart. For example, I normally monitor 15m charts for setups but look for volume bursts on the 1m chart as one of the triggers - how can I display volume box stats for the 1m chart across charts of any timeframe?

Thanks in advance for your help, I really appreciate it.

@Shema Unfortunately, Thinkorswim only supports longer Aggregation Periods, not shorter Aggregation periods... For more information I will refer you the Chapter 11. Referencing Secondary Aggregation of the Thinkorswim Learning Center...
 
Is possible to cover this script to scan for the highest volume on a daily and 1h timeframe based on the 30-day average? For example, if today volume is over by 200% it should show up in the scan list.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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