Weekly Relative Strength vs SPX

RmS59

RmS59

Member
I am trying to create a weekly Relative_Strength indicator that compares a security to the SPX (or other)

I can not seem to get the SPX data using Aggregation Period = weekly.

Here is what I use for the Daily RS_SPX
-------------------------------


input price = FundamentalType.CLOSE;
input RelativeToSecurity = "SPX";
input Lookback = 50;
input smoothingPeriod1 = 8;
input smoothingPeriod2 = 21;

def price1 = Fundamental(price);
def price2 = Fundamental(price, RelativeToSecurity);


def UnderlyingStrength = (price1 - price1[Lookback]) / price1[Lookback];
def BaseStrength = (price2 - price2[Lookback]) / price2[Lookback];

plot RSI = Round((1 + UnderlyingStrength) / (1 + BaseStrength), 3);


-----------------------------

I then look at 2 moving averages to see crosses - defing longer term performance.

I know that I could simply use periods that are 5* the daily period, but that does not provide correct results.

Can anyone help ??
 
RmS59

RmS59

Member
It seems that sometimes I just need to ask the question to get motivated.....

I had tried to do this for a while, but just stumbled upon something. This works:

input price = FundamentalType.CLOSE;
input RelativeToSecurity = "SPX";
input Lookback = 50;


def price1 = CLOSE(period = AggregationPeriod.WEEK);
def price2 = Fundamental(price, RelativeToSecurity, AggregationPeriod.WEEK);


def UnderlyingStrength = (price1 - price1[Lookback]) / price1[Lookback];
def BaseStrength = (price2 - price2[Lookback]) / price2[Lookback];

plot RSI = Round((1 + UnderlyingStrength) / (1 + BaseStrength), 3);

-------------

not using fundamental type for price1 was the key.
 
Last edited:
N

Nick

Active member
2019 Donor
VIP
It seems that sometimes I just need to ask the question to get motivated.....

I had tried to do this for a while, but just stumbled upon something. This works:

input price = FundamentalType.CLOSE;
input RelativeToSecurity = "SPX";
input Lookback = 50;


def price1 = CLOSE(period = AggregationPeriod.WEEK);
def price2 = Fundamental(price, RelativeToSecurity, AggregationPeriod.WEEK);


def UnderlyingStrength = (price1 - price1[Lookback]) / price1[Lookback];
def BaseStrength = (price2 - price2[Lookback]) / price2[Lookback];

plot RSI = Round((1 + UnderlyingStrength) / (1 + BaseStrength), 3);

-------------

not using fundamental type for price1 was the key.
Hi, how do i apply these code? do you mind posting a screenshot how the indicator looks like on the chart or scan. Thank you
 
wtf_dude

wtf_dude

Active member
Hey man, check out the RSMK indicator on TOS. It f*ckin rules, was just added, and I find it much easier to read at a glance. You can change the time period. I think it may be exactly what you may be looking for. I THINK it may have originally been done by one of the guys on here?
 
N

Nick

Active member
2019 Donor
VIP
Hey man, check out the RSMK indicator on TOS. It f*ckin rules, was just added, and I find it much easier to read at a glance. You can change the time period. I think it may be exactly what you may be looking for. I THINK it may have originally been done by one of the guys on here?
Wow..thanks alot...
 
RmS59

RmS59

Member
Sorry for the VERY LATE RESPONSE!

You asked how I use it - I have incorporated it into a study that defines a stock's movement strength using a variety of measurements that include trend, momentum, relative strength (SPX), Overbought/Oversold and Accumulation/Distribution.

Here is the complete code:

Code:
########
# RelativeStrength_MultiTimeFrame
#
#
# 04.15.20    Version 1   RmS59
#
#
# This indicator calculates the Relative Strength of the underlying security to an alternate (SPX default)
# Allows user to select Aggregation Period for calculation
#


declare lower;

def price = FundamentalType.CLOSE;
input AggPeriod  = AggregationPeriod.week;
input RelativeToSecurity = "SPX";
input Lookback = 50;
input smoothingPeriod1 = 5;
input smoothingPeriod2 = 8;
input smoothingPeriod3 = 34;
input showRSI3 = no;
input displayThresholds = yes;
input Threshold = 0.050;
input displayRSCrossOvers = no;
input showMvgAvgCross = yes;
input showTrendLabel = yes;
input hideLabel = no;

def price1 = close(Period = aggPeriod);
def price2 = Fundamental(price, RelativeToSecurity,AggPeriod);

def UnderlyingStrength = (price1 - price1[Lookback]) / price1[Lookback];
def BaseStrength = (price2 - price2[Lookback]) / price2[Lookback];

