TradingView
hkorange2007
13. Dez. 2021 12:11

republish US sector rrg (Relative Rotation Graph) 

S&P 500SP

Beschreibung

The script was hidden due to the reference link. Republishing without any links.
If you would like to know more about the formula, just google it. The script is based on the first few results from google search.

How to use: adjust the input number and timeframe. It means how far you would like to look back. e.g. weekly timeframe and 12 as input number mean you want to olok 12 weeks back.

Script explain: calculate the relative strength(100 * stock/spx ) > then normalize it(make it near 100) > now have relative strength ratio > find momentum(find roc of relative strength ratio) > normalize the roc(make the number near 100) > now have the relative strength momentum > use momentum and ratio to tell what state it is in.(e.g. both > 100 = leading)
Kommentare
FlammaTheKing
Is it universal indicator works for any indices or limited to us, am from India does it works for nse and bse.
aseemapoorv
why did you add 101?? shouldn't it be 100
hkorange2007
The script was based on a website(search rrg excel, I am not allowed to post a link). The excel formula on the website is 101+(N3-AVERAGE(OFFSET(N3,B$1,0,-B$1)))/STDEV(OFFSET(N3,B$1,0,-B$1))) and it says "And how does normalization work? It’s a simple formula: 100+ ((Value-Mean)/Standard Dev) +1"
ctannous2134
i dont think the data output is accurate can you please fix the script
hkorange2007
Hi everyone,

Sorry for the late reply. I see people are saying there is something wrong with the script. I am not a math guy and I don't know what is the real formula of RRG. This script was only based on a website. After reviewing the script, I am still not able to find the problem. I will a bit of explanation of the code and add some of the content of the website. Maybe you will be able to find the problem.

securityClose = security(ticker, timeframe.period, close)
spx = security("SPX", timeframe.period, close)
These 2 lines of code get the stock close and spx close

rs = 100 * (securityClose / spx)
This finds the relative strength of a stock compare to spx, the formula is (stock close / spx close) * 100

rsr = 101 + ((rs - sma(rs, period)) / stdev(rs, period))
This line of code is to calculate the normalized JdK RS-Ratio for each sector, the formula is 100+ ((Value-Mean)/Standard Dev) + 1 and the excel formula is IF(ISNUMBER(OFFSET(N3,B$1,0)),(101+(N3-AVERAGE(OFFSET(N3,B$1,0,-B$1)))/STDEV(OFFSET(N3,B$1,0,-B$1))),NA())

rsrRoc = 100 * ((rsr / rsr[1]) - 1)
This finds the rate of change of rsr, the excel formula is 100*(AJ3/AJ4 -1), so this should be 100 * ((current rsr/ last rsr) -1)

rsm = 101 + ((rsrRoc - sma(rsrRoc, period)) / stdev(rsrRoc, period))
Calculate the JdK-RS Momentum Ratio, similar to the rsr, 100+ ((rsrRoc - mean of rsrRoc ) / rsrRoc Standard Dev) + 1

status = "null"
bgcolor = color.white
if rsr < 100 and rsm > 100
status := "improving"
bgcolor := color.blue
else if rsr > 100 and rsm > 100
status := "leading"
bgcolor := color.green
else if rsr > 100 and rsm < 100
status := "weakening"
bgcolor := color.yellow
else if rsr < 100 and rsm < 100
status := "lagging"
bgcolor := color.red
status
It checks the value of rsr and rsm, and return what status (improving/ leading/ weakening/ lagging), 100 is the origin, both > 100 = leading, both < 100 = lagging, rsr < 100 but rsm >100 = improving, rsr > 100 but rsm < 100 =weakening

The rest of the codes just create a table and put different sector etf to test.

There are a few potential problems causing the result different from other source: The formula above is incorrect or different from other websites. They use other sectors equity to compare(I use XLE, XLU.... etc). The period variable is different from other source. I use close price and other use hlc3/ ohlc4.
strat_us
Good work. One tip, for the standard deviation ( statistics calculation) to work you need minimum 20 data points (period=20). Anything less than 20 data points will make the the stddev calcuation less reliable.
forestlake
TIP: In the "table.new" function, the number of rows and columns are swappable to create a horizontal table instead of a vertical one. The table is also aligned to the bottom left of the chart using the "position.bottom_left" parameter.
vhugeat
Hi hkorange2007,
Before giving you my observations, I would like to congrats you on this fantastic work. I'm working on the RRG chart (currently in Excel) before programming it. I compared your results with Julius de Kempenaer's chart and observed that your script differs from his results. For example, considering the weekly timeframe in de Kempenaer's chart the energy sector moves in the weakening quadrant, however in your script energy sector appears to be leading.
I don't know if you did the normalization step.
Best regards.
Mehr