RSI + Divergences

Socrate_FR · study · 925 行 · 点赞 2,738 · TradingView 原页

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

Pine Script

//@version=4
//This is Vash's Advanced RSI upgraded mixed up with @fikira's RSI divergences indicator
 
//RSI advanced from @Vash customized by @Socrate
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Taken from Vash's Youtube tutorial
 
 
//RSI Div from @fikira
// This source code is subject to the terms of the Creative Commons Zero v1.0 Universal license
// https://github.com/fikira12/Divergences
// https://github.com/fikira12/Divergences/blob/master/RSI
// Copyright (c) 2019 @fikira
 
//Mixed up and fine tuned by ©hisocrate
 
 
study(title="RSI + Divergences", shorttitle="RSI + Div by Socrate", max_bars_back = 2000)
 
 
// RSI
 
col_black = color.new(color.black, 100)
 
//Input
src = input(close, title="Source")
rsi_len = input(14, minval=1, title="RSI Length")
rsi_fast_len = input(5, minval=1, title="Fast RSI Length")
rsi_ema_len = input(14, minval=1, title="EMA Length")
overbought = input(70, minval=1, title="Overbought")
oversold = input(30, minval=1, title="Oversold")
 
//Logic
 
rsi = rsi(src, rsi_len)
rsi_fast = rsi(src, rsi_fast_len)
rsi_ema = ema(rsi, rsi_ema_len)
 
//View
 
color_short = #FF5252
color_long = #64FFDA
color_neutral = #FFD600
 
 
p_rsi_fast = plot(rsi_fast, title = "Fast RSI", style=plot.style_line, linewidth=1, transp=100, color=color_neutral)
p_rsi_ema = plot(rsi_ema, title = "RSI EMA", style=plot.style_line, linewidth=1, transp=20, color=color.blue)
fill (p_rsi_ema, p_rsi_fast, color = rsi_fast > rsi_ema ? color_long : color_short, transp=75, title = "RSI Cloud Fill")
p_rsi = plot(rsi, title = "RSI", style=plot.style_line, linewidth=2, transp=0, color=color.white)
 
//Grid
 
Ex_os =  hline(100, linestyle=plot.style_line, linewidth=3, color=color.red)
Ex_ob = hline(0, linestyle=plot.style_line, linewidth=3, color=color.green)
 
