Time-Based Volume Indicator (RVOL) Request

ZackeryE21

New member
Hey! I was looking for a volume indicator that compares Today's Volume at Specified Time to the X Day Average Volume at Specified Time.

Basically comparing 9:30-10:30 Today's Volume Bar to the X Day Average of the 9:30-10:30 Volume Bar.

I'm looking for the indicator in this video:

Thanks much :)

[EDIT]
I found an indicator that does what I was looking for. It doesn't work on a 1 Minute Time-Frame though, which is fine for me:
https://usethinkscript.com/threads/time-based-volume-indicator-for-thinkorswim.124/

Here is the edited code to make it match the video:
Ruby:
declare lower;
input LookBack = 20;

def nMinutes = GetAggregationPeriod() / 60000;
def nBars = RoundUp(390 / nMinutes, 0);

def pvSum = fold idx = 1 to LookBack + 1 with a=0 do a + GetValue(volume, idx * nBars, LookBack * nBars);

def pvAvg = pvSum / LookBack;
def VolPct = (volume / pvAvg) * 100;

plot VeryHighVolume = 120;
VeryHighVolume.SetDefaultColor(CreateColor(0, 255, 0));
VeryHighVolume.SetStyle(Curve.LONG_DASH);
plot HighVolume = 110;
HighVolume.SetDefaultColor(CreateColor(0, 102, 0));
HighVolume.SetStyle(Curve.LONG_DASH);
plot VeryLowVolume = 80;
VeryLowVolume.SetDefaultColor(CreateColor(255, 0, 0));
VeryLowVolume.SetStyle(Curve.LONG_DASH);
plot LowVolume = 90;
LowVolume.SetDefaultColor(CreateColor(102, 0, 0));
LowVolume.SetStyle(Curve.LONG_DASH);

plot RelativeVolume = VolPct;
RelativeVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelativeVolume.DefineColor("Strong Bullish", CreateColor(0, 255, 0));
RelativeVolume.DefineColor("Bullish", CreateColor(0, 102, 0));
RelativeVolume.DefineColor("Strong Bearish", CreateColor(255, 0, 0));
RelativeVolume.DefineColor("Bearish", CreateColor(102, 0, 0));
RelativeVolume.DefineColor("Neutral", CreateColor(255, 255, 0));

RelativeVolume.AssignValueColor(
if (VolPct > VeryHighVolume) then RelativeVolume.Color("strong bullish" )
else if VeryHighVolume >= VolPct and VolPct >= HighVolume then RelativeVolume.Color("bullish" )
else if VolPct < VeryLowVolume then RelativeVolume.Color("strong bearish" )
else if VeryLowVolume <= VolPct and VolPct <= LowVolume then RelativeVolume.Color("bearish" )
else RelativeVolume.Color("neutral"));
RelativeVolume.SetLineWeight(3);

As of now when this indicator is used on the Daily Time-Frame it looks back X Bars to create an Average. How can I make a new indicator that matches This Day This Year to This Day Last Year for X Years back instead? And ideally this will work with Weeks and Months as well.

Thanks! :)
 
Last edited:
Solution
As of now when this indicator is used on the Daily Time-Frame it looks back X Bars to create an Average. How can I make a new indicator that matches This Day This Year to This Day Last Year for X Years back instead? And ideally this will work with Weeks and Months as well.

Well, let's start by asking a few questions, so that it's clear what you want to do.
1. "This day this year" ... does this mean
a. this trading day, this year (1 - 252)
b. this day number, this year (1 - 365 / 366) -- also known as Julian Date
c. this date (may 5)
d. the Monday of the seventh week of the year
Each of these has an implementation (some are way harder to achieve) and each one has a distinct advantage for looking at the market. I'd guess...
As of now when this indicator is used on the Daily Time-Frame it looks back X Bars to create an Average. How can I make a new indicator that matches This Day This Year to This Day Last Year for X Years back instead? And ideally this will work with Weeks and Months as well.

Well, let's start by asking a few questions, so that it's clear what you want to do.
1. "This day this year" ... does this mean
a. this trading day, this year (1 - 252)
b. this day number, this year (1 - 365 / 366) -- also known as Julian Date
c. this date (may 5)
d. the Monday of the seventh week of the year
Each of these has an implementation (some are way harder to achieve) and each one has a distinct advantage for looking at the market. I'd guess that (d) is the most useful but also the hardest to implement. While you're thinking about exactly what it is you're looking for, I'd suggest looking at these two I concocted at points in the past:

First up this one: https://usethinkscript.com/threads/...ing-and-forecasting-vtf-for-thinkorswim.2950/ but it's for intraday as well.

There's this one: https://usethinkscript.com/threads/projected-volume-first-9min-volume-100-5-5.11705/post-102442 which does volume based on the first n minutes of the day and may be of interest

I'll give some thought to your ideas. but at some point, I'd guess that thinkOrSwim is not the place for this kind of analysis. A database of closing prices and volume and some python might work better, and since you're looking at daily (fastest) and weekly or monthly data aggregations, it is quite possible to do you analysis in a python notebook and then trade in ThinkOrSwim separately. Perhaps. Perhaps not.

-mashume
 
Solution

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

Follow up post on option d from above:

To show how simple this is in python, here's a notebook that will show average volume by day by week for as far back as yfinance gives daily data (9000 + days):
https://colab.research.google.com/drive/1K5wdiEwccg7rynU9AyJJFLyv8qxY5llQ?usp=sharing

RNKWLH0.png


-mashume

P.S. For example (using CL Futures, as that's what I trade most of the time) here's a plot of the output of the above:
SE9AtPl.png
 
Last edited:
@mashume Might you be interested in regularly posting python notebooks of indicators used on the forum? I'm certain most are able to import data and display it graphically, but I am curious as to how one could port (if this is proper terminology) ToS indicators to python for backtesting. Could be interesting learning experiences.
 
@mashume would it be possible to convert tos scripts that have been posted here and convert them to python using maybe chat gpt? I know the difference between the two languages he is a big barrier but backtesting on python can give you much more detailed results than in tos. One thing is you’re bounded to a limit in tos if you want to backtest a timeframe below 5 min to only 30 days. It would be cool to have some kind of thread to convert the many useful indicators posted on here to python for backtesting purposes. @MerryDay wonder if this is something you can set up?
 
@mashume would it be possible to convert tos scripts that have been posted here and convert them to python using maybe chat gpt? I know the difference between the two languages he is a big barrier but backtesting on python can give you much more detailed results than in tos. One thing is you’re bounded to a limit in tos if you want to backtest a timeframe below 5 min to only 30 days. It would be cool to have some kind of thread to convert the many useful indicators posted on here to python for backtesting purposes. @MerryDay wonder if this is something you can set up?
Sharing code other than ThinkScript is beyond the bounds of the forum. We share thinkscripts.
In the past when python and other code has been shared; it has created problems for the 50k viewers who come here and assume all code can be cut and pasted into the ToS app.

@mashume's image is more than enough for python-minded coders to further their quest.
We will keep it limited to that.
 
Last edited:
Hey! I was looking for a volume indicator that compares Today's Volume at Specified Time to the X Day Average Volume at Specified Time.

Basically comparing 9:30-10:30 Today's Volume Bar to the X Day Average of the 9:30-10:30 Volume Bar.

I'm looking for the indicator in this video:

Thanks much :)

[EDIT]
I found an indicator that does what I was looking for. It doesn't work on a 1 Minute Time-Frame though, which is fine for me:
https://usethinkscript.com/threads/time-based-volume-indicator-for-thinkorswim.124/

Here is the edited code to make it match the video:
Ruby:
declare lower;
input LookBack = 20;

def nMinutes = GetAggregationPeriod() / 60000;
def nBars = RoundUp(390 / nMinutes, 0);

def pvSum = fold idx = 1 to LookBack + 1 with a=0 do a + GetValue(volume, idx * nBars, LookBack * nBars);

def pvAvg = pvSum / LookBack;
def VolPct = (volume / pvAvg) * 100;

