RSI on Chart Window
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KhaiGuru

//@version=5
indicator("RSI on Chart Window", overlay = true)

rsi_group = "RSI Setting"
rsi_length = input.int(defval = 14, minval = 1, title = "Length", group = rsi_group, inline = "1")
rsi = ta.rsi(close, rsi_length)
//Adjustment factor for the ratio of RSI to match the ratio of the current chart frame, it will be different for each currency pair
tool_tip_rsi = "Adjustment factor for the ratio of RSI to match the ratio of the current chart frame, depending on the currency pair will be different. With Forex factor = about 10, with Oil factor = about 3, with Gold, BTC factor = about 100"
factor_rsi = input.int(defval = 10, title = "Factor", tooltip = tool_tip_rsi, minval = 1, step = 1) 
//=======overbought

rsi_overbought1 = input.int(defval = 70, title = "RSI Upper Band", minval = 50, maxval = 100, step = 1, group = rsi_group)
overbought1= plot(close + (rsi_overbought1-50)*factor_rsi*syminfo.mintick, title = "RSI Upper Band", color = color.rgb(175, 125, 125), display = display.none)
label_1 = label.new(bar_index+6, close + (rsi_overbought1-50)*factor_rsi*syminfo.mintick, textcolor= color.rgb(255, 1, 1), style = label.style_none)
label.delete(label_1[1])

//======oversold

rsi_oversold1 = input.int(defval = 30, title = "RSI Lower Band", minval = 1, maxval = 50, step = 1, group = rsi_group)
oversold1= plot(close - (50-rsi_oversold1)*factor_rsi*syminfo.mintick, title = "RSI Lower Band", color = color.rgb(63, 119, 65), display = display.none)
label_3 = label.new(bar_index+6, close - (50-rsi_oversold1)*factor_rsi*syminfo.mintick, textcolor= color.rgb(92, 133, 109) , style = label.style_none)
label.delete(label_3[1])

//==========RSI now
rsi_show_last = input.int(defval = 1000, minval = 5, title = "Show Last", step = 5, group = rsi_group)
rsi_color = (rsi >= rsi_overbought1)? color.red : (rsi <= rsi_oversold1) ? color.green : color.rgb(143, 139, 109)
rsi_now = plot(close + (rsi - 50)*factor_rsi*syminfo.mintick, title = "RSI color", show_last = rsi_show_last, color = rsi_color, display = display.pane)
label_rsi = label.new(bar_index + 4, close + (rsi - 50)*factor_rsi*syminfo.mintick,  textcolor = rsi_color, text = "RSI = " + str.tostring(math.round(rsi, 2)), style = label.style_none, textalign = text.align_right)
label.delete((label_rsi[1]))

//===========display Overbought & Oversold candles
plotshape( (rsi >= rsi_overbought1), location = location.abovebar, color = color.red, style = shape.triangledown, display = display.pane)
plotshape( (rsi <= rsi_oversold1), location = location.belowbar, color = color.green, style = shape.triangleup, display = display.pane)

