Relative Volume For ThinkOrSwim

zack3d_

New member
VIP
The author states:
Volume can be a very useful tool if used correctly. Relative volume is designed to filter out the noise and highlight anomalies assisting traders in tracking institutional movements. This tool can be used to identify stop loss hunters and organized dumps. It uses a variety of moving averages to hide usual activity and features an LSMA line to show trend. Trend columns are shown to highlight activity and can be seen at bottom of the volume columns, this is done using ZLSMA and LSMA.

ILTaPDK.png


Hello, relative volume has been a helpful indicator for me and I find this RVOL on tradingview to be very good. I have tried to convert the code from pinescript to thinkscript but have not been successful. Any assistance would be appreciated!

https://www.tradingview.com/script/rZpNXicF-Relative-Volume/

Thank you in advance!
 
Last edited by a moderator:

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

Hello, relative volume has been a helpful indicator for me and I find this RVOL on tradingview to be very good. I have tried to convert the code from pinescript to thinkscript but have not been successful. Any assistance would be appreciated!

https://www.tradingview.com/script/rZpNXicF-Relative-Volume/

Thank you in advance!
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © veryfid
#study("Relative Volume", shorttitle="RVOL", format = format.volume)
# Converted by Sam4Cok@Samer800    - 03/2024
declare lower;

input lsmalength = 50; #,"LSMA Length",group = "General Settings")
input avglength = 30; #,"Lookback bars for Average",group = "General Settings")
input volalert = 200000000; #, title = "Alert when volume reaches",group = "General Settings")
input showEntrySignals = yes; #(true, "Show Entry Signals?",group = "Entry Signals")
input showRvol = no; #(false, "Show RVOL Calculation?",group = "General Settings")
input showLsma21 = yes; #(true,"Show LSMA 21 Entry Points", group = "Entry Signals")
input showLsma6 = yes; #(true,"Show LSMA 6 Entry Points",group = "Entry Signals")
input showAnomalies = yes; #(true, "Show Anomalies",group = "General Settings")
input ShowTrendColumns = no; #(false, title = "Show Trend Columns",group = "General Settings")

def na = Double.NaN;
DefineGlobalColor("up", CreateColor(0,255,170));
DefineGlobalColor("dn", CreateColor(255,82,82));
DefineGlobalColor("yel",CreateColor(255,235,59));
DefineGlobalColor("bg", CreateColor(10, 109, 187));
    
############## ALMA
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
def len = 20;
def src = volume;
def hh = highest(src , 100);
def ma1 = Average(src, len);
def ma2 = Inertia(src, lsmalength);
def ma3 = Inertia(src, 21);
def ma4 = Inertia(src, 6);

def length = 21;
def std = 21;
def hullma = HullMovingAvg(src, length);
def windowsize = 9;
def offset = 0.85;
def sigma = 6;
def lsma2 = Inertia(ma2, len);
def a = ma2 - lsma2;
def zlsma = ma2 + a;
def almaMov = ALMA(src, windowsize, offset, sigma);
def stdv = stdev(src, std);
def dif = zlsma - ma2;
def clean = src - ma2;
#cond1 = crossover(ma2,0)
def cond1 = if showlsma21 and !showlsma6 then (ma2 crosses above 0) or (ma3  crosses above 0) else
            if showlsma6 and !showlsma21 then (ma2  crosses above 0) or (ma4  crosses above 0) else
            if showlsma6 and showlsma21 then (ma2  crosses above 0) or (ma3  crosses above 0) or (ma4  crosses above 0) else
            (ma2  crosses above 0);
def cond2 = (src  crosses above volalert);
def cond3 = src > ma2;

AddCloud(almaMov, 0, GlobalColor("bg"), GlobalColor("bg"), yes);
AddCloud(stdv, 0, GlobalColor("bg"), GlobalColor("bg"), yes);
AddCloud(ma1, 0, GlobalColor("bg"), GlobalColor("bg"), yes);

plot EntrySignal = if showEntrySignals and cond1 then hh else na; # "Entry Signal"
plot Anomalies = if showAnomalies and clean > stdv then src else na; # "Entry Signal"
plot TrendColumns = if ShowTrendColumns and dif > 0 then dif else na; # #fff9c4, title = "Trend Columns")
plot LSMA = ma2; # "LSMA"
plot volHist = src;     # "Volume"

EntrySignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
EntrySignal.SetDefaultColor(GlobalColor("yel"));
Anomalies.AssignValueColor(if close > open then GlobalColor("up") else  GlobalColor("dn"));
Anomalies.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
TrendColumns.SetDefaultColor(GlobalColor("yel"));
TrendColumns.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
LSMA.SetDefaultColor(Color.WHITE);
volHist.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
volHist.AssignValueColor(if close > open then GlobalColor("up") else  GlobalColor("dn"));

def avg = Average(src[1], avglength);
def rvol = src / avg;

AddLabel(showrvol, "RVOL(" + Round(rvol, 2) + ")", Color.WHITE);
#-- END of CODE
 
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © veryfid
#study("Relative Volume", shorttitle="RVOL", format = format.volume)
# Converted by Sam4Cok@Samer800    - 03/2024
declare lower;

input lsmalength = 50; #,"LSMA Length",group = "General Settings")
input avglength = 30; #,"Lookback bars for Average",group = "General Settings")
input volalert = 200000000; #, title = "Alert when volume reaches",group = "General Settings")
input showEntrySignals = yes; #(true, "Show Entry Signals?",group = "Entry Signals")
input showRvol = no; #(false, "Show RVOL Calculation?",group = "General Settings")
input showLsma21 = yes; #(true,"Show LSMA 21 Entry Points", group = "Entry Signals")
input showLsma6 = yes; #(true,"Show LSMA 6 Entry Points",group = "Entry Signals")
input showAnomalies = yes; #(true, "Show Anomalies",group = "General Settings")
input ShowTrendColumns = no; #(false, title = "Show Trend Columns",group = "General Settings")

def na = Double.NaN;
DefineGlobalColor("up", CreateColor(0,255,170));
DefineGlobalColor("dn", CreateColor(255,82,82));
DefineGlobalColor("yel",CreateColor(255,235,59));
DefineGlobalColor("bg", CreateColor(10, 109, 187));
   
############## ALMA
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
def len = 20;
def src = volume;
def hh = highest(src , 100);
def ma1 = Average(src, len);
def ma2 = Inertia(src, lsmalength);
def ma3 = Inertia(src, 21);
def ma4 = Inertia(src, 6);

def length = 21;
def std = 21;
def hullma = HullMovingAvg(src, length);
def windowsize = 9;
def offset = 0.85;
def sigma = 6;
def lsma2 = Inertia(ma2, len);
def a = ma2 - lsma2;
def zlsma = ma2 + a;
def almaMov = ALMA(src, windowsize, offset, sigma);
def stdv = stdev(src, std);
def dif = zlsma - ma2;
def clean = src - ma2;
#cond1 = crossover(ma2,0)
def cond1 = if showlsma21 and !showlsma6 then (ma2 crosses above 0) or (ma3  crosses above 0) else
            if showlsma6 and !showlsma21 then (ma2  crosses above 0) or (ma4  crosses above 0) else
            if showlsma6 and showlsma21 then (ma2  crosses above 0) or (ma3  crosses above 0) or (ma4  crosses above 0) else
            (ma2  crosses above 0);
def cond2 = (src  crosses above volalert);
def cond3 = src > ma2;

AddCloud(almaMov, 0, GlobalColor("bg"), GlobalColor("bg"), yes);
AddCloud(stdv, 0, GlobalColor("bg"), GlobalColor("bg"), yes);
AddCloud(ma1, 0, GlobalColor("bg"), GlobalColor("bg"), yes);

plot EntrySignal = if showEntrySignals and cond1 then hh else na; # "Entry Signal"
plot Anomalies = if showAnomalies and clean > stdv then src else na; # "Entry Signal"
plot TrendColumns = if ShowTrendColumns and dif > 0 then dif else na; # #fff9c4, title = "Trend Columns")
plot LSMA = ma2; # "LSMA"
plot volHist = src;     # "Volume"

EntrySignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
EntrySignal.SetDefaultColor(GlobalColor("yel"));
Anomalies.AssignValueColor(if close > open then GlobalColor("up") else  GlobalColor("dn"));
Anomalies.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
TrendColumns.SetDefaultColor(GlobalColor("yel"));
TrendColumns.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
LSMA.SetDefaultColor(Color.WHITE);
volHist.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
volHist.AssignValueColor(if close > open then GlobalColor("up") else  GlobalColor("dn"));

def avg = Average(src[1], avglength);
def rvol = src / avg;

AddLabel(showrvol, "RVOL(" + Round(rvol, 2) + ")", Color.WHITE);
#-- END of CODE
This is awesome! Thank you very much @samer800
 
