IBD Stock Charts Style and Scan for ThinkorSwim

What I use is the IBD 50 list from Here and run a TMO scan for OS and look for an entry. If you join IBD Digital(for $35 a month I believe) You get High RS, Stock Sptlight, Large Caps 20, New 52 Week High and other lists. I just update my IBD 50 once or twice a week. Hope this helps someone

I also use 20 day average volume above 1Million and price above 200EMA. Works for me for Swing trades.
Hi King, thanks for your valuable inputs , do you know how often IBD Digital gets updated
 

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

Hi King, thanks for your valuable inputs , do you know how often IBD Digital gets updated
@Kitchasap They update lists Monday-Friday I believe. They offer a free trial if you're interested. You can even search for your own stocks and it'll tell you what they've scored for the stock. It's a good subscription to learn about different companies and to see how strong stocks behave
 
@Kitchasap They update lists Monday-Friday I believe. They offer a free trial if you're interested. You can even search for your own stocks and it'll tell you what they've scored for the stock. It's a good subscription to learn about different companies and to see how strong stocks behave
Thanks King, I will look into those..
 
Below is the chart setup for ThinkorSwim inspired by IBD (Investor's Business Daily) stocks chart. Also, a watchlist column and the Relative Strength (RS) indicator.

Updated 9-5-19

In this shared Google Drive are 2 files: https://drive.google.com/drive/folders/13XOHAGuDNjx6k98U5VB8AL2TmQOjyQqS?usp=sharing
  • A file comparison of yesterdays IBD Relative Strength direct from IBD, along with a listing of what the watchlist code reads for the same security. If you follow the stocks in IBD's 85-85 list, my hope is that you would find most of them ranked above 70 in the watchlist column.
  • The picture is of the watchlist code on the right on my screen shot of the same NASDAQ 100.

IQTO7g2.png


Here's the Code to put in a Custom Column:
Code:
#uTS Watchlist Code for %52WkRng
#Mobius© WLC Percent Inside 52 Week Range

def h = highest(high, 252);
def l = lowest(low, 252);
def x = (close - l) / (h - l);
plot r = round(x * 100, 0);

#4 lines is complete code#

Use whichever you would like! :)

Below is a scan that I came across that will pull the top 20% of Relative Strength stocks in a Scan of the S&P 500. After loading the scanned list, most were above the 75% line for the above chart's RS line. I also changed the inputs to 0 & 20 and the RS line on this chart was down on all on the list. I suggest scanning in S&P 100 or 500 to keep your list manageable. My thanks to Chris Baker.

Code:
# Scan - Price Rank in Range 80-100
# Edited by Markos to prove out scan for Relative Strength - Use is set for 1Yr-1Day Chart
# This Scan Tab study finds stocks whose price is in the given Price Rank (Price Percentile)
# in the given number of bars.
# By Chris Baker <[email protected]> @ChrisBaker97
# Latest version maintained at: https://bitbucket.org/ChrisBaker97/thinkscript/src/
# This thinkScript is designed for use in the Scan tab. Detailed
# instructions may be found at: https://bitbucket.org/ChrisBaker97/thinkscript/
#
# This work is licensed under the Creative Commons Attribution-ShareAlike
# 3.0 Unported License. To view a copy of this license, visit:
# http://creativecommons.org/licenses/by-sa/3.0/deed.en_US

#Start Code
input period = 252;
input prLo = 80;
input prHi = 100;

def hi = highest(high,period);
def lo =  lowest(low,period);
def range = hi - lo;

def priceRank = 100 * (open - lo) / range;

plot inRange = prLo <= priceRank and priceRank <= prHi;
#End Code

Grid chart: https://tos.mx/hfEeqh

Relative Strength (RS) Line

BhFJjJ9.png


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);

How can I scan TraderLion's indicator for the RS New Highs Before Price (RSNHBP)?
RS New Highs Before Price (RSNHBP) is often indicative of a break out emerging.

And also how would I scan for the Green Dot signals (RSNH) when RS line is making a new high?
 
How can I scan TraderLion's indicator for the RS New Highs Before Price (RSNHBP)?
RS New Highs Before Price (RSNHBP) is often indicative of a break out emerging.

And also how would I scan for the Green Dot signals (RSNH) when RS line is making a new high?
I believe you are referring to this (Traderlion RS Line)! You should be able to use it in scan as all the plots are available in the script.
 
@leonidas That error tells me that you won't be able to get it to work, most likely due to secondary aggregation... You aren't doing anything wrong other than attempting to use the wrong tool for the job... But try changing the Aggregation from Day to another timeframe... Before that, review the entire topic to see whether there may be a post that addresses scanning... 💡
 
I tried your suggestion and it didn't work.

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);
 
Hi,
I have this code that does not sort correctly in my watchlist, please help me fix this

Code:
# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Dark Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 10;

