IBD Stock Charts Style and Scan for ThinkorSwim

Hello all, I'm trying to replicate the RS from IBD using Markos' code from 9-15-19 but when I plot it and double check it with IBD I get completely different numbers. For example, ticker DVN is showing RS of 5 but on IBD DVN has a RS of 91. What am I doing wrong?
@Be4Chst: your not doing anything wrong, you wont be able to find any script to match perfect with IBD. but it should be pretty close on most of the back checks
 
Hello all, I'm trying to replicate the RS from IBD using Markos' code from 9-15-19 but when I plot it and double check it with IBD I get completely different numbers. For example, ticker DVN is showing RS of 5 but on IBD DVN has a RS of 91. What am I doing wrong?
The issue is the RS line plotted is correct but the calculation of RS = 5 shown as a bubble as the end of the line is wrong due to the fact that calculation involves highest all of the entire dataset instead of High in last 252 days or 52week high.... hence it is calculation issue... not RS line plot issue....
 
The issue is the RS line plotted is correct but the calculation of RS = 5 shown as a bubble as the end of the line is wrong due to the fact that calculation involves highest all of the entire dataset instead of High in last 252 days or 52week high.... hence it is calculation issue... not RS line plot issue....
Is there a way to fix it so that it more accurately reflects the IBD RS? I feel like 5 and 91 is a big difference.
 
Is there a way to fix it so that it more accurately reflects the IBD RS? I feel like 5 and 91 is a big difference.
I think you're comparing apples to oranges unfortunately:( The script you mentioned generated a correct value of 5. It's the RS value and does not get compared to any other individual stocks, but it's compared to an index (i.e. SPX) only. However, the IBD RS Ranking value you gave is 91. It's a percentile value compared to all stocks in IBD database. The IBD RS Ranking is not a value just compared to one index but to all the stocks in the entire database. There is a separate indicator named as IBD RS (line, without the ranking) which compares the stock under investigation to an index!
 
This is a score for bottom 1% ranking. The negative score, which is not a percentile rank, indicates the stock has dropped in the time frame used by the script.
I'll provide more info on how to use it in the future when I get a chance.

@malone1020

I finally got some time to document the usage procedures of my script. As you probably know, it's different from other scripts in that it does provide a ranking percentile of the performance of a stock. I put it into my stock charts so that every time I pull up a stock chart, I get an idea about its performance ranking immediately as shown in the image below.
J35xoHm.png

The ranking number will be somewhat different from IBD's. For CAMT, I have 86 and IBD has 93 as of today.

The following is a picture illustrating all the important notes on how to use the script. It starts with the scan script to find the calibration data (rs_score).
qG8KMjN.png

Next, plug in the 3 recorded values of rs_score in the scan script into the main script as shown below.
EWpRw0K.png

Though there are quite a number of steps, but this is the only script I have for the RS ranking. Hopefully, the picture is worth a thousand words:)
I found it's OK to update the rs_score parameter only at the important market turning points.

The scan code is included in the original code I provided in my previous post. I extracted and put it below to make it easier for other people to use.
Code:
# IBD RS Scan Code Section Starts here
script my_rsrank {
# Set length to period of interest.
# Only total length of days is input and other periods are derived
input len4 = 252;
input cl =  close;

def len1 = round(len4/4, 0);   #63;
def len2 = len1 * 2; #126;
def len3 = len1 * 3; #189

# Calculate price change percentages per quarter
def p4q = (cl[len3]-cl[len4]) / cl[len4];
def p3q = (cl[len2]-cl[len3]) / cl[len3];
def p2q = (cl[len1]-cl[len2]) / cl[len2];
def p1q = (cl-cl[len1]) / cl[len1];
def weighted = ((2*p1q) + p2q + p3q + p4q) / 5;

plot rsrank = 100 * weighted;
}

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days
def len4 = 252;
# Use the following for 6 month period ranking
#def len4 = 126;

def stockCl = close;
def indexCl = close("SPX");

def stock_rsrank = my_rsrank(len4, stockCl);
#plot stockdbg = stock_rsrank;

def index_rsrank = my_rsrank(len4, indexCl);
#plot indexdbg = index_rsrank;

def index_rsrank1 = if (index_rsrank == 0, index_rsrank[1], index_rsrank);
def RS = stock_rsrank/index_rsrank1;