green = color.new(#00C000, transp=80)
red = color.new(#FF0000,transp=80)
white = color.new(#FFFFFF,transp=95)
 
 
Overbought = hline(70, linestyle=plot.style_line, linewidth=1, color=color.red)
Oversold = hline(30, linestyle=plot.style_line, linewidth=1, color=color.green)
 
Grid_10 = hline(10, linestyle=plot.style_line, linewidth=2, color=green)
Grid_20 = hline(20, linestyle=plot.style_line, linewidth=1, color=green)
Grid_40 = hline(40, linestyle=plot.style_line, linewidth=1, color=white)
Grid_50 = hline(50, linestyle=plot.style_line, linewidth=1, color=white) 
Grid_60 = hline(60, linestyle=plot.style_line, linewidth=1, color=white) 
Grid_80 = hline(80, linestyle=plot.style_line, linewidth=1, color=red)
Grid_90 = hline(90, linestyle=plot.style_line, linewidth=2, color=red) 
 
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
DIV = input(false, title="-<><><><><><>[Divergences]<><><><><><>-")
 
nwh = close > open ? close : na 
nwl = close < open ? close : na 
 
nwh_ = close > open ? high : close < open ? high : na 
nwl_ = close > open ? low : close < open ? low : na 
 
show_div = input(true, title="Show Regular Divergences")
 
arrows = input(false, title="Just Show Arrows (No Lines)")
 
dot = input(title="[Divergences] Line Type", defval="solid", options=["solid", "dashed", "dotted"]) 
lw = input(3, minval=0, maxval=10, title="[Divergences] linewidth")
 
_dot = line.style_solid
if dot == "solid"
    _dot := line.style_solid
else
    if dot == "dashed"
        _dot := line.style_dashed
    else
        if dot == "dotted"
            _dot := line.style_dotted
 
//solid = input(title="Line Type [Connections]", defval="solid", options=["solid", "dashed", "dotted"]) 
//_solid = line.style_solid
//if solid == "solid"
//    _solid := line.style_solid
//else
//    if solid == "dashed"
//        _solid := line.style_dashed
//    else
//        if solid == "dotted"
//            _solid := line.style_dotted
 
symbl = input(title="[Divergences] Bullish Labels", defval="Label Up", 
 options=["Label Up", "Arrow Up", "Triangle Up", "Circle", "Square", "Xcross", "Cross", "Flag", "Diamond"]) 
 
_symbl = label.style_labelup
if symbl == "Label Up"
    _symbl := label.style_labelup
else
    if symbl == "Arrow Up"
        _symbl := label.style_arrowup
    else
        if symbl == "Triangle Up"
            _symbl := label.style_triangleup
        else
            if symbl == "Circle"
                _symbl := label.style_circle
            else
                if symbl == "Square"
                    _symbl := label.style_square 
                else
                    if symbl == "Xcross"
                        _symbl := label.style_xcross
                    else
                        if symbl == "Cross"
                            _symbl := label.style_cross
                        else
                            if symbl == "Flag"
                                _symbl := label.style_flag 
                            else
                                if symbl == "Diamond"
                                    _symbl := label.style_diamond
                                    
symbr = input(title="[Divergences] Bearish Labels", defval="Label Down", 
 options=["Label Down", "Arrow Down", "Triangle Down", "Circle", "Square", "Xcross", "Cross", "Flag", "Diamond"]) 
 
_symbr = label.style_labeldown
if symbr == "Label Down"
    _symbr := label.style_labeldown
else
    if symbr == "Arrow Down"
        _symbr := label.style_arrowdown
    else
        if symbr == "Triangle Down"
            _symbr := label.style_triangledown
        else
            if symbr == "Circle"
                _symbr := label.style_circle
            else
                if symbr == "Square"
                    _symbr := label.style_square 
                else
                    if symbr == "Xcross"
                        _symbr := label.style_xcross
                    else
                        if symbr == "Cross"
                            _symbr := label.style_cross
                        else
                            if symbr == "Flag"
                                _symbr := label.style_flag 
                            else
                                if symbr == "Diamond"
                                    _symbr := label.style_diamond
 
size = input(title="[Divergences] Label Size", defval="Auto", 
 options=["Tiny", "Small", "Normal", "Auto"]) 
 
_size = size.auto
if size == "Tiny"
    _size := size.tiny
else
    if size == "Small"
        _size := size.small
    else
        if size == "Normal"
            _size := size.normal
        else
            if size == "Auto"
                _size := size.auto
 
Bars = input(false, title="-<><><><><><>[LeftBars   RightBars]<><><><><><>-")
 
LB = input(1, title = "LeftBars")                      
RB = input(1, title = "RightBars")                    
 
ph = pivothigh(nwh, LB, RB)     
pl = pivotlow(nwl, LB, RB)       
ph_ = pivothigh(nwh_, LB, RB)     
pl_ = pivotlow(nwl_, LB, RB) 
rh = pivothigh(rsi, LB, RB)      
rl = pivotlow(rsi, LB, RB)       
 
hh0 = valuewhen(ph, nwh[1], 0)                                        
ll0 = valuewhen(pl, nwl[1], 0)                                         
rsih0 = hh0 ? valuewhen(ph, rsi[1], 0) : na
rsil0 = ll0 ? valuewhen(pl, rsi[1], 0) : na
//plotshape(ll0 and pl ? ll0 : na, color=color.olive)
//plotshape(rsil0 and pl ? rsil0 : na, color=color.red, location=location.belowbar)
 
hh1 = hh0 ? valuewhen(ph, nwh[1], 1) : na  
hh1_ = hh0 ? valuewhen(ph, nwh_[1], 1) : na  
ll1 = ll0 ? valuewhen(pl, nwl[1], 1) : na                                      
ll1_ = ll0 ? valuewhen(pl, nwl_[1], 1) : na 
rsih1 = hh0 ? valuewhen(ph, rsi[1], 1) : na
rsil1 = ll0 ? valuewhen(pl, rsi[1], 1) : na
//plotshape(ll1 and pl ? ll1 : na)
 
hh2 = hh0 ? valuewhen(ph, nwh[1], 2) : na  
hh2_ = hh0 ? valuewhen(ph, nwh_[1], 2) : na 
ll2 = ll0 ? valuewhen(pl, nwl[1], 2) : na 
ll2_ = ll0 ? valuewhen(pl, nwl_[1], 2) : na 
rsih2 = hh0 ? valuewhen(ph, rsi[1], 2) : na
rsil2 = ll0 ? valuewhen(pl, rsi[1], 2) : na
 
hh3 = hh0 ? valuewhen(ph, nwh[1], 3) : na  
hh3_ = hh0 ? valuewhen(ph, nwh_[1], 3) : na 
ll3 = ll0 ? valuewhen(pl, nwl[1], 3) : na 
ll3_ = ll0 ? valuewhen(pl, nwl_[1], 3) : na 
rsih3 = hh0 ? valuewhen(ph, rsi[1], 3) : na
rsil3 = ll0 ? valuewhen(pl, rsi[1], 3) : na
 
hh4 = hh0 ? valuewhen(ph, nwh[1], 4) : na  
hh4_ = hh0 ? valuewhen(ph, nwh_[1], 4) : na 
ll4 = ll0 ? valuewhen(pl, nwl[1], 4) : na 
ll4_ = ll0 ? valuewhen(pl, nwl_[1], 4) : na 
rsih4 = hh0 ? valuewhen(ph, rsi[1], 4) : na
rsil4 = ll0 ? valuewhen(pl, rsi[1], 4) : na
 
hh5 = hh0 ? valuewhen(ph, nwh[1], 5) : na  
hh5_ = hh0 ? valuewhen(ph, nwh_[1], 5) : na 
ll5 = ll0 ? valuewhen(pl, nwl[1], 5) : na 
ll5_ = ll0 ? valuewhen(pl, nwl_[1], 5) : na 
rsih5 = hh0 ? valuewhen(ph, rsi[1], 5) : na
rsil5 = ll0 ? valuewhen(pl, rsi[1], 5) : na
 
hh6 = hh0 ? valuewhen(ph, nwh[1], 6) : na  
hh6_ = hh0 ? valuewhen(ph, nwh_[1], 6) : na 
ll6 = ll0 ? valuewhen(pl, nwl[1], 6) : na 
ll6_ = ll0 ? valuewhen(pl, nwl_[1], 6) : na 
rsih6 = hh0 ? valuewhen(ph, rsi[1], 6) : na
rsil6 = ll0 ? valuewhen(pl, rsi[1], 6) : na
 
hh7 = hh0 ? valuewhen(ph, nwh[1], 7) : na  
hh7_ = hh0 ? valuewhen(ph, nwh_[1], 7) : na 
ll7 = ll0 ? valuewhen(pl, nwl[1], 7) : na 
ll7_ = ll0 ? valuewhen(pl, nwl_[1], 7) : na 
rsih7 = hh0 ? valuewhen(ph, rsi[1], 7) : na
rsil7 = ll0 ? valuewhen(pl, rsi[1], 7) : na
 
hh8 = hh0 ? valuewhen(ph, nwh[1], 8) : na  
hh8_ = hh0 ? valuewhen(ph, nwh_[1], 8) : na 
ll8 = ll0 ? valuewhen(pl, nwl[1], 8) : na 
ll8_ = ll0 ? valuewhen(pl, nwl_[1], 8) : na 
rsih8 = hh0 ? valuewhen(ph, rsi[1], 8) : na
rsil8 = ll0 ? valuewhen(pl, rsi[1], 8) : na
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
_m = input(title="Margin", defval="0", options=["0", "0.236", "0.382", "0.5", "0.618", "0.786", "1", "1.272", "1.618", "1.786", "2"])  
 
m = 0.5
if _m == "0"
    m := 0 
else
    if _m == "0.236"
        m := 0.236
    else
        if _m == "0.382"
            m := 0.382
        else
            if _m == "0.5"
                m := 0.5
            else
                if _m == "0.618"
                    m := 0.618
                else
                    if _m == "0.786"
                        m := 0.786
                    else
                        if _m == "1"
                            m := 1
                        else
                            if _m == "1.272"
                                m := 1.272
                            else
                                if _m == "1.618"
                                    m := 1.618
                                else
                                    if _m == "1.786"
                                        m := 1.786
                                    else
                                        if _m == "2"
                                            m := 2
 
 
// Bullish Divergences = close LL - RSI HL
 
close_LL1 = ll0 < ll1
rsi_HL1 = rsil0 > rsil1
 
close_LL2 = ll0 < ll2 
 and ll1 > ll0 and ll1 > (ll2_ - ((ll2_ - ll0) * m))
rsi_HL2 = rsil0 > rsil2
 and rsil1 > rsil2 
 and rsil1 > (rsil2 + ((rsil0 - rsil2) / 2))
 
close_LL3 = ll0 < ll3 
 and ll1 > ll0 and ll1 > (ll3_ - ((ll3_ - ll0) * m))
 and ll2 > ll0 and ll2 > (ll3_ - ((ll3_ - ll0) * m))
rsi_HL3 = rsil0 > rsil3 
 and rsil1 > (rsil3 + ((rsil0 - rsil3) / 2))
 and rsil2 > (rsil3 + ((rsil0 - rsil3) / 2))
 
close_LL4 = ll0 < ll4 
 and ll1 > ll0 and ll1 > (ll4_ - ((ll4_ - ll0) * m)) 
 and ll2 > ll0 and ll2 > (ll4_ - ((ll4_ - ll0) * m)) 
 and ll3 > ll0 and ll3 > (ll4_ - ((ll4_ - ll0) * m))
rsi_HL4 = rsil0 > rsil4 
 and rsil1 > (rsil4 + ((rsil0 - rsil4) / 2))
 and rsil2 > (rsil4 + ((rsil0 - rsil4) / 2))
 and rsil3 > (rsil4 + ((rsil0 - rsil4) / 2))
 
close_LL5 = ll0 < ll5 
 and ll1 > ll0 and ll1 > (ll5_ - ((ll5_ - ll0) * m)) 
 and ll2 > ll0 and ll2 > (ll5_ - ((ll5_ - ll0) * m))
 and ll3 > ll0 and ll3 > (ll5_ - ((ll5_ - ll0) * m))
 and ll4 > ll0 and ll4 > (ll5_ - ((ll5_ - ll0) * m))
rsi_HL5 = rsil0 > rsil5 
 and rsil1 > (rsil5 + ((rsil0 - rsil5) / 2))
 and rsil2 > (rsil5 + ((rsil0 - rsil5) / 2)) 
 and rsil3 > (rsil5 + ((rsil0 - rsil5) / 2))
 and rsil4 > (rsil5 + ((rsil0 - rsil5) / 2))
 
close_LL6 = ll0 < ll6 
 and ll1 > ll0 and ll1 > (ll6_ - ((ll6_ - ll0) * m))
 and ll2 > ll0 and ll2 > (ll6_ - ((ll6_ - ll0) * m))
 and ll3 > ll0 and ll3 > (ll6_ - ((ll6_ - ll0) * m))
 and ll4 > ll0 and ll4 > (ll6_ - ((ll6_ - ll0) * m))
 and ll5 > ll0 and ll5 > (ll6_ - ((ll6_ - ll0) * m))
rsi_HL6 = rsil0 > rsil6 
 and rsil1 > (rsil6 + ((rsil0 - rsil6) / 2)) 
 and rsil2 > (rsil6 + ((rsil0 - rsil6) / 2)) 
 and rsil3 > (rsil6 + ((rsil0 - rsil6) / 2)) 
 and rsil4 > (rsil6 + ((rsil0 - rsil6) / 2)) 
 and rsil5 > (rsil6 + ((rsil0 - rsil6) / 2))
 
close_LL7 = ll0 < ll7 
 and ll1 > ll0 and ll1 > (ll7_ - ((ll7_ - ll0) * m))
 and ll2 > ll0 and ll2 > (ll7_ - ((ll7_ - ll0) * m))
 and ll3 > ll0 and ll3 > (ll7_ - ((ll7_ - ll0) * m))
 and ll4 > ll0 and ll4 > (ll7_ - ((ll7_ - ll0) * m))
 and ll5 > ll0 and ll5 > (ll7_ - ((ll7_ - ll0) * m))
 and ll6 > ll0 and ll6 > (ll7_ - ((ll7_ - ll0) * m))
rsi_HL7 = rsil0 > rsil7 
 and rsil1 > (rsil7 + ((rsil0 - rsil7) / 2)) 
 and rsil2 > (rsil7 + ((rsil0 - rsil7) / 2)) 
 and rsil3 > (rsil7 + ((rsil0 - rsil7) / 2)) 
 and rsil4 > (rsil7 + ((rsil0 - rsil7) / 2)) 
 and rsil5 > (rsil7 + ((rsil0 - rsil7) / 2)) 
 and rsil6 > (rsil7 + ((rsil0 - rsil7) / 2))
 
close_LL8 = ll0 < ll8 
 and ll1 > ll0 and ll1 > (ll8_ - ((ll8_ - ll0) * m))
 and ll2 > ll0 and ll2 > (ll8_ - ((ll8_ - ll0) * m))
 and ll3 > ll0 and ll3 > (ll8_ - ((ll8_ - ll0) * m))
 and ll4 > ll0 and ll4 > (ll8_ - ((ll8_ - ll0) * m))
 and ll5 > ll0 and ll5 > (ll8_ - ((ll8_ - ll0) * m))
 and ll6 > ll0 and ll6 > (ll8_ - ((ll8_ - ll0) * m))
 and ll7 > ll0 and ll7 > (ll8_ - ((ll8_ - ll0) * m))
rsi_HL8 = rsil0 > rsil8 
 and rsil1 > (rsil8 + ((rsil0 - rsil8) / 2)) 
 and rsil2 > (rsil8 + ((rsil0 - rsil8) / 2)) 
 and rsil3 > (rsil8 + ((rsil0 - rsil8) / 2)) 
 and rsil4 > (rsil8 + ((rsil0 - rsil8) / 2)) 
 and rsil5 > (rsil8 + ((rsil0 - rsil8) / 2)) 
 and rsil6 > (rsil8 + ((rsil0 - rsil8) / 2)) 
 and rsil7 > (rsil8 + ((rsil0 - rsil8) / 2))
 
div_bull_1 = close_LL1 and rsi_HL1
div_bull_2 = close_LL2 and rsi_HL2
div_bull_3 = close_LL3 and rsi_HL3
div_bull_4 = close_LL4 and rsi_HL4
div_bull_5 = close_LL5 and rsi_HL5
div_bull_6 = close_LL6 and rsi_HL6
div_bull_7 = close_LL7 and rsi_HL7
div_bull_8 = close_LL8 and rsi_HL8
   
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// Bearish Divergences = close HH - RSI LH
 
close_HH1 = hh0 > hh1
rsi_LH1 = rsih0 < rsih1
 
close_HH2 = hh0 > hh2 
 and hh1 < hh0 and hh1 < (hh2_ + ((hh0 - hh2_) * m))
rsi_LH2 = rsih0 < rsih2 
 and rsih1 < (rsih2 - ((rsih2 - rsih0) / 2)) 
 
close_HH3 = hh0 > hh3 
 and hh1 < hh0 and hh1 < (hh3_ + ((hh0 - hh3_) * m))
 and hh2 < hh0 and hh2 < (hh3_ + ((hh0 - hh3_) * m))
rsi_LH3 = rsih0 < rsih3 
 and rsih1 < (rsih3 - ((rsih3 - rsih0) / 2))  
 and rsih2 < (rsih3 - ((rsih3 - rsih0) / 2))  
 
close_HH4 = hh0 > hh4 
 and hh1 < hh0 and hh1 < (hh4_ + ((hh0 - hh4_) * m)) 
 and hh2 < hh0 and hh2 < (hh4_ + ((hh0 - hh4_) * m))  
 and hh3 < hh0 and hh3 < (hh4_ + ((hh0 - hh4_) * m)) 
rsi_LH4 = rsih0 < rsih4 
 and rsih1 < (rsih4 - ((rsih4 - rsih0) / 2))   
 and rsih2 < (rsih4 - ((rsih4 - rsih0) / 2))  
 and rsih3 < (rsih4 - ((rsih4 - rsih0) / 2)) 
 
close_HH5 = hh0 > hh5 
 and hh1 < hh0 and hh1 < (hh5_ + ((hh0 - hh5_) * m))  
 and hh2 < hh0 and hh2 < (hh5_ + ((hh0 - hh5_) * m))  
 and hh3 < hh0 and hh3 < (hh5_ + ((hh0 - hh5_) * m))  
 and hh4 < hh0 and hh4 < (hh5_ + ((hh0 - hh5_) * m)) 
rsi_LH5 = rsih0 < rsih5 
 and rsih1 < (rsih5 - ((rsih5 - rsih0) / 2))  
 and rsih2 < (rsih5 - ((rsih5 - rsih0) / 2))  
 and rsih3 < (rsih5 - ((rsih5 - rsih0) / 2))  
 and rsih4 < (rsih5 - ((rsih5 - rsih0) / 2)) 
 
close_HH6 = hh0 > hh6 
 and hh1 < hh0 and hh1 < (hh6_ + ((hh0 - hh6_) * m))  
 and hh2 < hh0 and hh2 < (hh6_ + ((hh0 - hh6_) * m))  
 and hh3 < hh0 and hh3 < (hh6_ + ((hh0 - hh6_) * m))  
 and hh4 < hh0 and hh4 < (hh6_ + ((hh0 - hh6_) * m))  
 and hh5 < hh0 and hh5 < (hh6_ + ((hh0 - hh6_) * m)) 
rsi_LH6 = rsih0 < rsih6 
 and rsih1 < (rsih6 - ((rsih6 - rsih0) / 2))  
 and rsih2 < (rsih6 - ((rsih6 - rsih0) / 2))   
 and rsih3 < (rsih6 - ((rsih6 - rsih0) / 2))   
 and rsih4 < (rsih6 - ((rsih6 - rsih0) / 2))   
 and rsih5 < (rsih6 - ((rsih6 - rsih0) / 2))  
 
close_HH7 = hh0 > hh7 
 and hh1 < hh0 and hh1 < (hh7_ + ((hh0 - hh7_) * m))  
 and hh2 < hh0 and hh2 < (hh7_ + ((hh0 - hh7_) * m))  
 and hh3 < hh0 and hh3 < (hh7_ + ((hh0 - hh7_) * m))  
 and hh4 < hh0 and hh4 < (hh7_ + ((hh0 - hh7_) * m))  
 and hh5 < hh0 and hh5 < (hh7_ + ((hh0 - hh7_) * m)) 
 and hh6 < hh0 and hh6 < (hh7_ + ((hh0 - hh7_) * m)) 
rsi_LH7 = rsih0 < rsih7 
 and rsih1 < (rsih7 - ((rsih7 - rsih0) / 2))   
 and rsih2 < (rsih7 - ((rsih7 - rsih0) / 2))  
 and rsih3 < (rsih7 - ((rsih7 - rsih0) / 2))  
 and rsih4 < (rsih7 - ((rsih7 - rsih0) / 2))  
 and rsih5 < (rsih7 - ((rsih7 - rsih0) / 2))  
 and rsih6 < (rsih7 - ((rsih7 - rsih0) / 2)) 
 
close_HH8 = hh0 > hh8 
 and hh1 < hh0 and hh1 < (hh8_ + ((hh0 - hh8_) * m))  
 and hh2 < hh0 and hh2 < (hh8_ + ((hh0 - hh8_) * m))  
 and hh3 < hh0 and hh3 < (hh8_ + ((hh0 - hh8_) * m))  
 and hh4 < hh0 and hh4 < (hh8_ + ((hh0 - hh8_) * m))  
 and hh5 < hh0 and hh5 < (hh8_ + ((hh0 - hh8_) * m)) 
 and hh6 < hh0 and hh6 < (hh8_ + ((hh0 - hh8_) * m))  
 and hh7 < hh0 and hh7 < (hh8_ + ((hh0 - hh8_) * m)) 
rsi_LH8 = rsih0 < rsih8 
 and rsih1 < (rsih8 - ((rsih8 - rsih0) / 2))  
 and rsih2 < (rsih8 - ((rsih8 - rsih0) / 2))  
 and rsih3 < (rsih8 - ((rsih8 - rsih0) / 2)) 
 and rsih4 < (rsih8 - ((rsih8 - rsih0) / 2))  
 and rsih5 < (rsih8 - ((rsih8 - rsih0) / 2))  
 and rsih6 < (rsih8 - ((rsih8 - rsih0) / 2))  
 and rsih7 < (rsih8 - ((rsih8 - rsih0) / 2)) 
 
div_bear_1 = close_HH1 and rsi_LH1 
div_bear_2 = close_HH2 and rsi_LH2 
div_bear_3 = close_HH3 and rsi_LH3
div_bear_4 = close_HH4 and rsi_LH4
div_bear_5 = close_HH5 and rsi_LH5
div_bear_6 = close_HH6 and rsi_LH6
div_bear_7 = close_HH7 and rsi_LH7
div_bear_8 = close_HH8 and rsi_LH8
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 
plotchar(arrows and div_bull_1 and not div_bull_1[1] and show_div, char="↑︎︎", title="Bull Div 1",
 location=location.bottom, color= color.green, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_2 and not div_bull_2[1] and show_div, char="↑︎︎", title="Bull Div 2",
 location=location.bottom, color= color.green, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_3 and not div_bull_3[1] and show_div, char="↑︎︎", title="Bull Div 3",
 location=location.bottom, color= color.green, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_4 and not div_bull_4[1] and show_div, char="↑︎︎", title="Bull Div 4",
 location=location.bottom, color= color.lime, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_5 and not div_bull_5[1] and show_div, char="↑︎︎", title="Bull Div 5",
 location=location.bottom, color= color.lime, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_6 and not div_bull_6[1] and show_div, char="↑︎︎", title="Bull Div 6",
 location=location.bottom, color= color.lime, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_7 and not div_bull_7[1] and show_div, char="↑︎︎", title="Bull Div 7",
 location=location.bottom, color= color.aqua, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bull_8 and not div_bull_8[1] and show_div, char="↑︎︎", title="Bull Div 8",
 location=location.bottom, color= color.aqua, size=size.tiny, transp=0, offset=-1)
 
plotchar(arrows and div_bear_1 and not div_bear_1[1] and show_div, char="↓︎︎", title="Bear Div 1",
 location=location.top, color= color.orange, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_2 and not div_bear_2[1] and show_div, char="↓︎︎", title="Bear Div 2",
 location=location.top, color= color.orange, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_3 and not div_bear_3[1] and show_div, char="↓︎︎", title="Bear Div 3",
 location=location.top, color= color.orange, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_4 and not div_bear_4[1] and show_div, char="↓︎︎", title="Bear Div 4",
 location=location.top, color= color.red, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_5 and not div_bear_5[1] and show_div, char="↓︎︎", title="Bear Div 5",
 location=location.top, color= color.red, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_6 and not div_bear_6[1] and show_div, char="↓︎︎", title="Bear Div 6",
 location=location.top, color= color.red, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_7 and not div_bear_7[1] and show_div, char="↓︎︎", title="Bear Div 7",
 location=location.top, color= color.purple, size=size.tiny, transp=0, offset=-1)
plotchar(arrows and div_bear_8 and not div_bear_8[1] and show_div, char="↓︎︎", title="Bear Div 8",
 location=location.top, color= color.purple, size=size.tiny, transp=0, offset=-1)
 
 
// Alerts
 
div_bull_ = div_bull_1 or div_bull_2 or div_bull_3 or div_bull_4 or div_bull_5 or div_bull_6 or div_bull_7 or div_bull_8 ? true : false
div_bull_alert = div_bull_ and not div_bull_[1] ? true : na
alertcondition(div_bull_alert, title='DIV BULLISH ALERT', message='DIV BULLISH ALERT')
 
 
div_bear_ = div_bear_1 or div_bear_2 or div_bear_3 or div_bear_4 or div_bear_5 or div_bear_6 or div_bear_7 or div_bear_8 ? true : false
div_bear_alert = div_bear_ and not div_bear_[1] ? true : na
alertcondition(div_bear_alert, title='DIV BEARISH ALERT', message='DIV BEARISH ALERT')
 
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
lime = color.new(color.lime, 50)
aqua = color.new(color.aqua, 50)
orange = color.new(color.orange, 50)
purple = color.new(color.purple, 50)
yellow = color.new(color.yellow, 50)
 
 
// Bullish Divergences = close LL - RSI HL
bl1 = 0 
bl_1 = 0  
bl2 = 0
bl_2 = 0  
bl3 = 0 
bl_3 = 0
bl4 = 0 
bl_4 = 0 
bl5 = 0 
bl_5 = 0 
bl6 = 0 
bl_6 = 0 
bl7 = 0 
bl_7 = 0
bl8 = 0 
bl_8 = 0
// Bearish Divergences = close HH - RSI LH
br1 = 0 
br_1 = 0
br2 = 0
br_2 = 0   
br3 = 0
br_3 = 0  
br4 = 0
br_4 = 0     
br5 = 0 
br_5 = 0
br6 = 0 
br_6 = 0 
br7 = 0
br_7 = 0  
br8 = 0
br_8 = 0 
 
 
for i = 0 to 1 
    if not arrows and div_bull_1 and rsi[i] == rsil0 
        break
    bl_1 := bl_1 + 1
    if not arrows and div_bull_2 and rsi[i] == rsil0 
        break
    bl_2 := bl_2 + 1
    if not arrows and div_bull_3 and rsi[i] == rsil0                                                      
        break
    bl_3 := bl_3 + 1
    if not arrows and div_bull_4 and rsi[i] == rsil0                                                       
        break
    bl_4 := bl_4 + 1
    if not arrows and div_bull_5 and rsi[i] == rsil0                                                      
        break
    bl_5 := bl_5 + 1 
    if not arrows and div_bull_6 and rsi[i] == rsil0                                                      
        break
    bl_6 := bl_6 + 1
    if not arrows and div_bull_7 and rsi[i] == rsil0                                                      
        break
    bl_7 := bl_7 + 1 
    if not arrows and div_bull_8 and rsi[i] == rsil0                                                      
        break
    bl_8 := bl_8 + 1 
    if not arrows and rsi[i] == rsil0                                                      
        break    
 
 
for i = 0 to 1    
    if not arrows and div_bear_1 and rsi[i] == rsih0                                                       
        break    
    br_1 := br_1 + 1 
    if not arrows and div_bear_2 and rsi[i] == rsih0                                                       
        break    
    br_2 := br_2 + 1
    if not arrows and div_bear_3 and rsi[i] == rsih0                                                       
        break    
    br_3 := br_3 + 1
    if not arrows and div_bear_4 and rsi[i] == rsih0                                                       
        break    
    br_4 := br_4 + 1
    if not arrows and div_bear_5 and rsi[i] == rsih0                                                      
        break    
    br_5 := br_5 + 1 
    if not arrows and div_bear_6 and rsi[i] == rsih0                                                      
        break    
    br_6 := br_6 + 1 
    if not arrows and div_bear_7 and rsi[i] == rsih0                                                      
        break    
    br_7 := br_7 + 1 
    if not arrows and div_bear_8 and rsi[i] == rsih0                                                      
        break    
    br_8 := br_8 + 1 
    if not arrows and rsi[i] == rsih0                                                     
        break    
 
 
for i = 0 to 100                                                              
    if not arrows and div_bull_1 and rsi[i] == rsil1
        break
    bl1 := bl1 + 1 
    if not arrows and rsi[i] == rsil1                                         
        break    
  
 
for i = 0 to 150 
    if not arrows and div_bull_2 and rsi[i] == rsil2                                          
        break
    bl2 := bl2 + 1
    if not arrows and rsi[i] == rsil2                                         
        break    
 
 
for i = 0 to 200 
    if not arrows and div_bull_3 and rsi[i] == rsil3                                          
        break
    bl3 := bl3 + 1
    if not arrows and rsi[i] == rsil3                                        
        break    
 
 
for i = 0 to 200 
    if not arrows and div_bull_4 and rsi[i] == rsil4                                           
        break
    bl4 := bl4 + 1
    if not arrows and rsi[i] == rsil4                                        
        break    
 
 
for i = 0 to 300 
    if not arrows and div_bull_5 and rsi[i] == rsil5                                         
        break
    bl5 := bl5 + 1
    if not arrows and rsi[i] == rsil5                                       
        break    
 
 
for i = 0 to 400 
    if not arrows and div_bull_6 and rsi[i] == rsil6                                          
        break
    bl6 := bl6 + 1
    if not arrows and rsi[i] == rsil6                                         
        break    
 
 
for i = 0 to 500 
    if not arrows and div_bull_7 and rsi[i] == rsil7                                        
        break
    bl7 := bl7 + 1 
    if not arrows and rsi[i] == rsil7                                        
        break    
 
 
 
for i = 0 to 500 
    if not arrows and div_bull_8 and rsi[i] == rsil8                                       
        break
    bl8 := bl8 + 1 
    if not arrows and rsi[i] == rsil8                                       
        break    
 
 
for i = 0 to 100 
    if not arrows and div_bear_1 and rsi[i] == rsih1                                      
        break    
    br1 := br1 + 1 
    if not arrows and rsi[i] == rsih1                                        
        break    
 
 
for i = 0 to 150 
    if not arrows and div_bear_2 and rsi[i] == rsih2                                            
        break    
    br2 := br2 + 1 
    if not arrows and rsi[i] == rsih2                                       
        break    
 
 
for i = 0 to 200 
    if not arrows and div_bear_3 and rsi[i] == rsih3                                          
        break    
    br3 := br3 + 1 
    if not arrows and rsi[i] == rsih3                                      
        break    
 
 
for i = 0 to 200 
    if not arrows and div_bear_4 and rsi[i] == rsih4                                          
        break    
    br4 := br4 + 1
    if not arrows and rsi[i] == rsih4                                      
        break    
 
 
for i = 0 to 300 
    if not arrows and div_bear_5 and rsi[i] == rsih5                                          
        break    
    br5 := br5 + 1 
    if not arrows and rsi[i] == rsih5                                      
        break    
 
 
for i = 0 to 400 
    if not arrows and div_bear_6 and rsi[i] == rsih6                                         
        break    
    br6 := br6 + 1 
    if not arrows and rsi[i] == rsih6                                      
        break    
 
 
for i = 0 to 500 
    if not arrows and div_bear_7 and rsi[i] == rsih7                                        
        break    
    br7 := br7 + 1                                                               
    if not arrows and rsi[i] == rsih7                                      
        break    
 
    
for i = 0 to 500 
    if not arrows and div_bear_8 and rsi[i] == rsih8                                       
        break    
    br8 := br8 + 1                                                               
    if not arrows and rsi[i] == rsih8                                      
        break    
 
 
// Bullish Divergences = close LL - RSI HL    
if not arrows and show_div and div_bull_1 and not div_bull_2 and not div_bull_3 
 and not div_bull_4 and not div_bull_5 and not div_bull_6 and not div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_1], rsi[bl_1], bar_index[bl1], rsi[bl1], xloc = 
     xloc.bar_index, extend=extend.none, color=color.green)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_1], rsi[bl_1], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=green, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_2 and not div_bull_3 and not div_bull_4 
 and not div_bull_5 and not div_bull_6 and not div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_2], rsi[bl_2], bar_index[bl2], rsi[bl2], xloc = 
     xloc.bar_index, extend=extend.none, color=color.green)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_2], rsi[bl_2], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=green, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_3 and not div_bull_4 and not div_bull_5 
 and not div_bull_6 and not div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_3], rsi[bl_3], bar_index[bl3], rsi[bl3], xloc = 
     xloc.bar_index, extend=extend.none, color=color.green)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_3], rsi[bl_3], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=green, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_4 and not div_bull_5 and not div_bull_6
 and not div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_4], rsi[bl_4], bar_index[bl4], rsi[bl4], xloc = 
     xloc.bar_index, extend=extend.none, color=color.lime)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_4], rsi[bl_4], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=lime, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_5 and not div_bull_6 and not div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_5], rsi[bl_5], bar_index[bl5], rsi[bl5], xloc = 
     xloc.bar_index, extend=extend.none, color=color.lime)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_5], rsi[bl_5], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=lime, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_6 and not div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_6], rsi[bl_6], bar_index[bl6], rsi[bl6], xloc = 
     xloc.bar_index, extend=extend.none, color=color.lime)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_6], rsi[bl_6], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=lime, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_7 and not div_bull_8
    ln = line.new(bar_index[bl_7], rsi[bl_7], bar_index[bl7], rsi[bl7], xloc = 
     xloc.bar_index, extend=extend.none, color=color.aqua)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_7], rsi[bl_7], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=aqua, size=_size)
    label.delete(not pl ? lb : na)
