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

//@version=5
indicator(title='Relative Strength Index with Range Shift', shorttitle='RSI', overlay=false, precision=1)

var table conditionTable = table.new(position=position.top_right, columns=1, rows=1)

log = input.string(title='Scale', options=['Logarithmic', 'Regular'], defval='Logarithmic')
range_1 = input.string(title='Range Bias', options=['Bullish', 'Strong Bullish', 'Bearish', 'Strong Bearish', 'No Bias'], defval='Bullish')
lookbackPeriod = input(title='Lookback Period', defval=14)
source = input(title='Source', defval=close)

rangeShift(range_2) =>
    if range_2 == 'Bullish'
        [40, 60, 80]
    else if range_2 == 'Strong Bullish'
        [45, 65, 85]
    else if range_2 == 'Bearish'
        [35, 55, 75]
    else if range_2 == 'Strong Bearish'
        [30, 50, 70]
    else
        [40, 60, 80]

condition(rsi, range_3) =>
    [lo, mid, hi] = rangeShift(range_3)
    if rsi <= lo
        [color.green, 'Very Oversold']
    else if rsi <= mid
        [color.yellow, 'Oversold']
    else if rsi <= hi
        [color.orange, 'Overbought']
    else
        [color.red, 'Very Overbought']

rsiSource = (log == 'Logarithmic' ? math.log(source) : source)
rsi = ta.rsi(rsiSource, lookbackPeriod)
[col, txt] = condition(rsi, range_1)
table.cell(conditionTable, 0, 0, text=txt, bgcolor=col)
plot(series=rsi, title='Relative Strength Index', color=col)

