Relative Strength Index - Divergences - Libertus

Libertus · study · 50 行 · 点赞 10,003 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=3
study(title="Relative Strength Index - Divergences - Libertus", shorttitle="RSI - Lib")
src = close
len = input(14, minval=1, title="RSI Length")
ob = input(70, "Overbought", integer, minval=0, maxval=100)
os = input(30, "Oversold", integer, minval=0, maxval=100)
 
// RSI code
rsi = rsi(src, len)
band1 = hline(ob)
band0 = hline(os)
plot(rsi, color=(rsi > ob or rsi < os ? red : black), transp=0)
fill(band1, band0, color=purple, transp=97)
 
// Divs code
xbars = input(50, "Div lookback period (bars)?", integer, minval=1)
xbars_to_len = xbars*interval*(isdaily ? 1440 : isweekly ? 1440*7 : ismonthly ? 1440*30 : 1)
xms = 1000 * 60 * xbars_to_len // millisecs * secs * min * hours * days
leftborder = (timenow - time) < xms  // true or na when false
 
max = na
max_rsi = na
min = na
min_rsi = na
 
max := not leftborder ? na : na(max[1]) ? close : max[1]
max_rsi := not leftborder ? na : na(max_rsi[1]) ? rsi : max_rsi[1]
min := not leftborder ? na : na(min[1]) ? close : min[1]
min_rsi := not leftborder ? na : na(min_rsi[1]) ? rsi : min_rsi[1]
 
// compare high of current bar being examined with previous bar's high
// if curr bar high is higher than the max bar high in the lookback window range
if close > max // we have a new high
    max := close // change variable "max" to use current bar's high value
if rsi > max_rsi // we have a new high
    max_rsi := rsi // change variable "max_rsi" to use current bar's RSI value
if close < min // we have a new low
    min := close // change variable "min" to use current bar's low value
if rsi < min_rsi // we have a new low
    min_rsi := rsi // change variable "min_rsi" to use current bar's low RSI
 
divbear = 0
divbull = 0
if (max > max[1]) and (rsi < max_rsi)
    divbear := 1
if (min < min[1]) and (rsi > min_rsi)
    divbull := 1
 
plotshape(divbear, location=location.top, style=shape.triangledown, color=red, size=size.tiny)
plotshape(divbull, location=location.bottom, style=shape.triangleup, color=green, size=size.tiny)

← 返回列表