xmd79

Divina - Support and Resistance

Jan 13th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. // © cAosX
  2. //@version=5
  3.  
  4. var int MAX_BOXES = 80
  5.  
  6. var string SENSITIVITY_TOOLTIP = "MIN = 0.01 / MAX = 1.0\nDefines how strong a signal " +
  7. "must be for the DivinaBox to be displayed. It is highly recommended to use it on a " +
  8. "chart with reliable volume data."
  9.  
  10. var string LINE_STYLE_SOLID = "Solid"
  11. var string LINE_STYLE_DOTTED = "Dotted"
  12. var string LINE_STYLE_DASHED = "Dashed"
  13.  
  14. resolveLineStyle(style) =>
  15. switch style
  16. LINE_STYLE_SOLID => line.style_solid
  17. LINE_STYLE_DOTTED => line.style_dotted
  18. LINE_STYLE_DASHED => line.style_dashed
  19.  
  20. percentChange(source) =>
  21. ta.roc(source, 1) / 100
  22.  
  23. indicator(
  24. title = "Divina - Support and Resistance",
  25. shorttitle = "Divina",
  26. overlay = true,
  27. max_boxes_count = MAX_BOXES,
  28. max_lines_count = MAX_BOXES * 4)
  29.  
  30. sensitivityInput = input.float(
  31. defval = 0.1618,
  32. title = "Sensitivity",
  33. minval = 0.01,
  34. maxval = 1.0,
  35. step = 0.05,
  36. tooltip = SENSITIVITY_TOOLTIP)
  37.  
  38. sourceInput = input.source(
  39. defval = close,
  40. title = "Source")
  41.  
  42. boxBorderStyleInput = input.string(
  43. defval = LINE_STYLE_DASHED,
  44. title = "Border      ",
  45. options = [LINE_STYLE_SOLID, LINE_STYLE_DOTTED, LINE_STYLE_DASHED],
  46. inline = "box",
  47. group = "Divina Box")
  48.  
  49. boxBorderColorInput = input.color(
  50. defval = color.black,
  51. title = "",
  52. inline = "box",
  53. group = "Divina Box")
  54.  
  55. boxBackgroundColorInput = input.color(
  56. defval = color.new(color.black, 100),
  57. title = "Background",
  58. group = "Divina Box")
  59.  
  60. outerLinesEnabledInput = input.bool(
  61. defval = true,
  62. title = "1.618  ",
  63. inline = "outer_lines",
  64. group = "Divina Lines")
  65.  
  66. outerLinesStyleInput = input.string(
  67. defval = LINE_STYLE_DOTTED,
  68. title = "",
  69. options = [LINE_STYLE_SOLID, LINE_STYLE_DOTTED, LINE_STYLE_DASHED],
  70. inline ="outer_lines",
  71. group = "Divina Lines")
  72.  
  73. outerLinesColorInput = input.color(
  74. defval = color.gray,
  75. title = "",
  76. inline = "outer_lines",
  77. group = "Divina Lines")
  78.  
  79. innerLinesEnabledInput = input.bool(
  80. defval = true,
  81. title = "0.618  ",
  82. inline = "inner_lines",
  83. group = "Divina Lines")
  84.  
  85. innerLinesStyleInput = input.string(
  86. defval = LINE_STYLE_DOTTED,
  87. title = "",
  88. options = [LINE_STYLE_SOLID, LINE_STYLE_DOTTED, LINE_STYLE_DASHED],
  89. inline = "inner_lines",
  90. group = "Divina Lines")
  91.  
  92. innerLinesColorInput = input.color(
  93. defval = color.gray,
  94. title = "",
  95. inline = "inner_lines",
  96. group = "Divina Lines")
  97.  
  98. volumeChange = percentChange(volume)
  99. priceChange = percentChange(sourceInput)
  100. priceVolumeRatio = math.abs(priceChange / volumeChange)
  101. condition = priceVolumeRatio >= sensitivityInput
  102.  
  103. hi = condition ? high : na
  104. lo = condition ? low : na
  105. phiRange = math.rphi * (hi - lo)
  106.  
  107. var box[] divinaBoxList = array.new_box(1)
  108. var line[] divinaInnerTopList = array.new_line(1)
  109. var line[] divinaInnerBottomList = array.new_line(1)
  110. var line[] divinaOuterTopList = array.new_line(1)
  111. var line[] divinaOuterBottomList = array.new_line(1)
  112.  
  113. if barstate.isconfirmed and not na(hi) and not na(lo)
  114. array.push(divinaBoxList, box.new(
  115. left = bar_index,
  116. top = hi,
  117. right = bar_index + 1,
  118. bottom = lo,
  119. bgcolor = boxBackgroundColorInput,
  120. border_color = boxBorderColorInput,
  121. border_style = resolveLineStyle(boxBorderStyleInput)))
  122.  
  123. if array.size(divinaBoxList) > MAX_BOXES
  124. box.delete(array.shift(divinaBoxList))
  125.  
  126. if innerLinesEnabledInput
  127. array.push(divinaInnerTopList, line.new(
  128. x1 = bar_index,
  129. y1 = hi - phiRange,
  130. x2 = bar_index + 1,
  131. y2 = hi - phiRange,
  132. color = innerLinesColorInput,
  133. style = resolveLineStyle(innerLinesStyleInput)))
  134.  
  135. array.push(divinaInnerBottomList, line.new(
  136. x1 = bar_index,
  137. y1 = lo + phiRange,
  138. x2 = bar_index + 1,
  139. y2= lo + phiRange,
  140. color = innerLinesColorInput,
  141. style = resolveLineStyle(innerLinesStyleInput)))
  142.  
  143. if array.size(divinaInnerTopList) > MAX_BOXES
  144. line.delete(array.shift(divinaInnerTopList))
  145. line.delete(array.shift(divinaInnerBottomList))
  146.  
  147. if outerLinesEnabledInput
  148. array.push(divinaOuterTopList, line.new(
  149. x1 = bar_index,
  150. y1 = hi + phiRange,
  151. x2 = bar_index + 1,
  152. y2 = hi + phiRange,
  153. color = outerLinesColorInput,
  154. style = resolveLineStyle(outerLinesStyleInput)))
  155.  
  156. array.push(divinaOuterBottomList, line.new(
  157. x1 = bar_index,
  158. y1 = lo - phiRange,
  159. x2 = bar_index + 1,
  160. y2 = lo - phiRange,
  161. color = outerLinesColorInput,
  162. style = resolveLineStyle(outerLinesStyleInput)))
  163.  
  164. if array.size(divinaOuterTopList) > MAX_BOXES
  165. line.delete(array.shift(divinaOuterTopList))
  166. line.delete(array.shift(divinaOuterBottomList))
  167. int(na)
  168. else
  169. box.set_right(array.get(divinaBoxList, array.size(divinaBoxList) - 1), bar_index)
  170.  
  171. if innerLinesEnabledInput
  172. line.set_x2(array.get(divinaInnerTopList, array.size(divinaInnerTopList) - 1), bar_index)
  173. line.set_x2(array.get(divinaInnerBottomList, array.size(divinaInnerBottomList) - 1), bar_index)
  174.  
  175. if outerLinesEnabledInput
  176. line.set_x2(array.get(divinaOuterTopList, array.size(divinaOuterTopList) - 1), bar_index)
  177. line.set_x2(array.get(divinaOuterBottomList, array.size(divinaOuterBottomList) - 1), bar_index)
  178. int(na)
Advertisement
Add Comment
Please, Sign In to add comment