IBD Stock Charts Style and Scan for ThinkorSwim

markos

Well-known member
VIP
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 Watch List Column:
Ruby:
#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);
AssignBackgroundColor( if rs > 80 then color.dark_green else
                       if rs > 60 then createcolor(0,175,0) else
                       if rs > 40 then color.gray else
                       if rs > 20 then CreateColor(220, 0,0) else
                       if rs <= 20 then CreateColor(150, 0,0) else
                       color.white  );
Shared Watch List Link: http://tos.mx/9VSRMyw
Click here for --> Easiest way to load shared links
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);
 

Attachments

  • IQTO7g2.png
    IQTO7g2.png
    381 KB · Views: 342
  • BhFJjJ9.png
    BhFJjJ9.png
    159.5 KB · Views: 378
Last edited by a moderator:
I always wondered how the IBD RS was created.

I plugged it into a watchlist column though the readings don't make sense.

Would it be adaptable to a watchlist column and or scan?

Thanks
 
It should be. You'd have to create it in the scan tab first, I think, but maybe can be done as a custom in the watch list. ( Working with an old tired memory here). Please share and post what you find out. Thanks!

One tweak I made was changing the volume average line from 50 to 34 (now 21 as of 9-2-19) ... just because. :)

I worked with it for a while last night to no avail. Stay tuned, I am working on getting this into a watchlist but it will take some time.

Code:
# The mini charts in IBD use a Relative Price Strength Line that compares the stock's price performance vs. the SP 500 index. The stock's price is divided by the value of the SP 500, and the result is plotted on a line. An upward sloping RS line indicates the stock is outperforming the SP 500, which is considered a good proxy for the general market. So, the higher the line, the better the stock is performing compared to the general market. 
# IBDRS
# Mobius
plot IBDRS = close / close(symbol = "/ES");
 
Last edited:
Thanks markos. I am really enjoying the threads here and the info that is shared. Hopefully I can contribute something soon.

I am jealous of my Twitter pals who subscribe to IBD and use this Relative Strength that is "proprietary". But I'm unwilling to pay 185. per month for Marketsmith. I've got years invested in Thinkorswim and there's no way I'm leaving or adding another chart system to the work load.

Hopefully someone will accept the challenge on this.
 
@dougn I have found a scan, though not perfect, will get you the type of Relative Strength stock you and I would be looking for. The reason the numbers look strange per the 2nd post is because it is close/close("SPY"). Ticker AZO is a 4.xx rank because it is 4x larger in price than SPY. The line is still valid, it just can't be scanned for or placed in a WLC thus the other scan was added to the 1st post. :)

It would be a great project for our coders here to give us all the ability to put something close to IBD's Relative Strength in a Watch List Column (WLC) and Sort for it. It's not as easy as one would think. The scan that I posted comes close but I haven't found a way to put the ranking in a list.
 
skynetgen ... can you please post the script? My customs are all filled and the only way I can install and check this out is with script. Thank you!
 
skynetgen ... can you please post the script? My customs are all filled and the only way I can install and check this out is with script. Thank you!
Well even though "custom quotes" appears limited you can import unlimited amount (or at least many more than 16). just click the link and it will add it to custom quotes beyond what is already there
 
The rules change at 100. After that you have to share an existing column, install it with a new name, then paste in your desired script. Per TOS there is no way to delete custom columns once the slot is used so over 100 you will have to do it this way.
 
Last edited:
Here is watchlist quote
@skynetgen, back to the drawing board with ya! 🧐 All you did was colored the higher RS stocks Green & lower, Red. Appreciate it, but you're a better coder than that. Right? :)

A number of us are looking for something akin to IBD's Rank for any given list of 1-99 with 99 being the highest Relative Strength.
Care to try again or are you stumped as well?

I have found a good proxy to get IBD's relative strength figured out. It will take a bit before it's ready for release and a shakedown for stability. Stay tuned. :cool:
 
