Relative Strength (IBD Style) For ThinkOrSwim

Champ

New member
mod note:
according to the comments on Tradingview; this indicator is no longer performing correctly

Oi74osM.png


Here is the original Tradingview code:
https://www.tradingview.com/script/SHE1xOMC-Relative-Strength-IBD-Style/


For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:

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

Looking for help converting this pine script to TOS. Appreciate if someone can convert and help me with the scanner for thinorswim

https://www.tradingview.com/script/SHE1xOMC-Relative-Strength-IBD-Style/
check the below:

CSS:
#// Indicator for TOS
#// @Author: Skyte
#indicator(title="Relative Strength (IBD Style)", shorttitle="RS", format=format.percent, max_bars_back=260)
# Converted by Sam4Cok@Samer800    - 01/2025
declare lower;

input ref_input = "SPY"; #("SPY", title="Reference")

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

#// use more recent quarters if data for full year is not available
script quarter_perf {
    input data = close;
    input n = 1;
    def qYear = 252 / 4;
    def refCandle; def baseCandle; def i;
    def i1 = CompoundValue(1, i[1], n);
    def refCandle1  = CompoundValue(1, refCandle[1] , n * qYear);
    def baseCandle1 = CompoundValue(1, baseCandle[1], (n - 1) * qYear);
    if GetValue(data, refCandle1)  {
        i = n;
        refCandle = n * qYear;
        baseCandle = (n - 1) * qYear;
    } else {
        i = if i1[1] > 1 then i1 - 1 else 1;
        refCandle = i * qYear;
        baseCandle = (i - 1) * qYear;
    }
    def quarter_perf = (GetValue(data, baseCandle) - GetValue(GetValue(data, baseCandle), refCandle)) /
                        GetValue(GetValue(data, baseCandle), refCandle) * 100;
    plot out = quarter_perf;
}

#// first quarter is weighted more
def quarter = AggregationPeriod.QUARTER;
def q1S = quarter_perf(stock, 1);
def q2S = quarter_perf(stock, 2);
def q3S = quarter_perf(stock, 3);
def q4S = quarter_perf(stock, 4);
def q1R = quarter_perf(ref, 1);
def q2R = quarter_perf(ref, 2);
def q3R = quarter_perf(ref, 3);
def q4R = quarter_perf(ref, 4);

def stock_performance = 0.4 * q1S + 0.2 * q2S + 0.2 * q3S + 0.2 * q4S;
def ref_performance   = 0.4 * q1R + 0.2 * q2R + 0.2 * q3R + 0.2 * q4R;
def rs = (stock_performance - ref_performance)/ref_performance * 100;

#-- plot

plot RelativeStrength = if !last then rs else na; #, title="Relative Strength", color=plot_color, linewidth=2)
def zeroLine = if !last then 0 else na;

RelativeStrength.SetLineWeight(2);
RelativeStrength.AssignValueColor(if rs >= zeroLine then Color.GREEN else Color.RED);

AddCloud(rs, zeroLine, Color.GREEN, Color.RED);


#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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