Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. //@version=3
  2. //
  3. // Thanks to Dan Valcu, original who originally developed the indicator
  4. // And Kumowizard + LazyBear for writing Qstick script previously
  5. //
  6. // The indicator measures difference between Heikin Ashi close and open
  7. // thus quantifies Heikin Ashi candles, to get earlier signals
  8. // haDelta smoothed by applying 3 period MA
  9. // Choose between 11 different types of MA's thanks to JustUncleL and John F. Ehlers super smoother.
  10. //
  11. // For further interpretation and use please check Mr. Dan Valcu's work
  12. //
  13.  
  14. study(title="haDelta Divergence +")
  15. delta = close - open
  16.  
  17. MAType = input(defval="SSMA", title="MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
  18. SwapMADelta = input(true, "swap MA with Delta")
  19.  
  20. DivOffsetInput = input(title="------ Divergences Offset to Realistic Entry Point ------", type = bool, defval = true)
  21. DivOffset = DivOffsetInput? 0 : -2
  22.  
  23. showdivs1 = input(true, title = "Regular Divergences")
  24. showhidden1 = input(false, title = "Hidden Divergences")
  25. showlabels1 = input(false, title = "Divergence Labels")
  26.  
  27.  
  28. // - variant(type, src, len, gamma)
  29. // Returns MA input selection variant, default to SMA if blank or typo.
  30.  
  31. // SuperSmoother filter
  32. // © 2013 John F. Ehlers
  33. variant_supersmoother(src,len) =>
  34. a1 = exp(-1.414*3.14159 / len)
  35. b1 = 2*a1*cos(1.414*3.14159 / len)
  36. c2 = b1
  37. c3 = (-a1)*a1
  38. c1 = 1 - c2 - c3
  39. v9 = 0.0
  40. v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
  41. v9
  42.  
  43. variant_smoothed(src,len) =>
  44. v5 = 0.0
  45. v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
  46. v5
  47.  
  48. variant_zerolagema(src,len) =>
  49. xLag = (len - 1) / 2
  50. xEMA = (src + (src - src[xLag]))
  51. v10 = ema(xEMA, len)
  52. v10
  53.  
  54. variant_doubleema(src,len) =>
  55. v2 = ema(src, len)
  56. v6 = 2 * v2 - ema(v2, len)
  57. v6
  58.  
  59. variant_tripleema(src,len) =>
  60. v2 = ema(src, len)
  61. v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
  62. v7
  63.  
  64.  
  65. // return variant, defaults to SMA
  66. variant(type, src, len) =>
  67. result = src
  68. if len>1
  69. result := type=="EMA" ? ema(src,len) :
  70. type=="WMA" ? wma(src,len):
  71. type=="VWMA" ? vwma(src,len) :
  72. type=="SMMA" ? variant_smoothed(src,len) :
  73. type=="DEMA" ? variant_doubleema(src,len):
  74. type=="TEMA" ? variant_tripleema(src,len):
  75. type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
  76. type=="SSMA" ? variant_supersmoother(src,len) :
  77. type=="ZEMA" ? variant_zerolagema(src,len) :
  78. type=="TMA" ? sma(sma(src,len),len) :
  79. sma(src,len)
  80. //end if
  81. result
  82.  
  83.  
  84. s2 = variant(MAType, delta, 3)
  85.  
  86. A = SwapMADelta? s2 : delta
  87. B = SwapMADelta? delta : s2
  88.  
  89. plot(A, color=black)
  90. plot(B, color = red)
  91. plot(B, color=color(blue,70), style=area)
  92. c_color=B < 0 ? (B < B[1] ? red : lime) : (B >= 0 ? (B > B[1] ? lime : red) : na)
  93. plot(B, color=c_color, style=circles, linewidth=3)
  94. h0 = hline(0)
  95.  
  96.  
  97.  
  98.  
  99. Dinput1=B
  100.  
  101. //------------------------------
  102. //@RicardoSantos' Divergence Script
  103.  
  104. f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
  105. f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
  106. f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0
  107. //-------------------------
  108.  
  109. // 1st set of Divergences
  110.  
  111. fractal_top1 = f_fractalize(Dinput1) > 0 ? Dinput1[2] : na
  112. fractal_bot1 = f_fractalize(Dinput1) < 0 ? Dinput1[2] : na
  113.  
  114. high_prev1 = valuewhen(fractal_top1, Dinput1[2], 0)[2]
  115. high_price1 = valuewhen(fractal_top1, high[2], 0)[2]
  116. low_prev1 = valuewhen(fractal_bot1, Dinput1[2], 0)[2]
  117. low_price1 = valuewhen(fractal_bot1, low[2], 0)[2]
  118.  
  119.  
  120. regular_bearish_div1 = fractal_top1 and high[2] > high_price1 and Dinput1[2] < high_prev1
  121. hidden_bearish_div1 = fractal_top1 and high[2] < high_price1 and Dinput1[2] > high_prev1
  122. regular_bullish_div1 = fractal_bot1 and low[2] < low_price1 and Dinput1[2] > low_prev1
  123. hidden_bullish_div1 = fractal_bot1 and low[2] > low_price1 and Dinput1[2] < low_prev1
  124. //-------------------------
  125.  
  126. col1 = showdivs1 and regular_bearish_div1 ? red : hidden_bearish_div1 and showhidden1 ? maroon : na
  127. col2 = showdivs1 and regular_bullish_div1 ? #00FF00EB : hidden_bullish_div1 and showhidden1 ? green : na
  128. //col3 = regular_bearish_div1 ? red : hidden_bearish_div1 and showhidden1 ? red : na
  129. //col4 = regular_bullish_div1 ? green : hidden_bullish_div1 and showhidden1 ? green : na
  130.  
  131. plot(title='Bearish Divergences', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1[2] : na, color=col1, linewidth=3, offset=DivOffset)
  132. plot(title='Bullish Divergences', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1[2] : na, color=col2, linewidth=3, offset=DivOffset)
  133.  
  134. // plot(title='1 Bearish Divergences', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1[2] : na, color=col1, linewidth=3, offset=DivOffset)
  135. // plot(title='1 Bullish Divergences', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1[2] : na, color=col2, linewidth=3, offset=DivOffset)
  136.  
  137. //plot(title='1 H D', series=(showdivs1 or showhidden1) and fractal_top1 ? Dinput1[2] : na, style=circles, color=col3, linewidth=3, offset=DivOffset)
  138. //plot(title='1 L D', series=(showdivs1 or showhidden1) and fractal_bot1 ? Dinput1[2] : na, style=circles, color=col4, linewidth=3, offset=DivOffset)
  139.  
  140. 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)
  141. 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)
  142. 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)
  143. 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