RVOL Watchlist For ThinkOrSwim

hboogie

Active member
Plus
Hi all

after some tinkering, I wanted to share some code that gives me what I'm looking for specifically. Try it out and if there are enhancements or errors, let me know. Otherwise, enjoy.

I use it against a watchlist of stocks primarily.

Code:
# RVOL (Relative Volume) - Watchlist Column (lighter / no daily-agg)
# Today's cumulative volume / Expected cumulative at SAME intraday bar.
# Primary: average of prior days at same bar index.
# Lightweight fallback: use a very short intraday SMA of today's cumVol slope (keeps numbers moving without daily aggregation).
# Made for tos by hboogie.
# Sept 2026

input lookbackDays = 5;   # lighter than 20
input minSamples   = 3;    # fewer same-time samples required
input rthOpenTime  = 0930;
input rthCloseTime = 1600;

def inRTH = SecondsFromTime(rthOpenTime) >= 0 and SecondsTillTime(rthCloseTime) >= 0;

def aggMS      = GetAggregationPeriod();
def minsPerBar = aggMS / 60000;
def barsPerDay = Max(1, RoundDown(390 / minsPerBar, 0));

def ymd    = GetYYYYMMDD();
def newDay = ymd <> ymd[1];

# Bar index within the RTH session
rec barInDay = if newDay then 0 else if inRTH then barInDay[1] + 1 else barInDay[1];

# Today's cumulative volume (RTH only)
rec cumVol = if newDay then 0 else if inRTH then cumVol[1] + volume else cumVol[1];

# Average of prior days' cumVol at SAME bar index (primary estimator)
def sumCum =
fold d = 1 to lookbackDays + 1
    with s = 0
    do s + (if barInDay > 0 then GetValue(cumVol, d * barsPerDay) else Double.NaN);

def cntCum =
fold d2 = 1 to lookbackDays + 1
    with c = 0
    do c + (if barInDay > 0 and !IsNaN(GetValue(cumVol, d2 * barsPerDay)) then 1 else 0);

def avgCumSameTime = if cntCum > 0 then sumCum / cntCum else Double.NaN;

# Lightweight fallback: extrapolate from recent intraday pace (avoids daily aggregation)
# Use short SMA of delta(cumVol) to estimate what cumVol "should" be by now.
def pace = if barInDay > 0 then cumVol - cumVol[1] else 0;
def paceSMA = Average(pace, 5);                    # 5-bar smoothing
def expectedFromPace = Max(0, paceSMA * barInDay); # naive linear accumulation

def expectedCum =
    if cntCum >= minSamples and !IsNaN(avgCumSameTime) and avgCumSameTime > 0
    then avgCumSameTime
    else if expectedFromPace > 0 then expectedFromPace
    else Double.NaN;

def rvolRaw = if expectedCum > 0 then cumVol / expectedCum else Double.NaN;

plot RV = Round(rvolRaw, 2);

# Black text for readability
RV.AssignValueColor(Color.BLACK);

# Your requested color map:
# <1 gray; [1,2) yellow; [2,3) light green; [3,5) orange; >=5 blue
AssignBackgroundColor(
    if !inRTH or IsNaN(RV) then Color.GRAY
    else if RV >= 5 then Color.BLUE
    else if RV >= 3 then Color.ORANGE
    else if RV >= 2 then Color.LIGHT_GREEN
    else if RV >= 1 then Color.YELLOW
    else Color.GRAY
);

RV.HideTitle();
RV.HideBubble();
 

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
363 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