Jurik RSX "noise free RSI" for ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
"noise free" version of RSI.
I modified the original code and added dynamic band and divergence.
Use this indicator just like RSI . I have set the default length to 14, feel free to experiment. You can reduce length with out worrying about jaggedness.

T5BOsZO.png


Rich (BB code):
#// Copyright (c) 2019-present, Alex Orekhov (everget)
#// Jurik RSX script may be freely distributed under the MIT license.
#https://www.tradingview.com/script/20TzvKPk-Jurik-RSX/
#http://www.jurikres.com/catalog1/ms_rsx.htm
#study("Jurik RSX", shorttitle="RSX")
# Converted and Mod by Sam4COK @ Samer800 07/31/2022

declare lower;
input BarColor = no;
input ShowDiv  = yes;
input highlightBreakouts = yes; # "Highlight Overbought/Oversold Breakouts ?"
input rsxLength = 14;           # "rsx Length"
input src = hlc3;               # "Source"
input obLevel = 70;             # "OB Level"
input osLevel = 30;             # "OS Level"
input maType    =  {"WMA", default "SMA", "EMA", "HMA", "SMMA"}; # "MA Type"
input maLength  = 69;           # "MA Length"
input DynamicBand = yes;
input bandType  =  {default "WMA", "SMA", "EMA", "HMA", "SMMA"}; # "Dynamic Band Type"
input DynamicPerios  = 100;
input DynamicPerCent = 90;

def na = Double.NaN;

########## Colors ########
DefineGlobalColor("red"     , CreateColor(255,0,0));
DefineGlobalColor("Melon"    , CreateColor(244,183,125));
DefineGlobalColor("green"   , CreateColor(14,187,35));
DefineGlobalColor("yellow"  , CreateColor(231,190,0));
########### SCRIPT
#ma(source, length, type) =>
script ma {
    input source = close;
    input length = 0;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(source, length) else
     if type == "EMA" then ExpAverage(source, length) else
     if type == "WMA" then WMA(source, length) else
     if type == "HMA" then WMA(2 * WMA(source, length / 2) - WMA(source, length), Round(Sqrt(length)))
       else WildersAverage(source, length);
    plot result = ma;
}
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
def f8 = 100 * src;
def f10 = nz(f8[1]);
def v8 = f8 - f10;
def f18 = 3 / (rsxLength + 2);
def f20 = 1 - f18;
def f28 = f20 * nz(f28[1]) + f18 * v8;
def f30 = f18 * f28 + f20 * nz(f30[1]);
def vC = f28 * 1.5 - f30 * 0.5;
def f38 = f20 * nz(f38[1]) + f18 * vC;
def f40 = f18 * f38 + f20 * nz(f40[1]);
def v10 = f38 * 1.5 - f40 * 0.5;
def f48 = f20 * nz(f48[1]) + f18 * v10;
def f50 = f18 * f48 + f20 * nz(f50[1]);
def v14 = f48 * 1.5 - f50 * 0.5;
def f58 = f20 * nz(f58[1]) + f18 * AbsValue(v8);
def f60 = f18 * f58 + f20 * nz(f60[1]);
def v18 = f58 * 1.5 - f60 * 0.5;
def f68 = f20 * nz(f68[1]) + f18 * v18;
def f70 = f18 * f68 + f20 * nz(f70[1]);
def v1C = f68 * 1.5 - f70 * 0.5;
def f78 = f20 * nz(f78[1]) + f18 * v1C;
def f80 = f18 * f78 + f20 * nz(f80[1]);
def v20 = f78 * 1.5 - f80 * 0.5;
def f88;
def f90_ = if nz(f90_[1]) == 0 then 1 else if nz(f88[1]) <= nz(f90_[1]) then nz(f88[1]) + 1 else nz(f90_[1]) + 1;
f88 = if nz(f90_[1]) == 0 and (rsxLength - 1 >= 5) then rsxLength - 1 else 5;
def f0 = if f88 >= f90_ and f8 != f10 then 1 else 0;
def f90 = if f88 == f90_ and f0 == 0 then 0 else f90_;
def v4_ = if f88 < f90 and v20 > 0 then (v14 / v20 + 1) * 50 else 50;

def rsx = if v4_ > 100 then 100 else if v4_ < 0 then 0 else v4_;

plot RSXLine = rsx;
RSXLine.SetLineWeight(2);
RSXLine.AssignValueColor(if rsx > obLevel then GlobalColor("green") else
                         if rsx < osLevel then GlobalColor("red") else GlobalColor("Melon"));

