# A chart that compares relative strength against spy

##### New member
Something similar to this screenshot where you can input 8 tickers and it will compare its' strength against spy.

Solution
Something similar to this screenshot where you can input 8 tickers and it will compare its' strength against spy.

this compares 8 stocks to 1 stock, to calculate the relative strength (a ratio of each pair)
default compare stock , SPY

Code:
``````# compare_8stocks_rel_str_00

#UnAnswered A chart that compares relative strength against spy

#Something similar to this screenshot where you can input 8 tickers and it will compare its' strength against spy.

# copy formulas from  RelativeStrength , TD Ameritrade

declare lower;

input CorrelationWithSecurity = "SPY";
def cls_corr =...``````

#### halcyonguy

##### Well-known member
VIP
Something similar to this screenshot where you can input 8 tickers and it will compare its' strength against spy.

this compares 8 stocks to 1 stock, to calculate the relative strength (a ratio of each pair)
default compare stock , SPY

Code:
``````# compare_8stocks_rel_str_00

#UnAnswered A chart that compares relative strength against spy

#Something similar to this screenshot where you can input 8 tickers and it will compare its' strength against spy.

# copy formulas from  RelativeStrength , TD Ameritrade

declare lower;

input CorrelationWithSecurity = "SPY";
def cls_corr = close(CorrelationWithSecurity);
#plot RS = if close_corr == 0 then 0 else close / close_corr;
#RS.SetDefaultColor(GetColor(6));
#def sr = CompoundValue("historical data" = RS, "visible data" = if IsNaN(sr[1]) then RS else sr[1]);
#plot SRatio =  sr;
#SRatio.SetDefaultColor(GetColor(5));

#----------------

input Symbol1 = "AAPL";
def cls1 = close(Symbol1);
def rs1 = if cls_corr == 0 then 0 else cls1/cls_corr;
plot z1 = rs1;

input Symbol2 = "META";
def cls2 = close(Symbol2);
def rs2 = if cls_corr == 0 then 0 else cls2/cls_corr;
plot z2 = rs2;

input Symbol3 = "PYPL";
def cls3 = close(Symbol3);
def rs3 = if cls_corr == 0 then 0 else cls3/cls_corr;
plot z3 = rs3;

input Symbol4 = "AMD";
def cls4 = close(Symbol4);
def rs4 = if cls_corr == 0 then 0 else cls4/cls_corr;
plot z4 = rs4;

input Symbol5 = "TSLA";
def cls5 = close(Symbol5);
def rs5 = if cls_corr == 0 then 0 else cls5/cls_corr;
plot z5 = rs5;

input Symbol6 = "AMZN";
def cls6 = close(Symbol6);
def rs6 = if cls_corr == 0 then 0 else cls6/cls_corr;
plot z6 = rs6;

input Symbol7 = "MSFT";
def cls7 = close(Symbol7);
def rs7 = if cls_corr == 0 then 0 else cls7/cls_corr;
plot z7 = rs7;

input Symbol8 = "QQQ";
def cls8 = close(Symbol8);
def rs8 = if cls_corr == 0 then 0 else cls8/cls_corr;
plot z8 = rs8;

#------------------------------

# draw bubbles , to the right of last bar, with symbol name
def off = 5;
def x = (!isnan(close[off]) and isnan(close[off-1]) );

def offc = off + 24;
def xc = (!isnan(close[offc]) and isnan(close[offc-1]) );
def minc = min(rs1,min(rs2,min(rs3,min(rs4,min(rs5,min(rs6,min(rs7,rs8)))))));
"Compared\n" +
"     to\n" +
"     " +
CorrelationWithSecurity
, Color.yellow, yes);
#
#``````

#### HODL-Lay-HE-hoo!

##### Active member
Search “Weighted Index Equites” you may like. Although it uses each sector but I really like it.

#### halcyonguy

##### Well-known member
VIP
an updated version, that normalizes the RS's

