Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //
- // Thanks to Dan Valcu, original who originally developed the indicator
- // And Kumowizard + LazyBear for writing Qstick script previously
- //
- // The indicator measures difference between Heikin Ashi close and open
- // thus quantifies Heikin Ashi candles, to get earlier signals
- // haDelta smoothed by applying 3 period MA
- // Choose between 11 different types of MA's thanks to JustUncleL and John F. Ehlers super smoother.
- //
- // For further interpretation and use please check Mr. Dan Valcu's work
- //
- study(title="haDelta Divergence +")
- delta = close - open
- MAType = input(defval="SSMA", title="MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
- SwapMADelta = input(true, "swap MA with Delta")
- DivOffsetInput = input(title="------ Divergences Offset to Realistic Entry Point ------", type = bool, defval = true)
- DivOffset = DivOffsetInput? 0 : -2
- showdivs1 = input(true, title = "Regular Divergences")
- showhidden1 = input(false, title = "Hidden Divergences")
- showlabels1 = input(false, title = "Divergence Labels")
- // - variant(type, src, len, gamma)
- // Returns MA input selection variant, default to SMA if blank or typo.
- // SuperSmoother filter
- // © 2013 John F. Ehlers
- variant_supersmoother(src,len) =>
- a1 = exp(-1.414*3.14159 / len)
- b1 = 2*a1*cos(1.414*3.14159 / len)
- c2 = b1
- c3 = (-a1)*a1
- c1 = 1 - c2 - c3
- v9 = 0.0
- v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
- v9
- variant_smoothed(src,len) =>
- v5 = 0.0
- v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
- v5
- variant_zerolagema(src,len) =>
- xLag = (len - 1) / 2
- xEMA = (src + (src - src[xLag]))
- v10 = ema(xEMA, len)
- v10
- variant_doubleema(src,len) =>
- v2 = ema(src, len)
- v6 = 2 * v2 - ema(v2, len)
- v6
- variant_tripleema(src,len) =>
- v2 = ema(src, len)
- v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
- v7
- // return variant, defaults to SMA
- variant(type, src, len) =>
- result = src
- if len>1
- result := type=="EMA" ? ema(src,len) :
- type=="WMA" ? wma(src,len):
- type=="VWMA" ? vwma(src,len) :
- type=="SMMA" ? variant_smoothed(src,len) :
- type=="DEMA" ? variant_doubleema(src,len):
- type=="TEMA" ? variant_tripleema(src,len):
- type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
- type=="SSMA" ? variant_supersmoother(src,len) :
- type=="ZEMA" ? variant_zerolagema(src,len) :
- type=="TMA" ? sma(sma(src,len),len) :
- sma(src,len)
- //end if
- result
- s2 = variant(MAType, delta, 3)
- A = SwapMADelta? s2 : delta
- B = SwapMADelta? delta : s2
- plot(A, color=black)
- plot(B, color = red)
- plot(B, color=color(blue,70), style=area)
- c_color=B < 0 ? (B < B[1] ? red : lime) : (B >= 0 ? (B > B[1] ? lime : red) : na)
- plot(B, color=c_color, style=circles, linewidth=3)
- h0 = hline(0)
- Dinput1=B
- //------------------------------
- //@RicardoSantos' Divergence Script
- 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
- //-------------------------
- // 1st set of Divergences
- fractal_top1 = f_fractalize(Dinput1) > 0 ? Dinput1[2] : na
- fractal_bot1 = f_fractalize(Dinput1) < 0 ? Dinput1[2] : na
- 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
- //-------------------------
- col1 = showdivs1 and regular_bearish_div1 ? red : hidden_bearish_div1 and showhidden1 ? maroon : na
- col2 = showdivs1 and regular_bullish_div1 ? #00FF00EB : hidden_bullish_div1 and showhidden1 ? green : na
- //col3 = regular_bearish_div1 ? red : hidden_bearish_div1 and showhidden1 ? red : na
- //col4 = regular_bullish_div1 ? green : hidden_bullish_div1 and showhidden1 ? green : na
- plot(title='Bearish Divergences', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1[2] : na, color=col1, linewidth=3, offset=DivOffset)
- plot(title='Bullish Divergences', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1[2] : na, color=col2, linewidth=3, offset=DivOffset)
- // plot(title='1 Bearish Divergences', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1[2] : na, color=col1, linewidth=3, offset=DivOffset)
- // plot(title='1 Bullish Divergences', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1[2] : na, color=col2, linewidth=3, offset=DivOffset)
- //plot(title='1 H D', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1[2] : na, style=circles, color=col3, linewidth=3, offset=DivOffset)
- //plot(title='1 L D', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1[2] : na, style=circles, color=col4, linewidth=3, offset=DivOffset)
- plotshape(title='Regular Bearish Divergence', series=showdivs1 and regular_bearish_div1 and showlabels1 ? Dinput1[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=na, textcolor=#FF0000FA, offset=DivOffset)
- plotshape(title='Hidden Bearish Divergence' , series=hidden_bearish_div1 and showhidden1 and showlabels1 ? Dinput1[2] : na, text='H', style=shape.labeldown, location=location.absolute, color=na, textcolor=#800000FA, offset=DivOffset)
- plotshape(title='Regular Bullish Divergence', series=showdivs1 and regular_bullish_div1 and showlabels1 ? Dinput1[2] : na, text='R', style=shape.labelup, location=location.absolute, color=na, textcolor=#00FF00FA, offset=DivOffset)
- plotshape(title='Hidden Bullish Divergence' , series=hidden_bullish_div1 and showhidden1 and showlabels1 ? Dinput1[2] : na, text='H', style=shape.labelup, location=location.absolute, color=na, textcolor=#008000FA, offset=DivOffset)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement