xmd79

Divergence and Pivot - Detecter For Any Indicator

Nov 24th, 2022
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © HALDRO
  3.  
  4. //@version=5
  5. indicator('Divergence and Pivot - Detecter For Any Indicator', shorttitle = 'Detector')
  6. //------------------------------------------------------------------------------
  7. // Inputs
  8. groupdiv = 'Divergence Detect'
  9. grouppiv = 'Pivot Detect'
  10. groupvis = 'Visual'
  11. src = input (close,'                                   Oscillator Source')
  12. pivothl = input.bool(true, 'Pivot Show ?' , group = grouppiv, inline = ' ')
  13. pivR = input.int (1, 'Pivot Lookback - Left / Right     ', group = grouppiv, inline = '2')
  14. pivL = input.int (21, ' ' , group = grouppiv, inline = '2')
  15. lbR = input.int (1, 'Divergence Lookback - Left / Right', group = groupdiv, inline = '1')
  16. lbL = input.int (16, ' ' , group = groupdiv, inline = '1')
  17. rangeUpper = input.int (100, 'Lookback Range - MAX / MIN        ', group = groupdiv, inline = '0')
  18. rangeLower = input.int (6, ' ' , group = groupdiv, inline = '0')
  19.  
  20. plotBull = input.bool(true, 'Bullish' , group = groupdiv, inline = 'd')
  21. plotBear = input.bool(true, 'Bearish' , group = groupdiv, inline = 'd')
  22. plotHiddenBull = input.bool(true, 'Hidden Bullish' , group = groupdiv, inline = 'd')
  23. plotHiddenBear = input.bool(true, 'Hidden Bearish' , group = groupdiv, inline = 'd')
  24. plot(src == close ? na : src, 'Oscillator Source')
  25.  
  26. // Visual
  27. bullColor = input.color(#00ff6d,'Bull' , group = groupvis, inline = 'c')
  28. bearColor = input.color(#ff0056,'Bear' , group = groupvis, inline = 'c')
  29. char1 = input('•', 'Char Div', group = groupvis, inline = 'c')
  30. char2 = input('▪', 'Char Pivot', group = groupvis, inline = 'c')
  31.  
  32. // Pivot Detect
  33. PHCond = ta.pivothigh(src, pivL, pivR), h = +1.1
  34. PLCond = ta.pivotlow (src, pivL, pivR), l = -0.9
  35.  
  36. // Check Panel
  37. var table panel = table.new(position = position.middle_center, columns = 2, rows = 1, bgcolor = #363A45, border_width = 1)
  38. if barstate.islast
  39. table.cell(panel, 1, 0, text=src == close ? str.tostring('Choose a source!') : na, text_color = #ffa726, bgcolor = #363A45)
  40. if src != close
  41. table.delete(panel)
  42.  
  43. // Plot Pivot
  44. plotchar(pivothl and src != close ? PHCond * +h : na, title='Pivot High', char=char2, size=size.tiny, location=location.absolute, color=bearColor)
  45. plotchar(pivothl and src != close ? PLCond * -l : na, title='Pivot Low' , char=char2, size=size.tiny, location=location.absolute, color=bullColor)
  46.  
  47.  
  48. // Divergence Detect
  49. osc = src
  50. //------------------------------------------------------------------------------
  51. plFound = na(ta.pivotlow(src, lbL, lbR)) ? false : true
  52. phFound = na(ta.pivothigh(src, lbL, lbR)) ? false : true
  53. _inRange(cond) =>
  54. bars = ta.barssince(cond == true)
  55. rangeLower <= bars and bars <= rangeUpper
  56.  
  57. //------------------------------------------------------------------------------
  58. // Regular Bullish
  59. // Osc: Higher Low
  60. oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) and src != close
  61. // Price: Lower Low
  62. priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
  63. bullCond = plotBull and priceLL and oscHL and plFound
  64. plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=1, color=bullCond ? #089981 : na)
  65. plotchar(bullCond ? osc[lbR] : na, offset=-lbR, title='Regular Bullish Label', char=char1, size=size.tiny, location=location.absolute, color=bullColor)
  66.  
  67. //------------------------------------------------------------------------------
  68. // Hidden Bullish
  69. // Osc: Lower Low
  70. oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) and src != close
  71. // Price: Higher Low
  72. priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
  73. hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
  74. plot(plFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=1, color=hiddenBullCond ? #089981 : na)
  75. plotchar(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bullish Label', char=char1, size=size.tiny, location=location.absolute, color=bullColor)
  76.  
  77. //------------------------------------------------------------------------------
  78. // Regular Bearish
  79. // Osc: Lower High
  80. oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) and src != close
  81. // Price: Higher High
  82. priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
  83. bearCond = plotBear and priceHH and oscLH and phFound
  84. plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=1, color=bearCond ? #673ab7 : na)
  85. plotchar(bearCond ? osc[lbR] : na, offset=-lbR, title='Regular Bearish Label', char=char1, size=size.tiny, location=location.absolute, color=bearColor)
  86.  
  87. //------------------------------------------------------------------------------
  88. // Hidden Bearish
  89. // Osc: Higher High
  90. oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) and src != close
  91. // Price: Lower High
  92. priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
  93. hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
  94. plot(phFound ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=1, color=hiddenBearCond ? #673ab7 : na)
  95. plotchar(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title='Hidden Bearish Label', char=char1, size=size.tiny, location=location.absolute, color=bearColor)
  96. //------------------------------------------------------------------------------
  97.  
  98.  
Advertisement
Add Comment
Please, Sign In to add comment