this calculates the relative strength of a stock compared to another (default, SPY)
the first stock RS sets the size of the plots.
can enter up to 7 more stocks. they are scaled to the first stock.

Code:
``````# rs_normalize_compare_00

# How can I normalize the stocks' RS ratios to compare them?

#==========================================

# compare_8stocks_rel_str_00
#UnAnswered A chart that compares relative strength against spy

declare lower;

def na = double.nan;

#=======================================

script normalizePlot {
input data = close;
input newRngMin = 0;
input newRngMax = 100;
def HHData = HighestAll(data);
def LLData = LowestAll(data);
plot nr = (((newRngMax - newRngMin)*(data - LLData))/(HHData - LLData)) + newRngMin;
}

#def a = normalizePlot(data, newmin, newmax);

#=======================================

input CorrelationWithSecurity = "SPY";
def cls_corr = close(CorrelationWithSecurity);
#plot RS = if close_corr == 0 then 0 else close / close_corr;
#RS.SetDefaultColor(GetColor(6));
#def sr = CompoundValue("historical data" = RS, "visible data" = if IsNaN(sr[1]) then RS else sr[1]);
#plot SRatio =  sr;
#SRatio.SetDefaultColor(GetColor(5));

#----------------

# symbol1 is the main stock.
# all others will be scaled to stock1 data
# use symbol  ZZ  for non entries

input Symbol1_primary = "AAPL";
#hint Symbol1_primary: This stock determines the min and max boundries. the other stocks will be scaled to be within the limits of this stock. This symbol needs to be entered.

def cls1 = close(Symbol1_primary);
def rs1 = if isnan(cls1) then na else if cls_corr == 0 then na else cls1/cls_corr;
def n1 = rs1;
plot z1 = n1;
z1.hidebubble();

def s1hi = highestall(rs1);
def s1lo = lowestall(rs1);
def s1rng = s1hi - s1lo;

input show_upper_lower_lines = yes;
plot s1top = if show_upper_lower_lines and !isnan(close) then s1hi else na;
plot s1bot = if show_upper_lower_lines and !isnan(close) then s1lo else na;
s1top.setdefaultcolor(color.gray);
s1bot.setdefaultcolor(color.gray);
s1top.hidebubble();
s1bot.hidebubble();

#---------------------------
#def a = normalizePlot(data, newmin, newmax);

input Symbol2 = "MSFT";
#hint symbol2: Enter a stock symbol for any of the symbols 2 to 8. \nIf you don't want to enter a stock, use ZZ.
def cls2 = close(Symbol2);
#def rs2 = if cls_corr == 0 then 0 else cls2/cls_corr;
def rs2 = if isnan(cls2) then na else if cls_corr == 0 then na else cls2/cls_corr;
def n2 = normalizePlot(rs2, s1lo, s1hi);
plot z2 = n2;
z2.hidebubble();

input Symbol3 = "WMT";
def cls3 = close(Symbol3);
def rs3 = if isnan(cls3) then na else if cls_corr == 0 then na else cls3/cls_corr;
def n3 = normalizePlot(rs3, s1lo, s1hi);
plot z3 = n3;
z3.hidebubble();

input Symbol4 = "ZZ";
def cls4 = close(Symbol4);
def rs4 = if isnan(cls4) then na else if cls_corr == 0 then na else cls4/cls_corr;
def n4 = normalizePlot(rs4, s1lo, s1hi);
plot z4 = n4;
z4.hidebubble();

input Symbol5 = "ZZ";
def cls5 = close(Symbol5);
def rs5 = if isnan(cls5) then na else if cls_corr == 0 then na else cls5/cls_corr;
def n5 = normalizePlot(rs5, s1lo, s1hi);
plot z5 = n5;
z5.hidebubble();

input Symbol6 = "ZZ";
def cls6 = close(Symbol6);
def rs6 = if isnan(cls6) then na else if cls_corr == 0 then na else cls6/cls_corr;
def n6 = normalizePlot(rs6, s1lo, s1hi);
plot z6 = n6;
z6.hidebubble();

input Symbol7 = "ZZ";
def cls7 = close(Symbol7);
def rs7 = if isnan(cls7) then na else if cls_corr == 0 then na else cls7/cls_corr;
def n7 = normalizePlot(rs7, s1lo, s1hi);
plot z7 = n7;
z7.hidebubble();

input Symbol8 = "ZZ";
def cls8 = close(Symbol8);
def rs8 = if isnan(cls8) then na else if cls_corr == 0 then na else cls8/cls_corr;
def n8 = normalizePlot(rs8, s1lo, s1hi);
plot z8 = n8;
z8.hidebubble();

#------------------------------

# draw bubbles , to the right of last bar, with symbol name
input show_name_bubbles = yes;

def off = 5;
def x = show_name_bubbles and (!isnan(close[off]) and isnan(close[off-1]) );

#-----------------------------

input show_labels = yes;

addlabel(show_labels, "RS of " + CorrelationWithSecurity, color.yellow);

def offc = off + 30;
def xc = (!isnan(close[offc]) and isnan(close[offc-1]) );
#def minc = min(rs1,min(rs2,min(rs3,min(rs4,min(rs5,min(rs6,min(rs7,rs8)))))));
# doesnt work, some values are na, so result is na
#def minc = min(n1,min(n2,min(n3,min(n4,min(n5,min(n6,min(n7,n8)))))));

input show_compare_stock_bubble = yes;
"Relative\nStrength\nof stocks\ncompared\nto  " +
CorrelationWithSecurity + "\n" +
"chart is scaled\nto Stock1\n" + Symbol1_primary
, Color.yellow, yes);
#

input shrink_the_plots = yes;
def zoom_per = 0.9;
def ztop = s1hi * ( 1 + (zoom_per/100));
def zbot = s1lo * ( 1 - (zoom_per/100));
plot zzt = if shrink_the_plots then ztop else na;
plot zzb = if shrink_the_plots then zbot else na;
zzt.setdefaultcolor(color.black);
zzb.setdefaultcolor(color.black);
zzt.hidebubble();
zzb.hidebubble();

n1 + "\n" +
n2 + "\n" +
n3 + "\n" +
n4 + "\n" +
n5 + "\n" +
n6 + "\n" +
n7 + "\n" +
n8
, color.yellow, no);
#``````

##### New member
an updated version, that normalizes the RS's

this calculates the relative strength of a stock compared to another (default, SPY)
the first stock RS sets the size of the plots.
can enter up to 7 more stocks. they are scaled to the first stock.

Code:
``````# rs_normalize_compare_00

# How can I normalize the stocks' RS ratios to compare them?

#==========================================

# compare_8stocks_rel_str_00
#UnAnswered A chart that compares relative strength against spy

declare lower;

def na = double.nan;

#=======================================

script normalizePlot {
input data = close;
input newRngMin = 0;
input newRngMax = 100;
def HHData = HighestAll(data);
def LLData = LowestAll(data);
plot nr = (((newRngMax - newRngMin)*(data - LLData))/(HHData - LLData)) + newRngMin;
}

#def a = normalizePlot(data, newmin, newmax);

#=======================================

input CorrelationWithSecurity = "SPY";
def cls_corr = close(CorrelationWithSecurity);
#plot RS = if close_corr == 0 then 0 else close / close_corr;
#RS.SetDefaultColor(GetColor(6));
#def sr = CompoundValue("historical data" = RS, "visible data" = if IsNaN(sr[1]) then RS else sr[1]);
#plot SRatio =  sr;
#SRatio.SetDefaultColor(GetColor(5));

#----------------

# symbol1 is the main stock.
# all others will be scaled to stock1 data
# use symbol  ZZ  for non entries

input Symbol1_primary = "AAPL";
#hint Symbol1_primary: This stock determines the min and max boundries. the other stocks will be scaled to be within the limits of this stock. This symbol needs to be entered.

