RSItrend
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AHgpeu

//@version=5
indicator("RSItrend", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

//RSI
rsiLengthInput = input.int(4, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
hline(80,editable =false)
hline (20,editable =false)

//RSI channel
max=rsi
max := rsi[2]<rsi[1] and rsi[1]>rsi ? rsi[1]: max[1]
min=rsi
min := rsi[2]>rsi[1] and rsi[1]<rsi ? rsi[1]:min[1]
plot(max, "max", linewidth = 2,color=color.rgb(44, 168, 81))
plot(min, "min", linewidth = 2,color=color.rgb(216, 48, 48))

//Bar Color
col =color.blue
col := rsi < min or rsi < 20 ? color.blue: rsi> max or rsi > 80 ? color.orange:col[1]
barcolor(col)



