Stochastic Smooth Relative Strength Index (SSRSI) For ThinkOrSwim

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

Hello Everyone,

Below is a not a very complicated code. Any coder out there can help convert from Tradingview to Thinkorswim
https://www.tradingview.com/script/YGspssrz-Stochastic-Smooth-Relative-Strength-Index-SSRSI/

Rich (BB code):
//@version=5
indicator('Relative Strength Index', 'RSI')

filter(float src, int len) =>
    var float filter = na
    filter := ta.cum((src + (src[1] * 2) + (src[2] * 2) + src[3])/6)
    (filter - filter[len])/len


len = input.int(8, 'Length', 1)
ex_sm = input.int(1, "Extra Smoothing", 1)
smooth_rsi = input.int(1, "Smooth RSI Filter", 1)
stoch_leng = input.int(13, "Stochastic Length", 1)
k = input.int(3, "K", 1)
smoothD = input.int(3, "D", 1)

rsi(src) =>
    up = math.sum(src > src[1] ? src - src[1] : 0, len)
    down = math.sum(src < src[1] ? src[1] - src : 0, len)
    rsi = up + down != 0 ? up / (up + down) : 0

Close = ta.sma(rsi(filter(close, smooth_rsi)), ex_sm)

stoch = ta.sma(ta.stoch(Close, Close, Close, stoch_leng), k)
d     = ta.sma(stoch, smoothD)


plot(stoch, color=color.new(color.purple, 0))
plot(d, "RSI-based MA", color=color.yellow)
rsiUpperBand = hline(80, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(20, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")

The link to tradingview is here link

Thank you so much
check the below

CSS:
# https://www.tradingview.com/v/YGspssrz/
#//@peacefulLizard50262
#indicator(Stochastic Smooth Relative Strength Index, 'SSRSI')
# Request from usethinkscript.com memeber
# Converted and mod by Sam4Cok@Samer800    - 07/2023
declare lower;

input len = 8;#, 'Length', 1)
input ex_sm = 1;#, "Extra Smoothing", 1)
input smooth_rsi = 1;#, "Smooth RSI Filter", 1)
input stoch_leng = 13;#, "Stochastic Length", 1)
input k = 3;#, "K", 1)
input smoothD = 3;#, "D", 1)

def na = Double.NaN;
def last = isNaN(close);

DefineGlobalColor("bg", CreateColor(48, 6, 80));
#filter(float src, int len) =>
script filter {
    input src = close;
    input len = 8;
    def srcSum = (src + (src[1] * 2) + (src[2] * 2) + src[3]);
    def filter = TotalSum(srcSum / 6);
    def filt = (filter - filter[len]) / len;
    plot out = filt;
}
#rsi(src) =>
script nRSI {
    input src = close;
    input len = 8;
    def up = Sum(if src > src[1] then src - src[1] else 0, len);
    def down = Sum(if src < src[1] then src[1] - src else 0, len);
    def rsi = if (up + down) != 0 then up / (up + down) else 0;
    plot out = rsi;
}
def filter = filter(close, smooth_rsi);
def nrsi = nRSI(filter, len);

def nClose = Average(nrsi , ex_sm);

def lowest_k = Lowest(nClose, stoch_leng);
def c1 = nClose - lowest_k;
def c2 = Highest(nClose, stoch_leng) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def stoch = Average(FastK, k);
def d     = Average(stoch, smoothD);

def crossUp = Crosses(stoch, d, CrossingDirection.ABOVE);
def crossDn = Crosses(stoch, d, CrossingDirection.BELOW);

plot stochK = stoch;
plot stochD = d;        # "RSI-based MA"
stochK.SetDefaultColor(Color.MAGENTA);
stochD.SetDefaultColor(Color.YELLOW);
stochK.SetLineWeight(2);
stochD.SetLineWeight(2);

plot SigUp = if crossUp then 15 else 0;
plot SigDn = if crossDn then 85 else 100;
SigUp.SetDefaultColor(Color.DARK_GREEN);
SigDn.SetDefaultColor(Color.DARK_RED);

plot rsiUpperBand = if last then na else 80;# "RSI Upper Band"
plot midhline = if last then na else 50;    # "RSI Middle Band"
plot rsiLowerBand = if last then na else 20;# "RSI Lower Band"

rsiUpperBand.SetDefaultColor(Color.GRAY);
midhline.SetDefaultColor(Color.DARK_GRAY);
rsiLowerBand.SetDefaultColor(Color.GRAY);
rsiUpperBand.SetStyle(Curve.MEDIUM_DASH);
midhline.SetStyle(Curve.SHORT_DASH);
rsiLowerBand.SetStyle(Curve.MEDIUM_DASH);

AddCloud(rsiUpperBand, rsiLowerBand, GlobalColor("bg"));

#---- End CODE
 
check the below

CSS:
# https://www.tradingview.com/v/YGspssrz/
#//@peacefulLizard50262
#indicator(Stochastic Smooth Relative Strength Index, 'SSRSI')
# Request from usethinkscript.com memeber
# Converted and mod by Sam4Cok@Samer800    - 07/2023
declare lower;

input len = 8;#, 'Length', 1)
input ex_sm = 1;#, "Extra Smoothing", 1)
input smooth_rsi = 1;#, "Smooth RSI Filter", 1)
input stoch_leng = 13;#, "Stochastic Length", 1)
input k = 3;#, "K", 1)
input smoothD = 3;#, "D", 1)

def na = Double.NaN;
def last = isNaN(close);

DefineGlobalColor("bg", CreateColor(48, 6, 80));
#filter(float src, int len) =>
script filter {
    input src = close;
    input len = 8;
    def srcSum = (src + (src[1] * 2) + (src[2] * 2) + src[3]);
    def filter = TotalSum(srcSum / 6);
    def filt = (filter - filter[len]) / len;
    plot out = filt;
}
#rsi(src) =>
script nRSI {
    input src = close;
    input len = 8;
    def up = Sum(if src > src[1] then src - src[1] else 0, len);
    def down = Sum(if src < src[1] then src[1] - src else 0, len);
    def rsi = if (up + down) != 0 then up / (up + down) else 0;
    plot out = rsi;
}
def filter = filter(close, smooth_rsi);
def nrsi = nRSI(filter, len);

def nClose = Average(nrsi , ex_sm);

def lowest_k = Lowest(nClose, stoch_leng);
def c1 = nClose - lowest_k;
def c2 = Highest(nClose, stoch_leng) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def stoch = Average(FastK, k);
def d     = Average(stoch, smoothD);

def crossUp = Crosses(stoch, d, CrossingDirection.ABOVE);
def crossDn = Crosses(stoch, d, CrossingDirection.BELOW);

plot stochK = stoch;
plot stochD = d;        # "RSI-based MA"
stochK.SetDefaultColor(Color.MAGENTA);
stochD.SetDefaultColor(Color.YELLOW);
stochK.SetLineWeight(2);
stochD.SetLineWeight(2);

plot SigUp = if crossUp then 15 else 0;
plot SigDn = if crossDn then 85 else 100;
SigUp.SetDefaultColor(Color.DARK_GREEN);
SigDn.SetDefaultColor(Color.DARK_RED);

plot rsiUpperBand = if last then na else 80;# "RSI Upper Band"
plot midhline = if last then na else 50;    # "RSI Middle Band"
plot rsiLowerBand = if last then na else 20;# "RSI Lower Band"

rsiUpperBand.SetDefaultColor(Color.GRAY);
midhline.SetDefaultColor(Color.DARK_GRAY);
rsiLowerBand.SetDefaultColor(Color.GRAY);
rsiUpperBand.SetStyle(Curve.MEDIUM_DASH);
midhline.SetStyle(Curve.SHORT_DASH);
rsiLowerBand.SetStyle(Curve.MEDIUM_DASH);

AddCloud(rsiUpperBand, rsiLowerBand, GlobalColor("bg"));

#---- End CODE
Thank you so much. Excellent conversion :)
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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