def cls1 = close(Symbol1_primary);
def rs1 = if isnan(cls1) then na else if cls_corr == 0 then na else cls1/cls_corr;
def n1 = rs1;
plot z1 = n1;
z1.hidebubble();

def s1hi = highestall(rs1);
def s1lo = lowestall(rs1);
def s1rng = s1hi - s1lo;

input show_upper_lower_lines = yes;
plot s1top = if show_upper_lower_lines and !isnan(close) then s1hi else na;
plot s1bot = if show_upper_lower_lines and !isnan(close) then s1lo else na;
s1top.setdefaultcolor(color.gray);
s1bot.setdefaultcolor(color.gray);
s1top.hidebubble();
s1bot.hidebubble();

#---------------------------
#def a = normalizePlot(data, newmin, newmax);

input Symbol2 = "MSFT";
#hint symbol2: Enter a stock symbol for any of the symbols 2 to 8. \nIf you don't want to enter a stock, use ZZ.
def cls2 = close(Symbol2);
#def rs2 = if cls_corr == 0 then 0 else cls2/cls_corr;
def rs2 = if isnan(cls2) then na else if cls_corr == 0 then na else cls2/cls_corr;
def n2 = normalizePlot(rs2, s1lo, s1hi);
plot z2 = n2;
z2.hidebubble();

input Symbol3 = "WMT";
def cls3 = close(Symbol3);
def rs3 = if isnan(cls3) then na else if cls_corr == 0 then na else cls3/cls_corr;
def n3 = normalizePlot(rs3, s1lo, s1hi);
plot z3 = n3;
z3.hidebubble();

input Symbol4 = "ZZ";
def cls4 = close(Symbol4);
def rs4 = if isnan(cls4) then na else if cls_corr == 0 then na else cls4/cls_corr;
def n4 = normalizePlot(rs4, s1lo, s1hi);
plot z4 = n4;
z4.hidebubble();

input Symbol5 = "ZZ";
def cls5 = close(Symbol5);
def rs5 = if isnan(cls5) then na else if cls_corr == 0 then na else cls5/cls_corr;
def n5 = normalizePlot(rs5, s1lo, s1hi);
plot z5 = n5;
z5.hidebubble();

input Symbol6 = "ZZ";
def cls6 = close(Symbol6);
def rs6 = if isnan(cls6) then na else if cls_corr == 0 then na else cls6/cls_corr;
def n6 = normalizePlot(rs6, s1lo, s1hi);
plot z6 = n6;
z6.hidebubble();

input Symbol7 = "ZZ";
def cls7 = close(Symbol7);
def rs7 = if isnan(cls7) then na else if cls_corr == 0 then na else cls7/cls_corr;
def n7 = normalizePlot(rs7, s1lo, s1hi);
plot z7 = n7;
z7.hidebubble();

input Symbol8 = "ZZ";
def cls8 = close(Symbol8);
def rs8 = if isnan(cls8) then na else if cls_corr == 0 then na else cls8/cls_corr;
def n8 = normalizePlot(rs8, s1lo, s1hi);
plot z8 = n8;
z8.hidebubble();

#------------------------------

# draw bubbles , to the right of last bar, with symbol name
input show_name_bubbles = yes;

def off = 5;
def x = show_name_bubbles and (!isnan(close[off]) and isnan(close[off-1]) );

#-----------------------------

input show_labels = yes;

addlabel(show_labels, "RS of " + CorrelationWithSecurity, color.yellow);

def offc = off + 30;
def xc = (!isnan(close[offc]) and isnan(close[offc-1]) );
#def minc = min(rs1,min(rs2,min(rs3,min(rs4,min(rs5,min(rs6,min(rs7,rs8)))))));
# doesnt work, some values are na, so result is na
#def minc = min(n1,min(n2,min(n3,min(n4,min(n5,min(n6,min(n7,n8)))))));