#def RS = if IsNan(relativeStrength("SPX")) then 0 else relativeStrength("SPX") ;
def RS = relativeStrength("SPX");
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
def RSRank = round(100 * (RS - RSLow) / (RSHigh - RsLow),1);
addlabel (yes,RSRank);

#AddLabel (yes, if  RSRank >= 1 and RSRank < 100 then "000" + astext(RSRank) else astext( RSRank)   );

assignbackgroundcolor (if RSRank > 80 then color.dark_green else
                       if RSRank > 60 and RSRank <= 80 then createcolor(0,175,0) else
                       if RSRank > 40 and RSRank <= 60 then color.gray else
                       if RSRank > 20 and RSRank <= 40 then CreateColor(220, 0,0) else
                       if RSRank <= 20 then CreateColor(150, 0,0) else
                       color.white);
 
Hi,
I have this code that does not sort correctly in my watchlist, please help me fix this

Code:
# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Dark Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 10;

#def RS = if IsNan(relativeStrength("SPX")) then 0 else relativeStrength("SPX") ;
def RS = relativeStrength("SPX");
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
def RSRank = round(100 * (RS - RSLow) / (RSHigh - RsLow),1);
addlabel (yes,RSRank);

#AddLabel (yes, if  RSRank >= 1 and RSRank < 100 then "000" + astext(RSRank) else astext( RSRank)   );

assignbackgroundcolor (if RSRank > 80 then color.dark_green else
                       if RSRank > 60 and RSRank <= 80 then createcolor(0,175,0) else
                       if RSRank > 40 and RSRank <= 60 then color.gray else
                       if RSRank > 20 and RSRank <= 40 then CreateColor(220, 0,0) else
                       if RSRank <= 20 then CreateColor(150, 0,0) else
                       color.white);
@ReyHak Where is says addlabel (yes,RSRank); in the code, change it to
Code:
plot RSRank_ = RSRank;
RSRank_.SetDefaultColor(Color.Red);
Check if that fixes the sorting issue, as I dont have ThinkorSwim open at the moment to verify the change.
 
@ReyHak Where is says addlabel (yes,RSRank); in the code, change it to
Code:
plot RSRank_ = RSRank;
RSRank_.SetDefaultColor(Color.Red);
Check if that fixes the sorting issue, as I dont have ThinkorSwim open at the moment to verify the change.
than you so much, worked like a charm
 
Yes, this one is a bit more complicated, because of the need to find the 3 RS scores from the scan tab, in order to calculate the RS rank.

Here's some more instructions on how to use the code. I think It's still necessary to read the descriptions in the script though.

The key part to obtain the RS Rank is to obtain 3 critical calibration points of IBD_RS scores in a database. Let's use TOS scan for SP500 index as an example and assume there are 500 stocks for easy calculation.

1). RS score corresponding to 99 percentile

This 99% outperforming percentile means 500 x 1% = 5, i.e. the 5th top RS score is equivalent to 99% rank. To make it easy to count a limited number of stocks, use the code that you've already put into the scan study:

You can reduce the value of 4.5 when the scan could not produce 5 stocks and increase the value when the scan produces too many number of stocks (e.g. over 50) for you to find the 5th one. Now sort the TOS scan results by IBD_RS (a custom quote added for this script) in a decreasing order, you can find the 5th stock is someone like DISA. Its IBD_RS score is 4.65.

Then, put this value in the variable below:

2). RS score corresponding to 1 percentile
For the same reason, select code in the scan study script to find the bottom 1% underperforming RS score, which is the 5th lowest score.

The 5th lowest RS score may be NI or other stocks. If you find its IBD_RS score is -1.17. then, put this value into the variable below:

3). Add a 90% calibration point since we are very interested at this percentile
We'll be looking for the RS score of the top 50th stock in this case. Select the code in the scan study below:

Make sure your scan results show all stocks satisfying the scan criteria by showing 100 or more stocks. Say you find the stock of the 50th (or 51th) highest RS value is NVDA and it has RS value of 3.07. Then, change the value of the following variable to 3.07 as shown below:
Going through this and still a little confused: how can a stock have a negative RS score (e.g., -1.17)? What is the code that you are using for your IBD_RS custom quote? Thanks!
 
Below is the chart setup for ThinkorSwim inspired by IBD (Investor's Business Daily) stocks chart. Also, a watchlist column and the Relative Strength (RS) indicator.

Updated 9-5-19

In this shared Google Drive are 2 files: https://drive.google.com/drive/folders/13XOHAGuDNjx6k98U5VB8AL2TmQOjyQqS?usp=sharing
  • A file comparison of yesterdays IBD Relative Strength direct from IBD, along with a listing of what the watchlist code reads for the same security. If you follow the stocks in IBD's 85-85 list, my hope is that you would find most of them ranked above 70 in the watchlist column.
  • The picture is of the watchlist code on the right on my screen shot of the same NASDAQ 100.

IQTO7g2.png


Here's the Code to put in a Custom Column:
Code:
#uTS Watchlist Code for %52WkRng
#Mobius© WLC Percent Inside 52 Week Range

def h = highest(high, 252);
def l = lowest(low, 252);
def x = (close - l) / (h - l);
plot r = round(x * 100, 0);

#4 lines is complete code#

Use whichever you would like! :)