@markos You are right. I just threw in some quick code in 5 min. Upon further examination this project is much more involved:

1) close/close(index) need to be reworked as percentage to be normalized. as it is is now its pretty meaningless for ranking purposes
2) There relative rank is pretty hard to do since TOS does not support arrays/data sources. A quick proxy would probably be to get 3-10 comparison
(say with strongest sector (e.g. XLU) mid sector (XLI) and weakest sector (XLE)). That is another can of worms
 
@markos Works very nice! Thanks for the research and posting. Below is the S&P 100 scan from this morning.

Watchlist Scanner
Results
SymbolDescriptionPrice Rank ScanP/C RatioLastNet Chng%ChangeVolumeMarket Cap5M_perfEarningsDiv. Yield - Current
DISWALT DISNEY COMPANY (THE) COM
82​
0.258​
138.84​
0​
0.00%
191​
250,103 M
20.77​
Earnings in 30 days
1.2317​
ALLALLSTATE CORP COM
85​
0.641​
104.38​
0​
0.00%
0​
34,361 M
10.02​
Earnings in 30 days
1.8881​
HONHONEYWELL INTERNATIONAL INC COM
85​
0.083​
170.37​
0​
0.00%
270​
122,583 M
5.13​
Earnings in 30 days
1.8357​
AIGAMER INTL GRP INC COM
86​
0.21​
54.68​
0​
0.00%
0​
47,567 M
21.86​
Earnings in 30 days
2.4024​
KMIKINDER MORGAN INC COM
86​
0.887​
20.51​
0​
0.00%
0​
46,431 M
2.86​
Earnings in 29 days
4.3103​
ABTABBOTT LABORATORIES COM
88​
0.646​
85.9​
0​
0.00%
222​
151,819 M
9.4​
Earnings in 29 days
1.4744​
LOWLOWE'S COMPANIES INC COM
88​
0.722​
114.21​
0​
0.00%
0​
88,147 M
-1.36​
Earnings in 30 days
2.0054​
CLCOLGATE-PALMOLIVE CO COM
89​
1.061​
74.29​
0​
0.00%
0​
63,741 M
9.22​
Earnings in 30 days
2.358​
UPSUNITED PARCEL SERVICE INC COM CL B
89​
0.906​
121.2​
0​
0.00%
0​
104,075 M
6.34​
Earnings in 30 days
3.6216​
NEENEXTERA ENERGY INC COM
90​
0.551​
219.81​
0​
0.00%
15​
107,432 M
16.52​
Earnings in 30 days
2.304​
AMGNAMGEN INC COM
91​
1.684​
207.65​
0​
0.00%
115​
124,528 M
6.55​
Earnings in 30 days
3.0063​
PEPPEPSICO INC COM
91​
1.176​
135.98​
0​
0.00%
426​
190,123 M
11.46​
Earnings in 20 days
2.8159​
SBUXSTARBUCKS CORP COM
91​
0.74​
95.56​
0​
0.00%
156​
114,385 M
27.07​
Earnings in 30 days
1.7178​
TXNTEXAS INSTRUMENTS INC COM
92​
0.421​
126.81​
0​
0.00%
0​
118,392 M
10.06​
Earnings in 30 days
2.5532​
WMTWALMART INC COM
92​
0.905​
115.44​
0​
0.00%
190​
329,549 M
16.34​
Earnings in 30 days
1.8663​
KOCOCA-COLA CO COM
93​
1.95​
55.12​
0​
0.00%
1350​
235,695 M
18.41​
Earnings in 30 days
3.1029​
MDTMEDTRONIC PLC COM
93​
0.292​
107.72​
0​
0.00%
30​
144,525 M
21.05​
Earnings in 30 days
1.9893​
NKENIKE INC COM CL B
93​
0.563​
88.42​
0​
0.00%
1736​
138,544 M
4.36​
Earnings in 13 days
1.1149​
BKNGBOOKING HOLDINGS INC COM
94​
0.928​
1994.44​
0​
0.00%
0​
84,787 M
11.5​
Earnings in 30 days
0​
MRKMERCK & CO INC COM
94​
0.679​
86.1​
0​
0.00%
25​
220,448 M
6.36​
Earnings in 30 days
2.5403​
SOSOUTHERN CO. COM
94​
0.776​
59.5​
0​
0.00%
0​
62,191 M
15.51​
Earnings in 30 days
4.3777​
DHRDANAHER CORP COM
95​
6.342​
142.95​
0​
0.00%
0​
102,548 M
8.34​
Earnings in 30 days
0.4618​
DUKDUKE ENERGY CORP COM
95​
1.106​
93.41​
0​
0.00%
0​
68,059 M
3.66​
Earnings in 30 days
4.2044​
LMTLOCKHEED MARTIN CORP COM
95​
0.449​
385.15​
0​
0.00%
120​
108,765 M
26.01​
Earnings in 30 days
2.3656​
CELGCELGENE CORP COM
96​
1.351​
97.51​
0​
0.00%
190​
69,109 M
2.64​
Earnings in 30 days
0​
CHTRCHARTER COMMUNICATIONS INC COM CL A
96​
1.092​
422.05​
0​
0.00%
0​
93,475 M
19.18​
Earnings in 30 days
0​
MCDMCDONALD'S CORPORATION COM
96​
0.649​
219.49​
0​
0.00%
111​
166,690 M
15.61​
Earnings in 30 days
2.1622​
COSTCOSTCO WHOLESALE CORP COM
97​
1.409​
296.97​
0​
0.00%
1244​
130,604 M
20.46​
Earnings in 20 days
0.95539​
MDLZMONDELEZ INTL INC COM CL A
97​
0.571​
56.14​
0​
0.00%
0​
80,962 M
13.16​
Earnings in 30 days
1.9295​
MSFTMICROSOFT CORP COM
97​
0.634​
140.05​
0​
0.00%
14886​
1,069,339 M
16.78​
Earnings in 30 days
1.3735​
ACNACCENTURE PLC COM
98​
1.432​
199.49​
0​
0.00%
0​
127,230 M
11.5​
Earnings in 15 days
1.5668​
HDHOME DEPOT INC COM
98​
0.898​
228.15​
0​
0.00%
1260​
249,859 M
12.09​
Earnings in 30 days
2.2531​
TGTTARGET CORP COM
98​
0.72​
108.54​
0​
0.00%
236​
55,456 M
32.48​
Earnings in 30 days
3.1403​
CMCSACOMCAST CORP COM CL A
99​
0.135​
46.41​
0​
0.00%
20​
210,933 M
14​
Earnings in 30 days
1.8922​
MAMASTERCARD INCORPORATED COM CL A
99​
0.694​
292.08​
0​
0.00%
4293​
296,333 M
23.62​
Earnings in 30 days
0.46876​
PGPROCTER & GAMBLE CO COM
99​
1.273​
122.76​
0​
0.00%
311​
307,223 M
16.95​
Earnings in 30 days
2.6425​
TAT&T INC COM
99​
0.667​
35.89​
0​
0.00%
4476​
262,248 M
10.81​
Earnings in 30 days
6.0579​
VVISA INC COM CL A
99​
0.841​
184.73​
0​
0.00%
914​
413,870 M
17.1​
Earnings in 30 days
0.55315​
 
Thank you everyone!!! You guys are awesome!!!
Hey @Nick if you look at the chart I posted in the beginning, I also use this chart for marking my bot and sold prices.
That is a checkbox in settings on first tab or Equity tab. Hopefully your version has that. Just going from memory, but thought you'd want to know.
 
Thanks @markos I believe it is the "show trades" that you are referring. Thanks.

QVeYo5o.jpg
 

Attachments

  • QVeYo5o.jpg
    QVeYo5o.jpg
    79.1 KB · Views: 150

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