plot RSI = Round((1 + UnderlyingStrength) / (1 + BaseStrength), 3);
RSI.DefineColor("UpTrending", Color.GREEN);
RSI.DefineColor("UpNormal", Color.DARK_GREEN);
RSI.DefineColor("DnTrending", Color.RED);
RSI.DefineColor("DnNormal", Color.DARK_RED);
RSI.DefineColor("Flat", Color.WHITE);

RSI.AssignValueColor(
   if RSI >= 1 + Threshold then RSI.Color("UpTrending")
     else if RSI >=  1 then RSI.Color("UpNormal")
        else if RSI <= 1 - Threshold then RSI.Color("DnTrending")
            else if RSI < 1 then RSI.Color("DnNormal")
                else RSI.Color("Flat"));

plot SmRSI1 = SimpleMovingAvg(RSI, smoothingPeriod1);
plot SmRSI2 = SimpleMovingAvg(RSI, smoothingPeriod2);
plot SmRSI3 = if showRSI3 then SimpleMovingAvg(RSI, smoothingPeriod3) else Double.NaN;

SmRSI1.DefineColor("Normal", Color.MAGENTA);
SmRSI1.AssignValueColor(RSI.TakeValueColor());#colorizeRSI1

SmRSI1.SetLineWeight(2);
SmRSI2.SetDefaultColor(Color.white);
#SmRSI1.AssignValueColor(RSI.TakeValueColor());
SmRSI2.SetLineWeight(1);

plot Base = if !IsNaN(close) then 1.00 else Double.NaN;
Base.SetDefaultColor(Color.WHITE);

plot PosCross = if RSI crosses above SmRSI1 and displayRSCrossOvers then SmRSI1 else Double.NaN;
PosCross.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
PosCross.setdefaultColor(color.green);
plot NegCross = if RSI crosses below SmRSI1 and displayRSCrossOvers then SmRSI1 else Double.NaN;
NegCross.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
NegCross.setdefaultColor(color.red);

plot  BullishThreshold = if displayThresholds and !IsNaN(close) then 1 + Threshold else Double.NaN;
BullishThreshold.SetDefaultColor(Color.DARK_GREEN);
plot  BearishThreshold = if displayThresholds and !IsNaN(close) then 1 - Threshold else Double.NaN;
BearishThreshold.SetDefaultColor(Color.DARK_RED);

BullishThreshold.setStyle(curve.short_dash);
BullishThreshold.setdefaultColor(color.dark_green);
BearishThreshold.setStyle(curve.short_dash);
BearishThreshold.setdefaultColor(color.dark_red);

AddLabel(!hideLabel, Lookback + " RS / " + RelativeToSecurity + ": " + RSI, RSI.TakeValueColor());


plot LongCross = if showMvgAvgCross and SmRSI1 crosses above SmRSI2 then SmRSI2 - 0.5*ticksize()  else Double.NaN;
LongCross.setpaintingStrategy(paintingStrategy.ARROW_UP);
LongCross.setdefaultColor(color.green);

plot ShortCross = if showMvgAvgCross and SmRSI1 crosses below SmRSI2 then SmRSI1 + 0.5*ticksize() else Double.NaN;
ShortCross.setpaintingStrategy(paintingStrategy.ARROW_DOWN);
ShortCross.setdefaultColor(color.red);

plot Trend = if SmRSI1 > SmRSI2 then 1 else -1;
Trend.hide();


##############

Trend.DefineColor("UpTrending", Color.GREEN);
Trend.DefineColor("DnTrending", Color.RED);
Trend.AssignValueColor(
   if Trend == 1 then Trend.Color("UpTrending")
        else Trend.Color("DnTrending"));
          
Addlabel(showTrendLabel, "Trend = "+ if Trend == 1 then "Bullish" else "Bearish", Trend.takeValueColor());

SmRSI1.AssignValueColor(RSI.TakeValueColor());
 
N

Nick

Active member
2019 Donor
VIP
Sorry for the VERY LATE RESPONSE!

You asked how I use it - I have incorporated it into a study that defines a stock's movement strength using a variety of measurements that include trend, momentum, relative strength (SPX), Overbought/Oversold and Accumulation/Distribution.

Here is the complete code:

Code:
########
# RelativeStrength_MultiTimeFrame
#
#
# 04.15.20    Version 1   RmS59
#
#
# This indicator calculates the Relative Strength of the underlying security to an alternate (SPX default)
# Allows user to select Aggregation Period for calculation
#


declare lower;

def price = FundamentalType.CLOSE;
input AggPeriod  = AggregationPeriod.week;
input RelativeToSecurity = "SPX";
input Lookback = 50;
input smoothingPeriod1 = 5;
input smoothingPeriod2 = 8;
input smoothingPeriod3 = 34;
input showRSI3 = no;
input displayThresholds = yes;
input Threshold = 0.050;
input displayRSCrossOvers = no;
input showMvgAvgCross = yes;
input showTrendLabel = yes;
input hideLabel = no;