#------------------- Code required for Custom Quote in Scan Tab----------------
# Selectively uncomment the following code in scan tab
# The following RS scores as of today need to be adjusted in each periodical
# calibrations
# Possible RS scores for bottom 1%
#input rs_score = -1;
#input rs_score = -0.16;
# Possible RS scores for top 1%
#input rs_score = 4.5;
# Possible RS scores for top 10%
#input rs_score = 2.8;
input rs_score = 2.35;
plot scan = if rs_score <= 0 then rs < rs_score else
            rs > rs_score;
#---------------- End of Scan Code Section ------------------------------------
 
Can we create a watchlist to create the relative strength of the stock on the red days from last 6 months or 1 year. For example , If spy is red last 5 days , what is the %change change or growth of the stock ( postive or negative).

@BenTen @rad14733 @wtf_dude
 
Check out this very good RS indicator https://www.traderlion.com/thinkorswim-scripts/tos-relative-strength-line/

Code:
# Plot the Relative Strength Line in ThinkorSwim
# Written by: @Diamond_Stocks @RayTL_ - TLScripts
# Site:     https://www.traderlion.com/ https://www.traderlion.com/tl-scripts/
# V1

# Declare Lower Places a study on the lower subgraph. This declaration is used when your study uses values that are considerably lower or higher than price history or volume values.
declare lower;

# User Inputs
input show_RSNHBP = yes;
input show_RSNH = yes;

#Relative Strength Type - Candlestick to be added later.
input graphStyle = {default "Line"};

#3 Month, 6 Month, 1 Year RS
input TimeFrame = {default "Three_Months", "Six_Months", "1_Year"};

#Index SymbolRelation
input CorrelationWithSecurity = "SPX";

#Calculation TimeFrame
def aggregationperiod = AggregationPeriod.DAY;

#Chart Normalized Relative Strength Rating on Last Bar
def isLastBar = BarNumber() == HighestAll(if !IsNaN(close) then BarNumber() else Double.NaN);

#Turn on or off Alerts when cycling charts
input Alerts_On = yes;

#Add Chart Bubbble to Graph
input RS_Rating_ChartBubble = yes;

#Establish look back length:
def Length = if TimeFrame == TimeFrame.Three_Months then 63 else if TimeFrame == TimeFrame.Six_Months then 126 else 252;

#Get Index Close/Open/High/Low - Prep for Candlestick RS.
def indexopen = open(CorrelationWithSecurity, aggregationperiod);
def indexhigh = high(CorrelationWithSecurity, aggregationperiod);
def indexlow = low(CorrelationWithSecurity, aggregationperiod);
def indexclose = close(CorrelationWithSecurity, aggregationperiod);

#Get Relative Strength - Prep for Candlestick RS.
def RSopen = open / indexopen;
def RShigh = high / indexhigh;
def RSlow = low / indexlow;
def RSclose = close / indexclose;

def barCount = IF !IsNaN(close) THEN IF IsNaN(barCount[1]) THEN 1 ELSE barCount[1] + 1 ELSE barCount[1];

#Normalize Relative Strength
def newRngMax = 99; #Maximum normalized value
def newRngMin = 1; #Minimum normalized value

def HHDataclose = HighestAll(RSclose);
def LLDataclose = LowestAll(RSclose);
def HHDataopen = HighestAll(RSopen);
def LLDataopen = LowestAll(RSopen);
def HHDatalow = HighestAll(RSlow);
def LLDatalow = LowestAll(RSlow);
def HHDatahigh = HighestAll(RShigh);
def LLDatahigh = LowestAll(RShigh);

def normalizeRSclose = ((( newRngMax - newRngMin ) * ( RSclose - LLDataclose )) / ( HHDataclose - LLDataclose )) + newRngMin;
def normalizeRSopen = ((( newRngMax - newRngMin ) * ( RSopen - LLDataopen )) / ( HHDataopen - LLDataopen )) + newRngMin;
def normalizeRShigh = ((( newRngMax - newRngMin ) * ( RShigh - LLDatahigh )) / ( HHDatahigh - LLDatahigh )) + newRngMin;
def normalizeRSlow = ((( newRngMax - newRngMin ) * ( RSlow - LLDatalow )) / ( HHDatalow - LLDatalow )) + newRngMin;