Hello, samer800...I copied and pasted the thinkscript in my TOS platform and I get an AddLable error:
"AddLabel is not allowed in this context"
Any idea what went wrong?
 
Hello, samer800...I copied and pasted the thinkscript in my TOS platform and I get an AddLable error:
"AddLabel is not allowed in this context"
Any idea what went wrong?
This script was created for adding to your charts.

The error that you are seeing occurs when you are attempting to add a chart script to a ToS widget.
If you are attempting to use this study in the scan hacker widget, here is a tutorial:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
 
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © veryfid
#study("Relative Volume", shorttitle="RVOL", format = format.volume)
# Converted by Sam4Cok@Samer800    - 03/2024
declare lower;

input lsmalength = 50; #,"LSMA Length",group = "General Settings")
input avglength = 30; #,"Lookback bars for Average",group = "General Settings")
input volalert = 200000000; #, title = "Alert when volume reaches",group = "General Settings")
input showEntrySignals = yes; #(true, "Show Entry Signals?",group = "Entry Signals")
input showRvol = no; #(false, "Show RVOL Calculation?",group = "General Settings")
input showLsma21 = yes; #(true,"Show LSMA 21 Entry Points", group = "Entry Signals")
input showLsma6 = yes; #(true,"Show LSMA 6 Entry Points",group = "Entry Signals")
input showAnomalies = yes; #(true, "Show Anomalies",group = "General Settings")
input ShowTrendColumns = no; #(false, title = "Show Trend Columns",group = "General Settings")

def na = Double.NaN;
DefineGlobalColor("up", CreateColor(0,255,170));
DefineGlobalColor("dn", CreateColor(255,82,82));
DefineGlobalColor("yel",CreateColor(255,235,59));
DefineGlobalColor("bg", CreateColor(10, 109, 187));
   
############## ALMA
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
def len = 20;
def src = volume;
def hh = highest(src , 100);
def ma1 = Average(src, len);
def ma2 = Inertia(src, lsmalength);
def ma3 = Inertia(src, 21);
def ma4 = Inertia(src, 6);

def length = 21;
def std = 21;
def hullma = HullMovingAvg(src, length);
def windowsize = 9;
def offset = 0.85;
def sigma = 6;
def lsma2 = Inertia(ma2, len);
def a = ma2 - lsma2;
def zlsma = ma2 + a;
def almaMov = ALMA(src, windowsize, offset, sigma);
def stdv = stdev(src, std);
def dif = zlsma - ma2;
def clean = src - ma2;
#cond1 = crossover(ma2,0)
def cond1 = if showlsma21 and !showlsma6 then (ma2 crosses above 0) or (ma3  crosses above 0) else
            if showlsma6 and !showlsma21 then (ma2  crosses above 0) or (ma4  crosses above 0) else
            if showlsma6 and showlsma21 then (ma2  crosses above 0) or (ma3  crosses above 0) or (ma4  crosses above 0) else
            (ma2  crosses above 0);
def cond2 = (src  crosses above volalert);
def cond3 = src > ma2;

AddCloud(almaMov, 0, GlobalColor("bg"), GlobalColor("bg"), yes);
AddCloud(stdv, 0, GlobalColor("bg"), GlobalColor("bg"), yes);
AddCloud(ma1, 0, GlobalColor("bg"), GlobalColor("bg"), yes);

plot EntrySignal = if showEntrySignals and cond1 then hh else na; # "Entry Signal"
plot Anomalies = if showAnomalies and clean > stdv then src else na; # "Entry Signal"
plot TrendColumns = if ShowTrendColumns and dif > 0 then dif else na; # #fff9c4, title = "Trend Columns")
plot LSMA = ma2; # "LSMA"
plot volHist = src;     # "Volume"

EntrySignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
EntrySignal.SetDefaultColor(GlobalColor("yel"));
Anomalies.AssignValueColor(if close > open then GlobalColor("up") else  GlobalColor("dn"));
Anomalies.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
TrendColumns.SetDefaultColor(GlobalColor("yel"));
TrendColumns.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
LSMA.SetDefaultColor(Color.WHITE);
volHist.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
volHist.AssignValueColor(if close > open then GlobalColor("up") else  GlobalColor("dn"));

def avg = Average(src[1], avglength);
def rvol = src / avg;

AddLabel(showrvol, "RVOL(" + Round(rvol, 2) + ")", Color.WHITE);
#-- END of CODE

Is it possible to make this code based on volume average the last X amount of days?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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