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

//@version=5
indicator("Relative Strength against Index", shorttitle = "RelStr")
symbol = input.symbol("SPX", "Reference Index Symbol")
ref_chgATR = request.security(symbol, timeframe.period, ta.change(ohlc4, 1)/ta.atr(11) )
self_chgATR = ta.change(ohlc4, 1) / ta.atr(11)
self_number = 0

if ref_chgATR < -0.5
    if ref_chgATR < -1 and self_chgATR < 2*ref_chgATR
        self_number := -1
    if ref_chgATR < -1 and self_chgATR > 0.5*ref_chgATR
        self_number := 1    
    if self_chgATR > 2
        self_number := 2
    if self_chgATR >= 0.5
        self_number := 1
if ref_chgATR > +0.5
    if ref_chgATR > 1 and self_chgATR > 2*ref_chgATR
        self_number := 1
    if ref_chgATR > 1 and self_chgATR < 0.5*ref_chgATR
        self_number := -1        
    if self_chgATR < -2
        self_number := -2
    if self_chgATR < -0.5
        self_number := -1
plot(ta.cum(self_number))