if not arrows and show_div and div_bull_8
    ln = line.new(bar_index[bl_8], rsi[bl_8], bar_index[bl8], rsi[bl8], xloc = 
     xloc.bar_index, extend=extend.none, color=color.aqua)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not pl ? ln : na)
    lb = label.new(bar_index[bl_8], rsi[bl_8], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbl, color=aqua, size=_size)
    label.delete(not pl ? lb : na)
// Bearish Divergences = close HH - RSI LH
if not arrows and show_div and div_bear_1 and not div_bear_2 and not div_bear_3 
 and not div_bear_4 and not div_bear_5 and not div_bear_6 and not div_bear_7 and not div_bear_8
    ln = line.new(bar_index[br_1], rsi[br_1], bar_index[br1], rsi[br1], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na)
    lb = label.new(bar_index[br_1], rsi[br_1], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=orange, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_2 and not div_bear_3 and not div_bear_4 
 and not div_bear_5 and not div_bear_6 and not div_bear_7 and not div_bear_8 
    ln = line.new(bar_index[br_2], rsi[br_2], bar_index[br2], rsi[br2], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na)
    lb = label.new(bar_index[br_2], rsi[br_2], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=orange, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_3 and not div_bear_4 and not div_bear_5 
 and not div_bear_6 and not div_bear_7 and not div_bear_8 
    ln = line.new(bar_index[br_3], rsi[br_3], bar_index[br3], rsi[br3], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na)
    lb = label.new(bar_index[br_3], rsi[br_3], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=orange, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_4 and not div_bear_5 and not div_bear_6
 and not div_bear_7 and not div_bear_8
    ln = line.new(bar_index[br_4], rsi[br_4], bar_index[br4], rsi[br4], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na) 
    lb = label.new(bar_index[br_4], rsi[br_4], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=red, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_5 and not div_bear_6 and not div_bear_7 and not div_bear_8
    ln = line.new(bar_index[br_5], rsi[br_5], bar_index[br5], rsi[br5], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na) 
    lb = label.new(bar_index[br_5], rsi[br_5], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=red, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_6 and not div_bear_7 and not div_bear_8
    ln = line.new(bar_index[br_6], rsi[br_6], bar_index[br6], rsi[br6], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na) 
    lb = label.new(bar_index[br_6], rsi[br_6], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=red, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_7 and not div_bear_8
    ln = line.new(bar_index[br_7], rsi[br_7], bar_index[br7], rsi[br7], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na)   
    lb = label.new(bar_index[br_7], rsi[br_7], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=purple, size=_size)
    label.delete(not ph ? lb : na)
if not arrows and show_div and div_bear_8
    ln = line.new(bar_index[br_8], rsi[br_8], bar_index[br8], rsi[br8], xloc = 
     xloc.bar_index, extend=extend.none, color=color.red)
    line.set_width(ln, lw)
    line.set_style(ln, _dot)
    line.delete(not ph ? ln : na)   
    lb = label.new(bar_index[br_8], rsi[br_8], xloc = xloc.bar_index, yloc=yloc.price, 
     style=_symbr, color=purple, size=_size)
    label.delete(not ph ? lb : na)
//End

← 返回列表