#Chart RS Line and set appearence:
plot RSLine = RSclose;
RSLine.DefineColor("Positive", Color.UPTICK);
RSLine.DefineColor("Negative", Color.DOWNTICK);
RSLine.SetLineWeight(1);
RSLine.AssignValueColor(if RSLine[0] > RSLine[1] then CreateColor(43, 152, 242) else CreateColor(227, 88, 251));

#Get Highest RS Value
def highestRS = Highest(RSclose, Length);

#RSNHBPCondition
def RSNHBPcondition = if RSclose >= highestRS and close < Highest(close, Length) then highestRS else no;

#Plot RSNHBP Condition
plot RSNHBP = if show_RSNHBP and RSNHBPcondition == highestRS then highestRS else Double.NaN;

#Plot RSNH Condition
plot RSNH = if show_RSNH and RSNHBPcondition == no and RSclose == highestRS and isLastBar then highestRS else Double.NaN;

#Appearance Settings
RSNHBP.SetPaintingStrategy(PaintingStrategy.POINTS);
RSNHBP.SetLineWeight(2);
RSNHBP.SetDefaultColor(CreateColor(196, 94, 225));
RSNHBP.HideBubble();
RSNH.SetPaintingStrategy(PaintingStrategy.POINTS);
RSNH.SetDefaultColor(Color.GREEN);
RSNH.SetLineWeight(2);
RSNH.HideBubble();

#Add Chart Bubble for RS Rating
AddChartBubble(RS_Rating_ChartBubble and isLastBar, RSclose, "RS: " + Round(normalizeRSclose, 0),  Color.WHITE, no);

#Add Label
AddLabel(yes, Concat("Relative Strength: ", Round(normalizeRSclose, 0)), CreateColor(43, 152, 242));

#Alert Capability
Alert( if Alerts_On and RSNHBP then yes else no, "Relative Strength Line New Highs Before Price", Alert.BAR, Sound.Ding);
Alert(if Alerts_On and RSNH then yes else no, "Relative Strength Line New Highs", Alert.BAR, Sound.Chimes);
Do you think it would be possible to get the RS number in a watchlist column? Thanks.
 
Hi, may i know if there is a way to scan the relative strength of SPDR sector vs SPX? Eg I would like to know in the last 3months, which are the sectors that are performing better than SPX?

Thanks
Nick
 
@Nick You would need to compare all of the sectors, 11 as I recall, with SPX, and, optionally, SPY... I'm sure it's doable... What would your criteria be for "performing better"...???
 
@Nick You would need to compare all of the sectors, 11 as I recall, with SPX, and, optionally, SPY... I'm sure it's doable... What would your criteria be for "performing better"...???
Sector Perf from stockcharts.com

sectorspdr tracker

@rad14733 thank you for your question. Yes, i would like to compare all the sectors. I have this assumption is that the strongest sector also could imply more funds flowing into it. So for the criteria, i just want to know how did the sectors performed against SPX over the last 30 days. And then finding the strong stocks in that sector as potential candidate to trade. What I hope the TOS scanner generate the overall relative performance of each sectors.

The attached pics are showing which are the stocks that are stronger or weaker and I hope to use that observation to help me find trading opportunities.
I have also also searched within our community and came across few posts about sector rotations, but dont really know how to interpret them and put them into practice.

Thank you
 
Hello Everyone,

I was looking to see if anyone has a way of scanning the stocks in a particular index, like the S&P500, to look for stocks that are in an uptrend relative to the index itself. There is a video on youtube I referenced,

,

but when I tried to modify and use it I got stocks that appeared to be in both up and downtrends. Can some one take a look and see maybe where I went wrong and thanks for any insight as I am a raw beginner with thinkscript.

The code I used:

Code:
# RelativeStrengthUptrendScan

declare lower;

input CorrelationWithSecurity = "SPX";
input referenceDate = 20210101;
def close2 = close(CorrelationWithSecurity);

def RS = if close2 == 0 then 0 else close/close2;

def startDate = DaysFromDate(referenceDate) == 0;

addchartbubble(startDate, RS, "Start", color.RED);

def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);


def SRatio =  sr;

# use this plot statement to find stocks trending stronger than the index
plot Scan = lowest(RS - SRatio, 21) > 0;
 