def price1 = close(Period = aggPeriod);
def price2 = Fundamental(price, RelativeToSecurity,AggPeriod);

def UnderlyingStrength = (price1 - price1[Lookback]) / price1[Lookback];
def BaseStrength = (price2 - price2[Lookback]) / price2[Lookback];

plot RSI = Round((1 + UnderlyingStrength) / (1 + BaseStrength), 3);
RSI.DefineColor("UpTrending", Color.GREEN);
RSI.DefineColor("UpNormal", Color.DARK_GREEN);
RSI.DefineColor("DnTrending", Color.RED);
RSI.DefineColor("DnNormal", Color.DARK_RED);
RSI.DefineColor("Flat", Color.WHITE);

RSI.AssignValueColor(
   if RSI >= 1 + Threshold then RSI.Color("UpTrending")
     else if RSI >=  1 then RSI.Color("UpNormal")
        else if RSI <= 1 - Threshold then RSI.Color("DnTrending")
            else if RSI < 1 then RSI.Color("DnNormal")
                else RSI.Color("Flat"));

plot SmRSI1 = SimpleMovingAvg(RSI, smoothingPeriod1);
plot SmRSI2 = SimpleMovingAvg(RSI, smoothingPeriod2);
plot SmRSI3 = if showRSI3 then SimpleMovingAvg(RSI, smoothingPeriod3) else Double.NaN;

SmRSI1.DefineColor("Normal", Color.MAGENTA);
SmRSI1.AssignValueColor(RSI.TakeValueColor());#colorizeRSI1

SmRSI1.SetLineWeight(2);
SmRSI2.SetDefaultColor(Color.white);
#SmRSI1.AssignValueColor(RSI.TakeValueColor());
SmRSI2.SetLineWeight(1);

plot Base = if !IsNaN(close) then 1.00 else Double.NaN;
Base.SetDefaultColor(Color.WHITE);

plot PosCross = if RSI crosses above SmRSI1 and displayRSCrossOvers then SmRSI1 else Double.NaN;
PosCross.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
PosCross.setdefaultColor(color.green);
plot NegCross = if RSI crosses below SmRSI1 and displayRSCrossOvers then SmRSI1 else Double.NaN;
NegCross.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
NegCross.setdefaultColor(color.red);

plot  BullishThreshold = if displayThresholds and !IsNaN(close) then 1 + Threshold else Double.NaN;
BullishThreshold.SetDefaultColor(Color.DARK_GREEN);
plot  BearishThreshold = if displayThresholds and !IsNaN(close) then 1 - Threshold else Double.NaN;
BearishThreshold.SetDefaultColor(Color.DARK_RED);

BullishThreshold.setStyle(curve.short_dash);
BullishThreshold.setdefaultColor(color.dark_green);
BearishThreshold.setStyle(curve.short_dash);
BearishThreshold.setdefaultColor(color.dark_red);

AddLabel(!hideLabel, Lookback + " RS / " + RelativeToSecurity + ": " + RSI, RSI.TakeValueColor());


plot LongCross = if showMvgAvgCross and SmRSI1 crosses above SmRSI2 then SmRSI2 - 0.5*ticksize()  else Double.NaN;
LongCross.setpaintingStrategy(paintingStrategy.ARROW_UP);
LongCross.setdefaultColor(color.green);

plot ShortCross = if showMvgAvgCross and SmRSI1 crosses below SmRSI2 then SmRSI1 + 0.5*ticksize() else Double.NaN;
ShortCross.setpaintingStrategy(paintingStrategy.ARROW_DOWN);
ShortCross.setdefaultColor(color.red);

plot Trend = if SmRSI1 > SmRSI2 then 1 else -1;
Trend.hide();


##############

Trend.DefineColor("UpTrending", Color.GREEN);
Trend.DefineColor("DnTrending", Color.RED);
Trend.AssignValueColor(
   if Trend == 1 then Trend.Color("UpTrending")
        else Trend.Color("DnTrending"));
         
Addlabel(showTrendLabel, "Trend = "+ if Trend == 1 then "Bullish" else "Bearish", Trend.takeValueColor());

SmRSI1.AssignValueColor(RSI.TakeValueColor());
Thank you very much.
 
Thread starter Similar threads Forum Replies Date
M Weekly scanner for %change and RS rating Questions 0
G Weekly Price Level Questions 0
J Weekly stochastic on daily chart Questions 1
R Weekly Opening Range Watchlist Questions 1
S Scan or watchlist based on Weekly Volume Questions 0

Similar threads

Top