plot obLevelPlot = obLevel;             # "Overbought Level"
obLevelPlot.SetStyle(Curve.MEDIUM_DASH);
obLevelPlot.SetDefaultColor(GlobalColor("red"));
obLevelPlot.SetHiding(DynamicBand);
obLevelPlot.HideTitle();
plot osLevelPlot = osLevel;             # "Oversold Level"
osLevelPlot.SetStyle(Curve.MEDIUM_DASH);
osLevelPlot.SetDefaultColor(GlobalColor("green"));
osLevelPlot.SetHiding(DynamicBand);
osLevelPlot.HideTitle();

plot mid = 50;                          # "Middle Level"
mid.SetStyle(Curve.SHORT_DASH);
mid.SetDefaultColor(Color.GRAY);
mid.SetHiding(DynamicBand);
mid.HideTitle();

AddCloud(if DynamicBand then na else obLevelPlot, osLevelPlot, Color.dark_gray);
AddCloud(if highlightBreakouts and rsx > obLevel then 100 else na, obLevel, Color.GREEN);
AddCloud(if highlightBreakouts and rsx < osLevel then 0 else na, osLevel, Color.RED);

### DynamicBand
def rsxMA = ma(rsx, maLength, maType);
def offs = (1.6185 * StDev(rsx, DynamicPerios));
def upBand = rsxMA + offs;
def dnBand = rsxMA - offs;

plot rsxAvg = rsxMA;
rsxAvg.SetDefaultColor(GlobalColor("yellow"));
plot Oband = upBand;
Oband.SetDefaultColor(Color.GRAY);
Oband.SetHiding(!DynamicBand);
plot Sband = dnBand;
Sband.SetDefaultColor(Color.GRAY);
Sband.SetHiding(!DynamicBand);

addcloud(if DynamicBand then if rsx > Oband then rsx else na else na, Oband, color.GREEN, color.GREEN, no);
addcloud(if DynamicBand then if rsx < Sband then rsx else na else na, Sband, color.RED, color.RED, no);
addcloud(if DynamicBand then Oband else na, Sband, Color.DARK_GRAY);

#### Bar Color
def Exup = rsx > rsxMA and rsx > upBand;
def Up   = rsx > rsxMA and rsx < upBand;
def ExDn = rsx < rsxMA and rsx < dnBand;
def Dn   = rsx < rsxMA and rsx > dnBand;

AssignPriceColor( if BarColor then if Exup then color.green else
                                   if Up   then color.dark_green else
                                   if ExDn then Color.RED else
                                   Color.Dark_RED else Color.Current);
##### DIVERGANCE
def bar = BarNumber();
def n = rsxLength;
def CurrH = if rsx > obLevel
                then fold i = 1 to Floor(n / 2)
                with p = 1
                while p
                do rsx > GetValue(rsx, -i)
                else 0;

def CurrPivotH = if (bar > n and
                         rsx == Highest(rsx, Floor(n / 2)) and CurrH) then rsx else na;

def CurrL = if rsx < osLevel
                then fold j = 1 to Floor(n / 2)
                with q = 1
                while q
                do rsx < GetValue(rsx, -j)
                else 0;

def CurrPivotL =  if (bar > n and
                         rsx == Lowest(rsx, Floor(n / 2)) and CurrL) then rsx else na;

def CurrPHBar = if !IsNaN(CurrPivotH) then bar else CurrPHBar[1];
def CurrPLBar = if !IsNaN(CurrPivotL) then bar else CurrPLBar[1];

def PHpoint = if !IsNaN(CurrPivotH) then CurrPivotH else PHpoint[1];
def PLpoint = if !IsNaN(CurrPivotL) then CurrPivotL else PLpoint[1];

def priorPHBar = if PHpoint != PHpoint[1] then CurrPHBar[1] else priorPHBar[1];
def priorPLBar = if PLpoint != PLpoint[1] then CurrPLBar[1] else priorPLBar[1];

def HighPivots = bar >= HighestAll(priorPHBar);
def LowPivots  = bar >= HighestAll(priorPLBar);

def pivotHigh = if HighPivots then CurrPivotH else na;
def pivotLow  = if LowPivots  then CurrPivotL else na;

plot PlotHline = pivotHigh;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.RED);
PlotHline.SetStyle(Curve.SHORT_DASH);
PlotHline.SetHiding(!ShowDiv);

plot PlotLline = pivotLow;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.LIME);
PlotLline.SetStyle(Curve.SHORT_DASH);
PlotLline.SetHiding(!ShowDiv);

plot PivotDot = if !IsNaN(pivotHigh) then pivotHigh else
                if !IsNaN(pivotLow)  then pivotLow  else na;
PivotDot.SetDefaultColor(Color.YELLOW);
PivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotDot.SetLineWeight(3);
PivotDot.SetHiding(!ShowDiv);

#### END Code
 
Last edited by a moderator:
Could anyone modify the script to show arrows, where ordinarily the "highlight breakouts" would normally appear? The highlight function does not work on the mobile app, and I would think it would function if arrows were used. Thank you for any assistance. This is a great indicator!
 

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