本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator(title = 'StochRSI of DI Oscillator', shorttitle = 'SR(DI Osc)', overlay = false)
// 입력 변수 설정
len = input.int(14, title = 'DI Length', minval = 1)
signalLen = input.int(14, title = 'DI Signal Length', minval = 1)
rsiLen = input.int(14, title = 'RSI period', minval = 1)
stochLen = input.int(7, title = 'Stochastic period', minval = 1)
kLen = input.int(3, title = '%K smoothing period', minval = 1)
dLen = input.int(3, title = '%D smoothing period', minval = 1)
// +DM, -DM calculation
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : up > down and up > 0 ? up : 0.0
minusDM = na(down) ? na : down > up and down > 0 ? down : 0.0
// True Range and DM smoothing (Wilder’s smoothing method)
trur = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / trur)
minus = fixnan(100 * ta.rma(minusDM, len) / trur)
// Calculation of the DI oscillator (+DI minus -DI)
diOsc = plus - minus
signalLine = ta.ema(diOsc, signalLen)
// RSI calculation based on the DI oscillator (diOsc)
diRsi = ta.rsi(diOsc, rsiLen)
// Calculation of Stochastic based on RSI (StochRSI)
lowestRsi = ta.lowest(diRsi, stochLen)
highestRsi = ta.highest(diRsi, stochLen)
stochRsi = highestRsi - lowestRsi == 0 ? 0 : (diRsi - lowestRsi) / (highestRsi - lowestRsi) * 100
// Calculation of %K and %D signal lines
k = ta.sma(stochRsi - 50, kLen)
d = ta.sma(k, dLen)
// Visualization
oscColor = color.new(color.green, 40)
d1 = plot(diOsc, title = 'DI Oscillator', style = plot.style_line, color = oscColor, linewidth = 1)
d2 = plot(signalLine, title = 'DI Signal Line', color = color.orange, linewidth = 1, display = display.none)
fill(d1, d2, diOsc > signalLine ? color.new(color.green, 10) : color.new(color.red, 10))
plot(k, title = '%K', color = color.new(#ff00ff, 0), linewidth = 1)
plot(d, title = '%D', color = color.new(#9800ff, 50), linewidth = 1)
// Overbought / oversold threshold lines
hline(30, title = 'Overbought', color = color.red, linestyle = hline.style_dashed)
hline(-30, title = 'Oversold', color = color.green, linestyle = hline.style_dashed)
hline(50, title = 'Upper Band', color = color.gray, linestyle = hline.style_solid)
hline(0, title = '0', color = color.gray, linestyle = hline.style_solid)
hline(-50, title = 'Lower Band', color = color.gray, linestyle = hline.style_solid)