Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. study(title = "Pekipek's PPO Divergence BETA", shorttitle = "PP's_PPO_DIV")
  2. source = close
  3. long_term_div = input(true, title="Use long term Divergences?")
  4. div_lookback_period = input(55, minval=1, title="Lookback Period")
  5. fastLength = input(12, minval=1), slowLength=input(26,minval=1)
  6. signalLength=input(9,minval=1)
  7. smoother = input(2,minval=1)
  8. fastMA = ema(source, fastLength)
  9. slowMA = ema(source, slowLength)
  10. macd = fastMA - slowMA
  11. macd2=(macd/slowMA)*100
  12. d = sma(macd2, smoother) // smoothing PPO
  13.  
  14. bullishPrice = low
  15.  
  16. priceMins = bullishPrice > bullishPrice[1] and bullishPrice[1] < bullishPrice[2] or
  17. low[1] == low[2] and low[1] < low and low[1] < low[3] or
  18. low[1] == low[2] and low[1] == low[3] and low[1] < low and low[1] < low[4] or
  19. low[1] == low[2] and low[1] == low[3] and low[1] and low[1] == low[4] and low[1] < low and low[1] < low[5] // this line identifies bottoms and plateaus in the price
  20. oscMins= d > d[1] and d[1] < d[2] // this line identifies bottoms in the PPO
  21.  
  22.  
  23. BottomPointsInPPO = oscMins
  24.  
  25. bearishPrice = high
  26. priceMax = bearishPrice < bearishPrice[1] and bearishPrice[1] > bearishPrice[2] or
  27. high[1] == high[2] and high[1] > high and high[1] > high[3] or
  28. high[1] == high[2] and high[1] == high[3] and high[1] > high and high[1] > high[4] or
  29. high[1] == high[2] and high[1] == high[3] and high[1] and high[1] == high[4] and high[1] > high and high[1] > high[5] // this line identifies tops in the price
  30. oscMax = d < d[1] and d[1] > d[2] // this line identifies tops in the PPO
  31.  
  32. TopPointsInPPO = oscMax
  33.  
  34.  
  35.  
  36. currenttrough4=valuewhen (oscMins, d[1], 0) // identifies the value of PPO at the most recent BOTTOM in the PPO
  37. lasttrough4=valuewhen (oscMins, d[1], 1) // NOT USED identifies the value of PPO at the second most recent BOTTOM in the PPO
  38. currenttrough5=valuewhen (oscMax, d[1], 0) // identifies the value of PPO at the most recent TOP in the PPO
  39. lasttrough5=valuewhen (oscMax, d[1], 1) // NOT USED identifies the value of PPO at the second most recent TOP in the PPO
  40.  
  41. currenttrough6=valuewhen (priceMins, low[1], 0) // this line identifies the low (price) at the most recent bottom in the Price
  42. lasttrough6=valuewhen (priceMins, low[1], 1) // NOT USED this line identifies the low (price) at the second most recent bottom in the Price
  43. currenttrough7=valuewhen (priceMax, high[1], 0) // this line identifies the high (price) at the most recent top in the Price
  44. lasttrough7=valuewhen (priceMax, high[1], 1) // NOT USED this line identifies the high (price) at the second most recent top in the Price
  45.  
  46.  
  47. delayedlow = priceMins and barssince(oscMins) < 3 ? low[1] : na
  48. delayedhigh = priceMax and barssince(oscMax) < 3 ? high[1] : na
  49.  
  50. // only take tops/bottoms in price when tops/bottoms are less than 5 bars away
  51. filter = barssince(priceMins) < 5 ? lowest(currenttrough6, 4) : na
  52. filter2 = barssince(priceMax) < 5 ? highest(currenttrough7, 4) : na
  53.  
  54. //delayedbottom/top when oscillator bottom/top is earlier than price bottom/top
  55. y11 = valuewhen(oscMins, delayedlow, 0)
  56. y12 = valuewhen(oscMax, delayedhigh, 0)
  57.  
  58. // only take tops/bottoms in price when tops/bottoms are less than 5 bars away, since 2nd most recent top/bottom in osc
  59. y2=valuewhen(oscMax, filter2, 1) // identifies the highest high in the tops of price with 5 bar lookback period SINCE the SECOND most recent top in PPO
  60. y6=valuewhen(oscMins, filter, 1) // identifies the lowest low in the bottoms of price with 5 bar lookback period SINCE the SECOND most recent bottom in PPO
  61.  
  62. long_term_bull_filt = valuewhen(priceMins, lowest(div_lookback_period), 1)
  63. long_term_bear_filt = valuewhen(priceMax, highest(div_lookback_period), 1)
  64.  
  65. y3=valuewhen(oscMax, currenttrough5, 0) // identifies the value of PPO in the most recent top of PPO
  66. y4=valuewhen(oscMax, currenttrough5, 1) // identifies the value of PPO in the second most recent top of PPO
  67.  
  68.  
  69.  
  70.  
  71. y7=valuewhen(oscMins, currenttrough4, 0) // identifies the value of PPO in the most recent bottom of PPO
  72. y8=valuewhen(oscMins, currenttrough4, 1) // identifies the value of PPO in the SECOND most recent bottom of PPO
  73.  
  74. y9=valuewhen(oscMins, currenttrough6, 0)
  75. y10=valuewhen(oscMax, currenttrough7, 0)
  76.  
  77. bulldiv= BottomPointsInPPO ? d[1] : na // plots dots at bottoms in the PPO
  78. beardiv= TopPointsInPPO ? d[1]: na // plots dots at tops in the PPO
  79.  
  80.  
  81. i = currenttrough5 < highest(d, div_lookback_period) // long term bearish oscilator divergence
  82. i2 = y10 > long_term_bear_filt // long term bearish top divergence
  83. i3 = delayedhigh > long_term_bear_filt // long term bearish delayedhigh divergence
  84.  
  85. i4 = currenttrough4 > lowest(d, div_lookback_period) // long term bullish osc divergence
  86. i5 = y9 < long_term_bull_filt // long term bullish bottom div
  87. i6 = delayedlow < long_term_bull_filt // long term bullish delayedbottom div
  88.  
  89.  
  90.  
  91. plot(d, color=white)
  92. plot(bulldiv, title = "Tops", color=aqua, style=circles, linewidth=4, offset= -1)
  93. plot(beardiv, title = "Bottoms", color=red, style=circles, linewidth=4, offset= -1)
  94.  
  95.  
  96. plot(y10>y2 and oscMax and y3 < y4 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
  97. plot(y9<y6 and oscMins and y7 > y8 ? d :na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
  98. plot(delayedlow<y6 and y7 > y8 ? d :na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
  99. plot(delayedhigh>y2 and y3 < y4 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
  100.  
  101. plot(long_term_div and oscMax and i and i2 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
  102. plot(long_term_div and oscMins and i4 and i5 ? d : na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
  103. plot(long_term_div and i and i3 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
  104. plot(long_term_div and i4 and i6 ? d : na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement