本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Quantum-Edge-Capital
//@version=6
indicator('RSI FOR HFT [Quant Edge]', ' RSI FAST ')
//------------------------------------------------------------------------------
// Settings
//------------------------------------------------------------------------------
length = input.int(7, minval = 2)
smoType1 = input.string('EMA', 'Method', options = ['EMA', 'SMA', 'RMA', 'TMA'])
src = input.source(close, 'Source')
// Neutral RSI color matched to the reference.
// Auto is disabled by default so the selected color is used consistently.
arsiCss = input.color(#D3D3D3, 'Color', inline = 'rsicss')
autoCss = input.bool(false, 'Auto', inline = 'rsicss')
// Signal Line
smooth = input.int(11, minval = 1, group = 'Signal Line')
smoType2 = input.string('EMA', 'Method', options = ['EMA', 'SMA', 'RMA', 'TMA'], group = 'Signal Line')
signalCss = input.color(#FFFF00, 'Color', group = 'Signal Line')
// OB/OS Style
obValue = input.float(80, 'Overbought', inline = 'ob', group = 'OB/OS Style')
obCss = input.color(#00FF00, '', inline = 'ob', group = 'OB/OS Style')
obAreaCss = input.color(color.new(#00FF00, 80), '', inline = 'ob', group = 'OB/OS Style')
osValue = input.float(20, 'Oversold', inline = 'os', group = 'OB/OS Style')
osCss = input.color(#FF002B, '', inline = 'os', group = 'OB/OS Style')
osAreaCss = input.color(color.new(#FF002B, 80), '', inline = 'os', group = 'OB/OS Style')
//------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------
ma(x, len, maType) =>
switch maType
'EMA' => ta.ema(x, len)
'SMA' => ta.sma(x, len)
'RMA' => ta.rma(x, len)
'TMA' => ta.sma(ta.sma(x, len), len)
//------------------------------------------------------------------------------
// Augmented RSI — original calculations unchanged
//------------------------------------------------------------------------------
upper = ta.highest(src, length)
lower = ta.lowest(src, length)
r = upper - lower
d = src - src[1]
diff = upper > upper[1] ? r : lower < lower[1] ? -r : d
num = ma(diff, length, smoType1)
den = ma(math.abs(diff), length, smoType1)
arsi = num / den * 50 + 50
signal = ma(arsi, smooth, smoType2)
//------------------------------------------------------------------------------
// Plots
//------------------------------------------------------------------------------
rsiColor = arsi > obValue ? obCss : arsi < osValue ? osCss : autoCss ? chart.fg_color : arsiCss
plot_rsi = plot(arsi, 'Ultimate RSI', color = rsiColor, linewidth = 1)
plot(signal, 'Signal Line', color = signalCss, linewidth = 1)
// Hidden levels used for fills
plot_up = plot(obValue, color = na, editable = false)
plot_avg = plot(50, color = na, editable = false)
plot_dn = plot(osValue, color = na, editable = false)
// OB/OS fills
fill(plot_rsi, plot_up, color = arsi > obValue ? obAreaCss : na, title = 'Overbought Fill')
fill(plot_dn, plot_rsi, color = arsi < osValue ? osAreaCss : na, title = 'Oversold Fill')
// Original gradient structure, using the matched palette
fill(plot_rsi, plot_avg, obValue, 50, obAreaCss, color.new(chart.bg_color, 100))
fill(plot_avg, plot_rsi, 50, osValue, color.new(chart.bg_color, 100), osAreaCss)
// Reference lines matched to the screenshot
hline(obValue, 'Overbought', color = #FF002B, linestyle = hline.style_solid)
hline(50, 'Midline', color = #B2B5BE, linestyle = hline.style_dotted)
hline(osValue, 'Oversold', color = #00FF00, linestyle = hline.style_solid)