input show_compare_stock_bubble = yes;
"Relative\nStrength\nof stocks\ncompared\nto  " +
CorrelationWithSecurity + "\n" +
"chart is scaled\nto Stock1\n" + Symbol1_primary
, Color.yellow, yes);
#

input shrink_the_plots = yes;
def zoom_per = 0.9;
def ztop = s1hi * ( 1 + (zoom_per/100));
def zbot = s1lo * ( 1 - (zoom_per/100));
plot zzt = if shrink_the_plots then ztop else na;
plot zzb = if shrink_the_plots then zbot else na;
zzt.setdefaultcolor(color.black);
zzb.setdefaultcolor(color.black);
zzt.hidebubble();
zzb.hidebubble();

n1 + "\n" +
n2 + "\n" +
n3 + "\n" +
n4 + "\n" +
n5 + "\n" +
n6 + "\n" +
n7 + "\n" +
n8
, color.yellow, no);
#``````

Thanks! I'll gave this a try

#### mjlinhle

##### New member
VIP
Thanks! I'll gave this a try
an updated version, that normalizes the RS's

this calculates the relative strength of a stock compared to another (default, SPY)
the first stock RS sets the size of the plots.
can enter up to 7 more stocks. they are scaled to the first stock.

Code:
``````# rs_normalize_compare_00

# How can I normalize the stocks' RS ratios to compare them?

#==========================================

# compare_8stocks_rel_str_00
#UnAnswered A chart that compares relative strength against spy

declare lower;

def na = double.nan;

#=======================================

script normalizePlot {
input data = close;
input newRngMin = 0;
input newRngMax = 100;
def HHData = HighestAll(data);
def LLData = LowestAll(data);
plot nr = (((newRngMax - newRngMin)*(data - LLData))/(HHData - LLData)) + newRngMin;
}

#def a = normalizePlot(data, newmin, newmax);

#=======================================

input CorrelationWithSecurity = "SPY";
def cls_corr = close(CorrelationWithSecurity);
#plot RS = if close_corr == 0 then 0 else close / close_corr;
#RS.SetDefaultColor(GetColor(6));
#def sr = CompoundValue("historical data" = RS, "visible data" = if IsNaN(sr[1]) then RS else sr[1]);
#plot SRatio =  sr;
#SRatio.SetDefaultColor(GetColor(5));

#----------------

# symbol1 is the main stock.
# all others will be scaled to stock1 data
# use symbol  ZZ  for non entries

input Symbol1_primary = "AAPL";
#hint Symbol1_primary: This stock determines the min and max boundries. the other stocks will be scaled to be within the limits of this stock. This symbol needs to be entered.

def cls1 = close(Symbol1_primary);
def rs1 = if isnan(cls1) then na else if cls_corr == 0 then na else cls1/cls_corr;
def n1 = rs1;
plot z1 = n1;
z1.hidebubble();

def s1hi = highestall(rs1);
def s1lo = lowestall(rs1);
def s1rng = s1hi - s1lo;

input show_upper_lower_lines = yes;
plot s1top = if show_upper_lower_lines and !isnan(close) then s1hi else na;
plot s1bot = if show_upper_lower_lines and !isnan(close) then s1lo else na;
s1top.setdefaultcolor(color.gray);
s1bot.setdefaultcolor(color.gray);
s1top.hidebubble();
s1bot.hidebubble();

#---------------------------
#def a = normalizePlot(data, newmin, newmax);

input Symbol2 = "MSFT";
#hint symbol2: Enter a stock symbol for any of the symbols 2 to 8. \nIf you don't want to enter a stock, use ZZ.
def cls2 = close(Symbol2);
#def rs2 = if cls_corr == 0 then 0 else cls2/cls_corr;
def rs2 = if isnan(cls2) then na else if cls_corr == 0 then na else cls2/cls_corr;
def n2 = normalizePlot(rs2, s1lo, s1hi);
plot z2 = n2;
z2.hidebubble();