Below is a scan that I came across that will pull the top 20% of Relative Strength stocks in a Scan of the S&P 500. After loading the scanned list, most were above the 75% line for the above chart's RS line. I also changed the inputs to 0 & 20 and the RS line on this chart was down on all on the list. I suggest scanning in S&P 100 or 500 to keep your list manageable. My thanks to Chris Baker.

Code:
# Scan - Price Rank in Range 80-100
# Edited by Markos to prove out scan for Relative Strength - Use is set for 1Yr-1Day Chart
# This Scan Tab study finds stocks whose price is in the given Price Rank (Price Percentile)
# in the given number of bars.
# By Chris Baker <[email protected]> @ChrisBaker97
# Latest version maintained at: https://bitbucket.org/ChrisBaker97/thinkscript/src/
# This thinkScript is designed for use in the Scan tab. Detailed
# instructions may be found at: https://bitbucket.org/ChrisBaker97/thinkscript/
#
# This work is licensed under the Creative Commons Attribution-ShareAlike
# 3.0 Unported License. To view a copy of this license, visit:
# http://creativecommons.org/licenses/by-sa/3.0/deed.en_US

#Start Code
input period = 252;
input prLo = 80;
input prHi = 100;

def hi = highest(high,period);
def lo =  lowest(low,period);
def range = hi - lo;

def priceRank = 100 * (open - lo) / range;

plot inRange = prLo <= priceRank and priceRank <= prHi;
#End Code

Grid chart: https://tos.mx/hfEeqh

Relative Strength (RS) Line

BhFJjJ9.png


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);
Any idea, In which part of the code it creates small dots on the RS line ? I am still learning on fundamentals of the script.
 
Hi,
I have this code that does not sort correctly in my watchlist, please help me fix this

Code:
# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Dark Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 10;

#def RS = if IsNan(relativeStrength("SPX")) then 0 else relativeStrength("SPX") ;
def RS = relativeStrength("SPX");
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
def RSRank = round(100 * (RS - RSLow) / (RSHigh - RsLow),1);
addlabel (yes,RSRank);

#AddLabel (yes, if  RSRank >= 1 and RSRank < 100 then "000" + astext(RSRank) else astext( RSRank)   );

assignbackgroundcolor (if RSRank > 80 then color.dark_green else
                       if RSRank > 60 and RSRank <= 80 then createcolor(0,175,0) else
                       if RSRank > 40 and RSRank <= 60 then color.gray else
                       if RSRank > 20 and RSRank <= 40 then CreateColor(220, 0,0) else
                       if RSRank <= 20 then CreateColor(150, 0,0) else
                       color.white);
This script is about as close it gets, thank you for the share! does anyone know if or how to modify this to put into the minervini trend Template?
 
Going through this and still a little confused: how can a stock have a negative RS score (e.g., -1.17)? What is the code that you are using for your IBD_RS custom quote? Thanks!
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.
 
Hi all,
Is it possible to modify this code so that when I change symbols on my chart, this section of the code that has "SPX" gets changed automatically to the industry that the symbol is in? For example FBK is in the bank industry which the symbol for this industry is $SP500#401010. This way, I don't have to keep manually changing the industry symbol in the code every time I change the symbol.
Any help would be greatly appreciated, thank you

def RS = relativeStrength("SPX");

Code:
Full Code:

# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Dark Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 21;

[I][B]#def RS = if IsNan(relativeStrength(""SPX"")) then 0 else relativeStrength(""SPX"") ;[/B][/I]
[B][I]def RS = relativeStrength("SPX");[/I][/B]
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
plot RSRank = round(100 * (RS - RSLow) / (RSHigh - RsLow),1);
 
Hi all,
Is it possible to modify this code so that when I change symbols on my chart, this section of the code that has "SPX" gets changed automatically to the industry that the symbol is in? For example FBK is in the bank industry which the symbol for this industry is $SP500#401010. This way, I don't have to keep manually changing the industry symbol in the code every time I change the symbol.
Any help would be greatly appreciated, thank you

def RS = relativeStrength("SPX");

Code:
Full Code:

# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Dark Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 21;

[I][B]#def RS = if IsNan(relativeStrength(""SPX"")) then 0 else relativeStrength(""SPX"") ;[/B][/I]
[B][I]def RS = relativeStrength("SPX");[/I][/B]
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
plot RSRank = round(100 * (RS - RSLow) / (RSHigh - RsLow),1);
Cannot be done in automated way... limitation of ToS
 
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?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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