RSI Divergence Tops + Bottoms

capriole_charles · study · 63 行 · 点赞 3,259 · TradingView 原页

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

Pine Script

//@version=4
 
// Author: Charles Edwards, 2019
study("RSI Divergence Tops + Bottoms")
 
plot_bands = input(true,"Plot Overbought / Oversold Bands?")
 
plot_troughs = input(false,"Plot Potential RSI troughs?")
plot_peaks = input(false,"Plot Potential RSI peaks?")
 
plot_troughs_d = input(true,"Plot RSI Troughs Divergence?")
plot_peaks_d = input(true,"Plot RSI Peak Divergence?")
 
change = change(close)
gain = change >= 0 ? change : 0.0
loss = change < 0 ? (-1) * change : 0.0
avgGain = rma(gain, 14)
avgLoss = rma(loss, 14)
rs = avgGain / avgLoss
rsi = 100 - (100 / (1 + rs))
 
 
plot(rsi,color=color.white,linewidth=3)
over_sold = plot((plot_bands ? 30.0 : na), color=color.green,linewidth=1)
mediam = plot((plot_bands ? 50.0 : na), color =color.gray,linewidth=1,transp=30,style=plot.style_linebr)
over_bought = plot((plot_bands ? 70.0 : na), color=color.red,linewidth=1) 
extreme_over_bought = plot((plot_bands ? 90.0 : na), color=color.red,linewidth=1)
 
min = plot((plot_bands ? 0.0 : na), color=color.green,linewidth=1) //dashed or dotted
max = plot((plot_bands ? 100.0 : na), color=color.red,linewidth=1) //dashed or dotted
fill(min,over_sold,plot_bands ? color.green : na, title="RegionFill", transp=90)
fill(over_bought,extreme_over_bought,plot_bands ? color.red : na, title="RegionFill", transp=95)
fill(extreme_over_bought,max,plot_bands ? color.red : na, title="RegionFill", transp=80)
 
 
// RSI DIVERGENCE LOGIC
top = false
top := avg(rsi[4],rsi[3]) < rsi[2] 
     and avg(rsi,rsi[1]) < rsi[2] 
     and rsi[2] > 60
     and top[1] == false
     
bottom = false
bottom := avg(rsi[4],rsi[3]) > rsi[2] 
     and avg(rsi,rsi[1]) > rsi[2] 
     and rsi[2] < 40
     and bottom[1] == false
 
sell = false
sell := top == true 
     and rsi[2] < valuewhen(top==true,rsi[2],1)
     and close[2] > valuewhen(top==true,close[2],1)
     
buy = false
buy := bottom == true 
     and rsi[2] > valuewhen(bottom==true,rsi[2],1)
     and close[2] < valuewhen(bottom==true,close[2],1)
 
plotshape(plot_peaks ? top : na,style=shape.circle,location=location.top,size = size.normal, color=color.gray)    
plotshape(plot_peaks_d ? sell : na,style=shape.circle,location=location.top,size = size.normal, color=color.red)
 
plotshape(plot_troughs ? bottom : na,style=shape.circle,location=location.bottom,size = size.normal, color=color.gray)
plotshape(plot_peaks_d ? buy : na,style=shape.circle,location=location.bottom,size = size.normal, color=color.lime)

← 返回列表