plot VeryHighVolume = 120;
VeryHighVolume.SetDefaultColor(CreateColor(0, 255, 0));
VeryHighVolume.SetStyle(Curve.LONG_DASH);
plot HighVolume = 110;
HighVolume.SetDefaultColor(CreateColor(0, 102, 0));
HighVolume.SetStyle(Curve.LONG_DASH);
plot VeryLowVolume = 80;
VeryLowVolume.SetDefaultColor(CreateColor(255, 0, 0));
VeryLowVolume.SetStyle(Curve.LONG_DASH);
plot LowVolume = 90;
LowVolume.SetDefaultColor(CreateColor(102, 0, 0));
LowVolume.SetStyle(Curve.LONG_DASH);

plot RelativeVolume = VolPct;
RelativeVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelativeVolume.DefineColor("Strong Bullish", CreateColor(0, 255, 0));
RelativeVolume.DefineColor("Bullish", CreateColor(0, 102, 0));
RelativeVolume.DefineColor("Strong Bearish", CreateColor(255, 0, 0));
RelativeVolume.DefineColor("Bearish", CreateColor(102, 0, 0));
RelativeVolume.DefineColor("Neutral", CreateColor(255, 255, 0));

RelativeVolume.AssignValueColor(
if (VolPct > VeryHighVolume) then RelativeVolume.Color("strong bullish" )
else if VeryHighVolume >= VolPct and VolPct >= HighVolume then RelativeVolume.Color("bullish" )
else if VolPct < VeryLowVolume then RelativeVolume.Color("strong bearish" )
else if VeryLowVolume <= VolPct and VolPct <= LowVolume then RelativeVolume.Color("bearish" )
else RelativeVolume.Color("neutral"));
RelativeVolume.SetLineWeight(3);

As of now when this indicator is used on the Daily Time-Frame it looks back X Bars to create an Average. How can I make a new indicator that matches This Day This Year to This Day Last Year for X Years back instead? And ideally this will work with Weeks and Months as well.

Thanks! :)
Here is a version that works on the 1-minute chart.
declare lower;
input LookBack = 20;

def nBars = LookBack;

def pvSum = fold idx = 1 to LookBack + 1 with a = 0 do a + GetValue(volume, idx * nBars, LookBack * nBars);

def pvAvg = pvSum / LookBack;
def VolPct = (volume / pvAvg) * 100;

plot VeryHighVolume = 120;
VeryHighVolume.SetDefaultColor(CreateColor(0, 255, 0));
VeryHighVolume.SetStyle(Curve.LONG_DASH);
plot HighVolume = 110;
HighVolume.SetDefaultColor(CreateColor(0, 102, 0));
HighVolume.SetStyle(Curve.LONG_DASH);
plot VeryLowVolume = 80;
VeryLowVolume.SetDefaultColor(CreateColor(255, 0, 0));
VeryLowVolume.SetStyle(Curve.LONG_DASH);
plot LowVolume = 90;
LowVolume.SetDefaultColor(CreateColor(102, 0, 0));
LowVolume.SetStyle(Curve.LONG_DASH);

plot RelativeVolume = VolPct;
RelativeVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelativeVolume.DefineColor("Strong Bullish", CreateColor(0, 255, 0));
RelativeVolume.DefineColor("Bullish", CreateColor(0, 102, 0));
RelativeVolume.DefineColor("Strong Bearish", CreateColor(255, 0, 0));
RelativeVolume.DefineColor("Bearish", CreateColor(102, 0, 0));
RelativeVolume.DefineColor("Neutral", CreateColor(255, 255, 0));

RelativeVolume.AssignValueColor(
if (VolPct > VeryHighVolume) then RelativeVolume.Color("strong bullish")
else if VeryHighVolume >= VolPct and VolPct >= HighVolume then RelativeVolume.Color("bullish")
else if VolPct < VeryLowVolume then RelativeVolume.Color("strong bearish")
else if VeryLowVolume <= VolPct and VolPct <= LowVolume then RelativeVolume.Color("bearish")
else RelativeVolume.Color("neutral")
);
RelativeVolume.SetLineWeight(3);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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