Advantage RSI Predictor
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AdvantageTrading


//@version=5
indicator(title="Advantage RSI Predictor", shorttitle="Advantage RSI Predictor", overlay=true, format=format.price, timeframe="", timeframe_gaps=true)

rsiLengthInput = input.int(14, minval=1, title="Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
up_level = input.float(70, "overbought level",maxval=99,minval=50, group="RSI Predictor Settings")
down_level = input.float(30, "oversold level",maxval=50,minval=1, group="RSI Predictor Settings")
line50 = input(true, '50-point line On/Off')

up      = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down    = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)

SF = 1/rsiLengthInput
X1 = up_level/(100 - up_level)
X2 = (100 - down_level)/down_level

resistance  = rsiSourceInput + (rsiLengthInput -1) * (X1 * down - up)
support     = rsiSourceInput - (rsiLengthInput -1) * (X2 * up - down)
middle      = rsiSourceInput - (rsiLengthInput -1) * (up - down)

plot(resistance, "resistance", color=color.red, offset=1)
plot(support, "support", color=color.red, offset=1)
plot(line50 ? middle : na, "50-point line", color=color.black, offset=1)