Hi,
I have been using this scanner to find break outs, I like to apply this same concept to find stocks that are breaking out in relation to another symbol, in this case $SPX, how do I do this? TOS has an indicator called Relative Strength (pic below), I like to find symbols that are breakout out relative to another symbol.
Any help would greatly be appreciated.

Scanner Code:
#follow @KRose_TDA on twitter for updates to this and other custom scripts
#
#Script below is meant to find stocks breaking above a resistance point in the last 3 days.
#input the length of the lookback for resitance level broken into line 5 default is 15
Input Length = 15;
def price = close;
def HighPrice = fold counter = 2 to length with holder = 0 do if high[counter] > holder then high[counter] else holder;
plot trig = if (close[1]<highPrice and close > HighPrice)then 1 else if (close[2]<highPrice and close[1] > HighPrice and close > HighPrice)then 2 else if (close[3]<highPrice and close[2] > HighPrice and close > HighPrice)then 3 else 0;
-------------
Example:
xgIMvdK.jpg
 
Do you think it would be possible to get the RS number in a watchlist column? Thanks.
I was able to get it to work by just editing it myself, (I know very little coding). I get a message from TOS that its a complex script and could slow down performance but I have not seen much effect.
Code:
# Plot the Relative Strength Line in ThinkorSwim
# Written by: @Diamond_Stocks @RayTL_ - TLScripts
# Site:     https://www.traderlion.com/ https://www.traderlion.com/tl-scripts/
# V1

# User Inputs
input show_RSNHBP = yes;
input show_RSNH = yes;

#Relative Strength Type - Candlestick to be added later.
input graphStyle = {default "Line"};

#3 Month, 6 Month, 1 Year RS
input TimeFrame = {default "Three_Months", "Six_Months", "1_Year"};

#Index SymbolRelation
input CorrelationWithSecurity = "SPX";

#Calculation TimeFrame
def aggregationperiod = AggregationPeriod.DAY;

#Establish look back length:
def Length = if TimeFrame == TimeFrame.Three_Months then 63 else if TimeFrame == TimeFrame.Six_Months then 126 else 252;

#Get Index Close/Open/High/Low - Prep for Candlestick RS.
def indexopen = open(CorrelationWithSecurity, aggregationperiod);
def indexhigh = high(CorrelationWithSecurity, aggregationperiod);
def indexlow = low(CorrelationWithSecurity, aggregationperiod);
def indexclose = close(CorrelationWithSecurity, aggregationperiod);

#Get Relative Strength - Prep for Candlestick RS.
def RSopen = open / indexopen;
def RShigh = high / indexhigh;
def RSlow = low / indexlow;
def RSclose = close / indexclose;

def barCount = IF !IsNaN(close) THEN IF IsNaN(barCount[1]) THEN 1 ELSE barCount[1] + 1 ELSE barCount[1];

#Normalize Relative Strength
def newRngMax = 99; #Maximum normalized value
def newRngMin = 1; #Minimum normalized value

def HHDataclose = HighestAll(RSclose);
def LLDataclose = LowestAll(RSclose);
def HHDataopen = HighestAll(RSopen);
def LLDataopen = LowestAll(RSopen);
def HHDatalow = HighestAll(RSlow);
def LLDatalow = LowestAll(RSlow);
def HHDatahigh = HighestAll(RShigh);
def LLDatahigh = LowestAll(RShigh);

def normalizeRSclose = ((( newRngMax - newRngMin ) * ( RSclose - LLDataclose )) / ( HHDataclose - LLDataclose )) + newRngMin;
def normalizeRSopen = ((( newRngMax - newRngMin ) * ( RSopen - LLDataopen )) / ( HHDataopen - LLDataopen )) + newRngMin;
def normalizeRShigh = ((( newRngMax - newRngMin ) * ( RShigh - LLDatahigh )) / ( HHDatahigh - LLDatahigh )) + newRngMin;
def normalizeRSlow = ((( newRngMax - newRngMin ) * ( RSlow - LLDatalow )) / ( HHDatalow - LLDatalow )) + newRngMin;

#Get Highest RS Value
def highestRS = Highest(RSclose, Length);



#Add Label
AddLabel(yes,Round(normalizeRSclose, 0), CreateColor(43, 152, 242));
 

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