Webby's RSI 2.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amphibiantrading

//@version=5
indicator("Webby RSI 2.0")

//constants
EMA21 = ta.ema(close,21)
SMA10 = ta.sma(close,10)

//inputs
atrLen  = input.int(50, 'Atr Length')
osLevel = input.int(3, 'Stretched Level')
posCol  = input.color(color.green, 'Above 21 Color')
negCol  = input.color(color.red, 'Below 21 Color')
maCol   = input.color(color.orange, 'Moving Average Extension Color')

//atr
atr = ta.atr(50)

// vs 21 & 10
lowV21  =   low - EMA21 
highV21 =   EMA21 - high
highV10 =   high - SMA10

//calculations
rsiPos =    lowV21 / atr
rsiNeg =    highV21 / atr
smaPos =    highV10 / atr

//plots
plot(rsiPos > 0 ? rsiPos : na, 'ATR > 21', posCol, 2, plot.style_histogram)
plot(rsiNeg > 0 ? rsiNeg : na, 'ATR < 21', negCol, 2, plot.style_histogram)
hline(osLevel, 'Extended Level', color.red, hline.style_solid, 2)
plot(smaPos > 0 ? smaPos : na, 'SMA Extension', maCol, 2, plot.style_linebr)
