本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
//Created by elijah071
//This is the Ultimate RSI Diveregence Indicator,
//Not only does it plot Regular and Hidden Divergence lines for an RSI smoothed by an EMA and for its Signal Line
//The RSI can be set to change color with direction or can be set as single color with or with out OB / OS highlights
//Color Changing RSI helps when trading Multiple Timeframes as you can look for confluence in the direction of RSI
//
//Included options for the Signal Line include;
// Various calculations EMA, SMA and Linear Regression which provides very accurate signal line crossover signals
// Color Changing with direction
// Second RSI with different Length
// Multi Time Frame RSI
// Bollinger Bands applied to the RSI
// RSI Stochastic that has been compressed to fit into RSI OB / OS so that it doesnt compress the RSI when in these regions
// There are also Background Highlights for when the RSI Stochastic moves into OB / OS and crosses its signal line
//
//There are plenty of Alerts for signals with more complex alerts coming soon
//I have also added Hima Reddy's Power Zones for support and resistance so now you can also
//Take full advantage of trading; signal line crosses, 50 crosses and Power Zone RSI support and resistance and much more
//The divergence script is thanks to @RicardoSantos, I've just adjusted it to suite my indicator
//Remember that divergences work best when traded with the trend or very late in a trend when going against the trend
study("RSI Divergence Ultimate", shorttitle="RSI Divergence Ultimate")
// Menus
RSI1Length = input(13, title="RSI")
Smoothing = input(2, title=" RSI Smooothing")
RSIColorTypeMenu = input(title='RSI Color', defval='Directional Color Changing', options=['Directional Color Changing', 'Single Color','Single Color With OB / OS Colored Highlights' ], type=string)
ClrChRSI = RSIColorTypeMenu == 'Directional Color Changing' ? true : RSIColorTypeMenu == 'Single Color' ? false : false
RSIHLTs = RSIColorTypeMenu == 'Single Color With OB / OS Colored Highlights' ? true : false
SigalLine1Menu = input(title='Signal Line 1', defval='Linear Regression SMA', options=['EMA', 'SMA', 'Linear Regression SMA', 'Linear Regression EMA', 'N/A'], type=string)
ShowSig = SigalLine1Menu == 'N/A' ? false : true
SigMA = SigalLine1Menu == 'Linear Regression EMA' ? true : false
SignalLineLength1= input(21, title="Signal Line 1 - Length")
ShowSigCross1 = input(true, title='Show Signal Line 1 Crossover Dots')
SigalLine2Menu = input(title='Signal Line 2', defval='EMA', options=['Bollinger Bands', 'EMA', 'SMA', 'RSI Stochastic - Compressed', 'RSI - Standard', 'RSI 2 Period - Compressed', 'RSI 15 min Timeframe', 'RSI 1H Timeframe', 'RSI 4H Timeframe', 'RSI D Timeframe', 'RSI W Timeframe', 'Linear Regression SMA', 'Linear Regression EMA', 'N/A'], type=string)
SignalLineLength2= input(21, title="Signal Line 2 - Length For MA's, Linear Regression's and RSI - Standard Only ")
ShowSigCross2 = input(false, title='Show Signal Line 2 Crossover Dots')
ShowSig2 = SigalLine2Menu == 'N/A'? false : true
SigMA2 = SigalLine2Menu == 'Linear Regression EMA' ? true : false
showdivs1 = input(true, title="RSI Regular Divergences")
showhidden1 = input(false, title="RSI Hidden Divergences")
showlabels1 = input(false, title="RSI Divergence Labels")
showdivs2 = input(true, title="SL1 Regular Divergences")
showhidden2 = input(false, title="SL1 Hidden Divergences")
showlabels2 = input(false, title="SL1 Divergence Labels")
lengthStoch = input(14, minval=1, title='RSI Stochastic Length')
smoothK = input(3, minval=1, title='K')
smoothD = input(3, minval=1, title='D')
BGH = input(true, title="Highlight When RSI Stoch is OB/OS")
CHOBOS = input(false, title="Highlight When RSI Stoch Cross in OB/OS Regions")
CHnOBOS = input(false, title="Highlight When RSI Stoch Cross outside of OB/OS Regions")
StochOB = input(80, minval=50, maxval=90, title="RSI Stoch Overbought")
StochOS = input(20, minval=10, maxval=50, title="RSI Stoch Oversold")
vob = input(70, title="RSI Very Overbought")
ob = input(65, title="RSI Overbought")
os = input(35, title="RSI Oversold")
vos = input(30, title="RSI Very Oversold")
DivVertOffsetRSI= input(2, minval=0, maxval=10, title="Vertical Offset For Divergence Lines - RSI")
DivVertOffsetSL = input(10, minval=0, maxval=20, title="Vertical Offset For Divergence Lines - Signal Line 1")
// RSI1 Calculations
RSI1 = rsi(close, RSI1Length)
SmoothedRSI1 = ema(RSI1,Smoothing)
// Linear Regression Calculation For Signal Line 1
x = n
y = RSI1
x_ = if SigMA
ema(x,SignalLineLength1)
else
sma(x,SignalLineLength1)
y_ = if SigMA
ema(y,SignalLineLength1)
else
sma(y,SignalLineLength1)
mx = stdev(x,SignalLineLength1)
my = stdev(y,SignalLineLength1)
c = correlation(x,y,SignalLineLength1)
slope = c * (my/mx)
inter = y_ - slope*x_
LinReg1 = x*slope + inter
// Linear Regression Calculation For Signal Line 2
x2 = n
y2 = RSI1
x_2 = if SigMA2
ema(x2,SignalLineLength2)
else
sma(x2,SignalLineLength2)
y_2 = if SigMA2
ema(y2,SignalLineLength2)
else
sma(y2,SignalLineLength2)
mx2 = stdev(x2,SignalLineLength2)
my2 = stdev(y2,SignalLineLength2)
c2 = correlation(x2,y2,SignalLineLength2)
slope2 = c2 * (my2/mx2)
inter2 = y_2 - slope2*x_2
LinReg2 = x2*slope2 + inter2
////////////// Calculate Colours/////////////////////////
// RSI1 Color Calculations
RSI1Color = SmoothedRSI1 >= SmoothedRSI1[1] ? #00FF00FA : SmoothedRSI1 < SmoothedRSI1[1] ? #FF0000FA : na // Color Changing with Direction
RSI1MainColor = color(blue,40) // Single Color
rsiclrs = ClrChRSI? RSI1Color:RSI1MainColor
color4 = (SmoothedRSI1 > vob) ? #ff4500fa : (SmoothedRSI1 > ob and SmoothedRSI1 < vob) ? orange : RSI1MainColor // Single color with highlights
color5 = (SmoothedRSI1 < vos) ? lime : (SmoothedRSI1 > vos and SmoothedRSI1 < os) ? #32cd32fa : RSI1MainColor // Single color with highlights
color8 = SmoothedRSI1 >50 ? color4 : color5
color7 = RSIHLTs ? color8 : RSI1MainColor
RSIColor = ClrChRSI ? rsiclrs : color7
// Multi Time Frame RSI Calculation
RSIMultiTimeFrame1 = security(tickerid,"15", expression=rsi(close,RSI1Length))
RSIMultiTimeFrame2 = security(tickerid,"60", expression=rsi(close,RSI1Length))
RSIMultiTimeFrame3 = security(tickerid,"240",expression=rsi(close,RSI1Length))
RSIMultiTimeFrame4 = security(tickerid,"D", expression=rsi(close,RSI1Length))
RSIMultiTimeFrame5 = security(tickerid,"W", expression=rsi(close,RSI1Length))
// Signal Line 1 Calculations
SignalLine1 = SigalLine1Menu == 'EMA' ? ema(RSI1,SignalLineLength1) : SigalLine1Menu == 'SMA' ? sma(RSI1,SignalLineLength1) : SigalLine1Menu == 'Linear Regression SMA' ? LinReg1 : SigalLine1Menu == 'Linear Regression EMA' ? LinReg1 : na
//Signal Line 1 Color Calculation
SignalLine1Color = SignalLine1 >= SignalLine1[1] ? #FF00FFFA : SignalLine1 < SignalLine1[1] ? #800080FA : na
//Signal Line 2 Color Calculations
// RSI Short Term 2 Period
rsi2period = rsi(close, 2)
RSISTcolor1 = (rsi2period > 95) ? #ff0000e1 : (rsi2period >90 and rsi2period < 95) ? #ff7f00e1 : #80008082
RSISTcolor2 = (rsi2period < 5) ? #00ff00e1 : (rsi2period > 5 and rsi2period < 10) ? #008000e1 : #80008082
RSI2ShortTermColor = rsi2period >50 ? RSISTcolor1 : RSISTcolor2
RSIShortTerm2PeriodCompressed = rsi2period * 0.7 + 20
// Signal Line 2 Calculations
SignalLine2 = SigalLine2Menu == 'EMA' ? ema(RSI1,SignalLineLength2) : SigalLine2Menu == 'SMA' ? sma(RSI1,SignalLineLength2) : SigalLine2Menu == 'Linear Regression SMA' ? LinReg2 : SigalLine2Menu == 'Linear Regression EMA' ? LinReg2 : SigalLine2Menu == 'RSI - Standard' ? rsi(close,SignalLineLength2) : SigalLine2Menu == 'RSI 2 Period - Compressed' ? RSIShortTerm2PeriodCompressed : SigalLine2Menu == 'RSI 15 min Timeframe' ? RSIMultiTimeFrame1 : SigalLine2Menu == 'RSI 1H Timeframe' ? RSIMultiTimeFrame2 : SigalLine2Menu == 'RSI 4H Timeframe' ? RSIMultiTimeFrame3 : SigalLine2Menu == 'RSI D Timeframe' ? RSIMultiTimeFrame4 : SigalLine2Menu == 'RSI W Timeframe'? RSIMultiTimeFrame5 : na
//Signal Line 2 Color Calculation
SignalLine2Color1 = SignalLine2 >= SignalLine2[1] ? blue : SignalLine2 < SignalLine2[1] ? navy : na
SignalLine2Color2 = SignalLine2 >= SignalLine2[1] ? #0000ffaf : SignalLine2 < SignalLine2[1] ? #000080b9 : na
SignalLine2Color = SigalLine2Menu == 'RSI 2 Period - Compressed' ? RSI2ShortTermColor : SigalLine2Menu == 'RSI 15 min Timeframe' ? SignalLine2Color2 : SigalLine2Menu == 'RSI 1H Timeframe' ? SignalLine2Color2 : SigalLine2Menu == 'RSI 4H Timeframe' ? SignalLine2Color2 : SigalLine2Menu == 'RSI D Timeframe' ? SignalLine2Color2 : SigalLine2Menu == 'RSI - Standard' ? SignalLine2Color2 : SigalLine2Menu == 'RSI W Timeframe'? SignalLine2Color2 : SignalLine2Color1
///////////////////////////////////////////////////////////
// Plot Smoothed RSI1
plot(SmoothedRSI1, color=RSIColor, linewidth=3, title='RSI')
// Plot Signal Lines
plot(title='Signal Line 1', series=ShowSig? SignalLine1:na, color=SignalLine1Color,linewidth=2)
plot(title='Signal Line 2', series=ShowSig2? SignalLine2:na, color=SignalLine2Color,transp=0, linewidth=1)
// Bollinger Bands Calculations and Plots
BollingerBasis = sma(RSI1, 20)
BollingerEMA = ema(RSI1, SignalLineLength2)
BollingerDeviation = 2 * stdev(RSI1, 20)
BollingerUpper = BollingerBasis + BollingerDeviation
BollingLower = BollingerBasis - BollingerDeviation
plot(SigalLine2Menu == 'Bollinger Bands' ? BollingerEMA : na, title='BB Basis', color=#000080d2, linewidth=1)
plot(SigalLine2Menu == 'Bollinger Bands' ? BollingerUpper : na, title='BB Upper', color=red, transp=50, linewidth=2)
plot(SigalLine2Menu == 'Bollinger Bands' ? BollingLower : na, title='BB Lower', color=green, transp=50, linewidth=2)
// Plot Signal Line 1 Cross Over Dots
plot(title='Cross Over Dots 1 Black Outline', series=ShowSigCross1 and cross(SmoothedRSI1, SignalLine1) ? SmoothedRSI1 : na, color = black , style = circles, linewidth = 3)
plot(title='Cross Over Dots 1 Colored Inside', series=ShowSigCross1 and cross(SmoothedRSI1, SignalLine1) ? SmoothedRSI1 : na, color = (SmoothedRSI1 - SignalLine1 < 0 ? #ff4500fa : #00ff00fa), style = circles, linewidth = 2)
// Plot Signal Line 2 Cross Over Dots
plot(title='Cross Over Dots 2 Black Outline', series=ShowSigCross2 and cross(SmoothedRSI1, SignalLine2) ? SmoothedRSI1 : na, color = black , style = circles, linewidth = 3)
plot(title='Cross Over Dots 2 Colored Inside', series=ShowSigCross2 and cross(SmoothedRSI1, SignalLine2) ? SmoothedRSI1 : na, color = (SmoothedRSI1 - SignalLine1 < 0 ? #ff4500fa : #00ff00fa), style = circles, linewidth = 2)
// RSI Stochastic Calculations and Plots
K = sma(stoch(RSI1, RSI1, RSI1, lengthStoch), smoothK)
D = sma(K, smoothD)
kcompressed = K * 0.7 + 20
dcompressed = D * 0.7 + 20
plot(series=SigalLine2Menu == 'RSI Stochastic - Compressed'? kcompressed:na, color=orange, transp=50, linewidth=1, title="K")
plot(series=SigalLine2Menu == 'RSI Stochastic - Compressed'? dcompressed:na, color=blue, transp=60, linewidth=1, title="D")
// RSI Stochastic Background Highlights thanks to Chris Moody
// Calculations for OB and OS
OB = K > StochOB ? 1 : 0
OS = K < StochOS ? 1 : 0
// Calculations for Crosses in OB/OS Regions
CrossUp = (K[1] < D[1] and K[1] < StochOS[1]) and (K > D) ? 1 : 0
CrossDown = (K[1] > D[1] and K[1] > StochOB[1]) and (K < D) ? 1 : 0
// Calculations for Crosses not in OB/OS Regions
CrossUpOther = (K[1] < D[1] and K[1] > StochOS[1]) and (K[1] < StochOB[1]) and (K > D) ? 1 : 0
CrossDownOther = (K[1] > D[1] and K[1] < StochOB[1]) and (K[1] > StochOS[1]) and (K < D) ? 1 : 0
// BackGround - OB/OS
bgcolor( BGH and OB ? red : na, transp=97, title = 'Background Highlite For RSI Stochastic OB')
bgcolor( BGH and OS ? lime : na, transp=96, title = 'Background Highlite For RSI Stochastic OS')
// BackGround - OB/OS Crosses
bgcolor(CHOBOS and CrossUp ? lime : na, transp=94, title = 'Background Highlite For RSI Stochastic Cross Up when OS')
bgcolor(CHOBOS and CrossDown ? red : na, transp=96, title = 'Background Highlite For RSI Stochastic Cross Down when OB')
// BackGround - Crosses not in OB/OS Regions
bgcolor(CHnOBOS and CrossUpOther ? olive : na, transp=95, title = 'Background Highlite For RSI Stochastic Cross Up when not OS')
bgcolor(CHnOBOS and CrossDownOther ? orange : na, transp=94, title = 'Background Highlite For RSI Stochastic Cross Down when not OB')
//color=#0080008C green
//color=#FF00008C red
h1 = hline(90, color=#00800096, linestyle=solid)
h2 = hline(85, color=#00800096, linestyle=solid)
h3 = hline(80, color=#00800096, linestyle=solid)
h4 = hline(75, color=#80808096, linestyle=solid)
h5 = hline(70, color=#80808096, linestyle=solid)
h6 = hline(65, color=#FF0000fa, linestyle=solid)
h7 = hline(60, color=#FF000096, linestyle=solid)
h8 = hline(55, color=#FF000096, linestyle=solid)
h9 = hline(50, color=lime, linestyle=solid, linewidth=3)
h10 = hline(45, color=#00800096, linestyle=solid)
h11 = hline(40, color=#008000fa, linestyle=solid)
h12 = hline(35, color=#80808096, linestyle=solid)
h13 = hline(30, color=#FF000096, linestyle=solid)
h14 = hline(25, color=#FF000096, linestyle=solid)
h15 = hline(20, color=#FF000096, linestyle=solid)
//color=#0080008C green
//color=#FF00008C red
//fill(h5, h11, color=purple, transp=97)
fill(h1,h3, color=green, transp=96)
fill(h6,h8, color=red, transp=96)
fill(h9,h11, color=green, transp=96)
fill(h13,h15, color=red, transp=96)
// ------------------------------------------------------
// Inputs For Diveregences
Dinput1 =SmoothedRSI1
Dinput1vertoffsetplus =SmoothedRSI1 + DivVertOffsetRSI
Dinput1vertoffsetminus =SmoothedRSI1 - DivVertOffsetRSI
Dinput2 =SignalLine1
Dinput2vertoffsetplus =SignalLine1 + DivVertOffsetSL
Dinput2vertoffsetminus =SignalLine1 - DivVertOffsetSL
//////////////@RicardoSantos' Divergence Script///////////
// Calculations
f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0
//-------------------------
fractal_top1 = f_fractalize(Dinput1) > 0 ? Dinput1[2] : na
fractal_bot1 = f_fractalize(Dinput1) < 0 ? Dinput1[2] : na
////////////// RSI Divergences /////////////////////////
high_prev1 = valuewhen(fractal_top1, Dinput1[2], 0)[2]
high_price1 = valuewhen(fractal_top1, high[2], 0)[2]
low_prev1 = valuewhen(fractal_bot1, Dinput1[2], 0)[2]
low_price1 = valuewhen(fractal_bot1, low[2], 0)[2]
regular_bearish_div1 = fractal_top1 and high[2] > high_price1 and Dinput1[2] < high_prev1
hidden_bearish_div1 = fractal_top1 and high[2] < high_price1 and Dinput1[2] > high_prev1
regular_bullish_div1 = fractal_bot1 and low[2] < low_price1 and Dinput1[2] > low_prev1
hidden_bullish_div1 = fractal_bot1 and low[2] > low_price1 and Dinput1[2] < low_prev1
// RSI Divergence Lines
col1 = showdivs1 and regular_bearish_div1 ? red : hidden_bearish_div1 and showhidden1 ? maroon : na
col2 = showdivs1 and regular_bullish_div1 ? lime : hidden_bullish_div1 and showhidden1 ? green : na
plot(title='Bearish Divergences', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1vertoffsetplus[2] : na, color=col1, linewidth=3, offset=-2)
plot(title='Bullish Divergences', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1vertoffsetminus[2] : na, color=col2, linewidth=3, offset=-2)
// Black Inside For RSI Divergences
col11 = showdivs1 and regular_bearish_div1 ? #000000BE : hidden_bearish_div1 and showhidden1 ? #0000008C : na
col21 = showdivs1 and regular_bullish_div1 ? #0000008C : hidden_bullish_div1 and showhidden1 ? #0000008C : na
plot(title='Divergence Black Inside', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1vertoffsetplus[2] : na, color=col11, linewidth=1, offset=-2)
plot(title='Divergence Black Inside', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1vertoffsetminus[2] : na, color=col21, linewidth=1, offset=-2)
// Divergence Labels For RSI
plotshape(title='Regular Bearish Divergence', series=showdivs1 and regular_bearish_div1 and showlabels1 ? Dinput1vertoffsetplus[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=#FF000010, textcolor=#FF0000FA, offset=-2)
plotshape(title='Hidden Bearish Divergence' , series=hidden_bearish_div1 and showhidden1 and showlabels1 ? Dinput1vertoffsetplus[2] : na, text='H', style=shape.labeldown, location=location.absolute, color=#80000010, textcolor=#800000FA, offset=-2)
plotshape(title='Regular Bullish Divergence', series=showdivs1 and regular_bullish_div1 and showlabels1 ? Dinput1vertoffsetminus[2] : na, text='R', style=shape.labelup, location=location.absolute, color=#00FF0010, textcolor=#00FF00FA, offset=-2)
plotshape(title='Hidden Bullish Divergence' , series=hidden_bullish_div1 and showhidden1 and showlabels1 ? Dinput1vertoffsetminus[2] : na, text='H', style=shape.labelup, location=location.absolute, color=#00800010, textcolor=#008000FA, offset=-2)
////////////// Signal Line Divergences ///////////////////
fractal_top2 = f_fractalize(Dinput2) > 0 ? Dinput2[2] : na
fractal_bot2 = f_fractalize(Dinput2) < 0 ? Dinput2[2] : na
high_prev2 = valuewhen(fractal_top2, Dinput2[2], 0)[2]
high_price2 = valuewhen(fractal_top2, high[2], 0)[2]
low_prev2 = valuewhen(fractal_bot2, Dinput2[2], 0)[2]
low_price2 = valuewhen(fractal_bot2, low[2], 0)[2]
regular_bearish_div2 = fractal_top2 and high[2] > high_price2 and Dinput2[2] < high_prev2
hidden_bearish_div2 = fractal_top2 and high[2] < high_price2 and Dinput2[2] > high_prev2
regular_bullish_div2 = fractal_bot2 and low[2] < low_price2 and Dinput2[2] > low_prev2
hidden_bullish_div2 = fractal_bot2 and low[2] > low_price2 and Dinput2[2] < low_prev2
// Signal Line 1 Divergence Lines
col3 = ShowSig and showdivs2 and regular_bearish_div2 ? red : ShowSig and hidden_bearish_div2 and showhidden2 ? maroon : na
col4 = ShowSig and showdivs2 and regular_bullish_div2 ? lime : ShowSig and hidden_bullish_div2 and showhidden2 ? green : na
plot(title='SL Bearish Divergences', series=(showdivs2 or showhidden2) and fractal_top2 ? Dinput2vertoffsetplus[2] : na, color=col3, linewidth=3, offset=-2)
plot(title='SL Bullish Divergences', series=(showdivs2 or showhidden2) and fractal_bot2 ? Dinput2vertoffsetminus[2] : na, color=col4, linewidth=3, offset=-2)
// Black Inside For Signal Line 1 Divergence Lines
col31 = ShowSig and showdivs2 and regular_bearish_div2 ? #000000BE : ShowSig and hidden_bearish_div2 and showhidden2 ? #0000008C : na
col41 = ShowSig and showdivs2 and regular_bullish_div2 ? #0000008C : ShowSig and hidden_bullish_div2 and showhidden2 ? #0000008C : na
plot(title='SL Divergence Black Inside', series=(showdivs2 or showhidden2) and fractal_top2 ? Dinput2vertoffsetplus[2] : na, color=col31, linewidth=1, offset=-2)
plot(title='SL Divergence Black Inside', series=(showdivs2 or showhidden2) and fractal_bot2 ? Dinput2vertoffsetminus[2] : na, color=col41, linewidth=1, offset=-2)
// Colored Border For Signal Line 1 Diverence Lines
col51 = ShowSig and showdivs2 and regular_bearish_div2 ? #800080 : ShowSig and hidden_bearish_div2 and showhidden2 ? #800080 : na
col61 = ShowSig and showdivs2 and regular_bullish_div2 ? #800080 : ShowSig and hidden_bullish_div2 and showhidden2 ? #800080 : na
plot(title='SL Divergence Border', series=(showdivs2 or showhidden2) and fractal_top2 ? Dinput2vertoffsetplus[2] : na, color=col51, transp=93, linewidth=20, offset=-2)
plot(title='SL Divergence Border', series=(showdivs2 or showhidden2) and fractal_bot2 ? Dinput2vertoffsetminus[2] : na, color=col61, transp=93, linewidth=20, offset=-2)
// Divergence Labels For Signal Line 1
plotshape(title='SL Regular Bearish Divergence', series=ShowSig and showdivs2 and regular_bearish_div2 and showlabels2 ? Dinput2vertoffsetplus[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=#FF000010, textcolor=#FF0000FA, offset=-2)
plotshape(title='SL Hidden Bearish Divergence' , series=ShowSig and hidden_bearish_div2 and showhidden2 and showlabels2 ? Dinput2vertoffsetplus[2] : na, text='H', style=shape.labeldown, location=location.absolute, color=#80000010, textcolor=#800000FA, offset=-2)
plotshape(title='SL Regular Bullish Divergence', series=ShowSig and showdivs2 and regular_bullish_div2 and showlabels2 ? Dinput2vertoffsetminus[2] : na, text='R', style=shape.labelup, location=location.absolute, color=#00FF0010, textcolor=#00FF00FA, offset=-2)
plotshape(title='SL Hidden Bullish Divergence' , series=ShowSig and hidden_bullish_div2 and showhidden2 and showlabels2 ? Dinput2vertoffsetminus[2] : na, text='H', style=shape.labelup, location=location.absolute, color=#00800010, textcolor=#008000FA, offset=-2)
// Alerts
// Signal Line Cross Alerts
SL1Long = crossover (SmoothedRSI1, SignalLine1)
SL1Short = crossunder(SmoothedRSI1, SignalLine1)
SL2Long = crossover (SmoothedRSI1, SignalLine2)
SL2Short = crossunder(SmoothedRSI1, SignalLine2)
alertcondition(SL1Long, title='Alert - a Long - RSI Cross Over Signal Line 1', message='Long - RSI Cross Over Signal Line 1')
alertcondition(SL1Short, title='Alert - a Short - RSI Cross Under Signal Line 1', message='Short - RSI Cross Under Signal Line 1')
alertcondition(SL1Long, title='Alert - Long - RSI Cross Over Signal Line 1', message='Long - RSI Cross Over Signal Line 1')
alertcondition(SL1Short, title='Alert - Short - RSI Cross Under Signal Line 1', message='Short - RSI Cross Under Signal Line 1')
alertcondition(SL2Long, title='Alert - Long - RSI Cross Over Signal Line 2', message='Long - RSI Cross Over Signal Line 2')
alertcondition(SL2Short, title='Alert - Short - RSI Cross Under Signal Line 2', message='Short - RSI Cross Under Signal Line 2')
// Divergence Alerts
// RSI Divergence Alerts
alertcondition(regular_bearish_div1, title='Alert - RSI - Regular Bearish Divergence', message='RSI - Regular Bearish Divergence')
alertcondition(hidden_bearish_div1, title='Alert - RSI - Hidden Bearish Divergence', message='RSI - Hidden Bearish Divergence')
alertcondition(regular_bullish_div1, title='Alert - RSI - Regular Bullish Divergence', message='RSI - Regular Bullish Divergence')
alertcondition(hidden_bullish_div1, title='Alert - RSI - Hidden Bullish Divergence', message='RSI - Hidden Bullish Divergence')
// Signal Line 1 Divergence Alerts
alertcondition(regular_bearish_div2, title='Alert - Signal Line 1 - Regular Bearish Divergence', message='Signal Line 1 - Regular Bearish Divergence')
alertcondition(hidden_bearish_div2, title='Alert - Signal Line 1 - Hidden Bearish Divergence', message='Signal Line 1 - Hidden Bearish Divergence')
alertcondition(regular_bullish_div2, title='Alert - Signal Line 1 - Regular Bullish Divergence', message='Signal Line 1 - Regular Bullish Divergence')
alertcondition(hidden_bullish_div2, title='Alert - Signal Line 1 - Hidden Bullish Divergence', message='Signal Line 1 - Hidden Bullish Divergence')