// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yoooounglee
//@version=6
indicator("RSI", shorttitle="RSI", overlay=false)
// RSI 参数设置
len = input.int(14, "RSI Length", group = "RSI") // RSI 的计算周期长度
// RSI 阈值设置
upper_ = input.int(70, "RSI 上限阈值", inline = "RSI 上限阈值") // RSI 上限阈值
lower_ = input.int(30, " RSI 下限阈值", inline = "Threshold") // RSI 下限阈值
// 计算 RSI 值
rsi = ta.rsi(close, len)
// --------------------------------------------------------------------------------------------------------------------}
// 可视化部分
// --------------------------------------------------------------------------------------------------------------------{
// 绘制 RSI 线
rsiPlot = plot(rsi, "RSI", color=chart.fg_color)
// 绘制 RSI 上下限水平线
rsiUpperBand = hline(upper_, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(lower_, "RSI Lower Band", color=#787B86)
// 填充 RSI 背景
fill(rsiUpperBand, rsiLowerBand, color=#c292571a, title="RSI Background Fill")
// 当RSI穿过上下限时,分别加入气泡标签提示超买和超卖
if rsi > upper_ and rsi[1] <= upper_
label.new(bar_index, upper_, "超买", style = label.style_label_down, color = color.red)
if rsi < lower_ and rsi[1] >= lower_
label.new(bar_index, lower_, "超卖", style = label.style_label_up, color = color.green)