RSRW
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

// © WorkPiece 12.28.21 OMXS30

//@version=5



indicator(title="Real Relative Strength", shorttitle="RSRW")

comparedWithSecurity = input.symbol(title="Compare With", defval="SPY")

length = input(title="Length", defval=12)



//##########Rolling Price Change##########

comparedClose = request.security(symbol=comparedWithSecurity, timeframe="", expression=close)

comparedRollingMove = comparedClose - comparedClose[length]

symbolRollingMove = close - close[length]



//##########Rolling ATR Change##########

symbolRollingATR = ta.atr(length)[1]

comparedRollingATR = request.security (symbol=comparedWithSecurity, timeframe="", expression= ta.atr(length)[1])



//##########Calculations##########

powerIndex = comparedRollingMove / comparedRollingATR

RRS = (symbolRollingMove - powerIndex * symbolRollingATR) / symbolRollingATR



//##########Plot##########

RealRelativeStrength = plot(RRS, "RealRelativeStrength", color=color.blue, linewidth=2)

Baseline = plot(0, "Baseline", color=color.red)



//##########Extra Stuff##########

//fill(RealRelativeStrength, Baseline, color = RRS >= 0 ? color.green : color.red, title="fill")



correlated = ta.correlation(close, comparedClose, length)

Correlation = plot(0, title="Correlation", color = correlated > .75 ? #00ff00 : correlated > .50 ? #00C000 : correlated > .25 ? #008000 : correlated > 0.0 ? #004000 :correlated > -.25 ? #400000 :correlated > -.50 ? #800000 :correlated > -.75 ? #C00000 :#FF0000, linewidth=3, style=plot.style_line)
