Stock Relative Strength Power Index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © christoefert

//@version=5
indicator(title="Relative Strength vs. Market Power Rating", shorttitle="Power Rating", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

//Get the Rates of Change

//Get Rate of Chage for Security
length = input.int(5, minval=1, title = "Current Ticker Length")
source = input(close, "Source")
roc = 100 * (source - source[length])/source[length]

//Get Rate of Change for Market
length2 = input.int(5, minval=1, title = "SPY Length")
MarketChange = request.security("SPY", "", close)
source2 = MarketChange
roc2 = 100 * (source2 - source2[length2])/source2[length2]

//Get Rate of Change for Sector Index
length3 = input.int(5, minval = 1, title = "Sector ETF")
SectorChange = (request.security(input.symbol(""), "", close))
source3 = SectorChange
roc3 = 100 * (source3 - source3[length3])/source3[length3]

//Get the Normalized ATRs

//Get Normalized ATR for Security
Normalized_ATR_Security = (ta.atr(length)/close) * 100

//Get Normalized ATR for Market
MarketATR = (request.security("SPY", "", ta.atr(length2)))
Normalized_ATR_Market = (MarketATR/MarketChange) * 100

//Get Normalized ATR for Sector ETF
SectorATR = (request.security(input.symbol(""), "", ta.atr(length3)))
Normalized_ATR_Sector = (SectorATR/SectorChange) * 100

//Plot Everything
hline(0, color=#787B86, title="Zero Line")
hline(1, color=color.green, title="Long Line")
hline(-1, color=color.red, title="ShortLine")
plot(roc/Normalized_ATR_Security, color=color.aqua, title = "Current Security")
plot(roc2/Normalized_ATR_Market, color=color.red, title = "SPY")
plot(roc3/Normalized_ATR_Sector, color=color.white, title = "Sector")