input Symbol3 = "WMT";
def cls3 = close(Symbol3);
def rs3 = if isnan(cls3) then na else if cls_corr == 0 then na else cls3/cls_corr;
def n3 = normalizePlot(rs3, s1lo, s1hi);
plot z3 = n3;
z3.hidebubble();

input Symbol4 = "ZZ";
def cls4 = close(Symbol4);
def rs4 = if isnan(cls4) then na else if cls_corr == 0 then na else cls4/cls_corr;
def n4 = normalizePlot(rs4, s1lo, s1hi);
plot z4 = n4;
z4.hidebubble();

input Symbol5 = "ZZ";
def cls5 = close(Symbol5);
def rs5 = if isnan(cls5) then na else if cls_corr == 0 then na else cls5/cls_corr;
def n5 = normalizePlot(rs5, s1lo, s1hi);
plot z5 = n5;
z5.hidebubble();

input Symbol6 = "ZZ";
def cls6 = close(Symbol6);
def rs6 = if isnan(cls6) then na else if cls_corr == 0 then na else cls6/cls_corr;
def n6 = normalizePlot(rs6, s1lo, s1hi);
plot z6 = n6;
z6.hidebubble();

input Symbol7 = "ZZ";
def cls7 = close(Symbol7);
def rs7 = if isnan(cls7) then na else if cls_corr == 0 then na else cls7/cls_corr;
def n7 = normalizePlot(rs7, s1lo, s1hi);
plot z7 = n7;
z7.hidebubble();

input Symbol8 = "ZZ";
def cls8 = close(Symbol8);
def rs8 = if isnan(cls8) then na else if cls_corr == 0 then na else cls8/cls_corr;
def n8 = normalizePlot(rs8, s1lo, s1hi);
plot z8 = n8;
z8.hidebubble();

#------------------------------

# draw bubbles , to the right of last bar, with symbol name
input show_name_bubbles = yes;

def off = 5;
def x = show_name_bubbles and (!isnan(close[off]) and isnan(close[off-1]) );

#-----------------------------

input show_labels = yes;

addlabel(show_labels, "RS of " + CorrelationWithSecurity, color.yellow);

def offc = off + 30;
def xc = (!isnan(close[offc]) and isnan(close[offc-1]) );
#def minc = min(rs1,min(rs2,min(rs3,min(rs4,min(rs5,min(rs6,min(rs7,rs8)))))));
# doesnt work, some values are na, so result is na
#def minc = min(n1,min(n2,min(n3,min(n4,min(n5,min(n6,min(n7,n8)))))));

input show_compare_stock_bubble = yes;
"Relative\nStrength\nof stocks\ncompared\nto  " +
CorrelationWithSecurity + "\n" +
"chart is scaled\nto Stock1\n" + Symbol1_primary
, Color.yellow, yes);
#

input shrink_the_plots = yes;
def zoom_per = 0.9;
def ztop = s1hi * ( 1 + (zoom_per/100));
def zbot = s1lo * ( 1 - (zoom_per/100));
plot zzt = if shrink_the_plots then ztop else na;
plot zzb = if shrink_the_plots then zbot else na;
zzt.setdefaultcolor(color.black);
zzb.setdefaultcolor(color.black);
zzt.hidebubble();
zzb.hidebubble();

n1 + "\n" +
n2 + "\n" +
n3 + "\n" +
n4 + "\n" +
n5 + "\n" +
n6 + "\n" +
n7 + "\n" +
n8
, color.yellow, no);
#``````

HI, is there a way we could have a scan for this ?
Thanks.

#### halcyonguy

##### Well-known member
VIP
HI, is there a way we could have a scan for this ?
Thanks.

why?
what would the scan look for?

#### mjlinhle

##### New member
VIP
why?
what would the scan look for
Hi,
I just want to see the strong or weakness vs current market

#### sindhu19

##### New member
2019 Donor
hi @halcyonguy , is it possible to make this as a watchlist coloumn? thank you.

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?