xmd79

Ross Hook Pattern (Expo)

Nov 30th, 2022
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.08 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. // © Zeiierman
  3.  
  4. //@version=5
  5. indicator("Ross Hook Pattern (Expo)",overlay=true,max_bars_back=5000,max_labels_count=500,max_lines_count=500)
  6.  
  7. // ~~ ToolTips {
  8. t1 = "Set the Ross Hook Period - A high value returns long-term patterns, and a low value returns short-term patterns"
  9. t2 = "Set the minimum distance between point 2 and point 3. A high value indicates a bigger price correction before the price takes off again. A low value indicates a shorter price correction before the price takes off again."
  10. t3 = "Show pattern break, set the size, and coloring"
  11. t4 = "Show the Ross Hook"
  12. t5 = "Show the Ross Hook pattern"
  13. t6 = "Enable the HH/HL/LL/LH labels"
  14. // ~~}
  15. // ~~ Inputs {
  16. prd = input.int(20, minval=1,title="Set Period",tooltip=t1)
  17. dst = input.int(20,minval=0, title="Set Hook Distance",tooltip=t2)
  18.  
  19. showBreak = input.bool(true,"Show Break", inline="break")
  20. showHook = input.bool(true,"Show Hook",tooltip=t4)
  21. showPattern = input.bool(false,"Show Pattern",tooltip=t5)
  22. showPvts = input.bool(false,"Show Pivots",tooltip=t6)
  23.  
  24. visuell = input.string("Diamond","",options=["Diamond","XCross","Cross","Flag","Square"],inline="break")
  25. colBull = input.color(color.new(#31be0c,0),"",inline="break")
  26. colBear = input.color(color.new(#df3d3d,0),"",inline="break")
  27. size = input.string(size.tiny,"",options=[size.tiny,size.small,size.normal,size.large,size.huge],inline="break",tooltip=t3)
  28.  
  29. shape = switch visuell
  30. "Diamond" => label.style_diamond
  31. "XCross" => label.style_xcross
  32. "Cross" => label.style_cross
  33. "Flag" => label.style_flag
  34. "Square" => label.style_square
  35. // ~~ }
  36. // ~~ Arrays {
  37. var pvts = array.new<float>(5,0.0)
  38. var idx = array.new<int>(5,0)
  39. // ~~ }
  40. // ~~ Pivots {
  41. pvtHi = ta.pivothigh(high,prd,prd)
  42. pvtLo = ta.pivotlow(low,prd,prd)
  43. var pos = 0
  44. if not na(pvtHi) and pos<=0
  45. if showPvts
  46. label.new(bar_index-prd,high[prd],text=pvtHi>array.get(pvts,1)?"HH":"LH",style=label.style_label_down,color=color(na),textcolor=chart.fg_color)
  47. array.pop(pvts)
  48. array.pop(idx)
  49. array.unshift(pvts,high[prd])
  50. array.unshift(idx,bar_index-prd)
  51. pos := 1
  52. if not na(pvtLo) and pos>=0
  53. if showPvts
  54. label.new(bar_index-prd,low[prd],text=pvtLo>array.get(pvts,1)?"HL":"LL",style=label.style_label_up,color=color(na),textcolor=chart.fg_color)
  55. array.pop(pvts)
  56. array.pop(idx)
  57. array.unshift(pvts,low[prd])
  58. array.unshift(idx,bar_index-prd)
  59. pos := -1
  60. // ~~ }
  61. // ~~ Identify RossHook Pattern & Alerts {
  62. var Hook = true
  63. if ta.crossover(high,array.get(pvts,1)) and Hook
  64. if array.get(pvts,0)<array.get(pvts,1)
  65. if array.get(pvts,1)>array.get(pvts,3) and array.get(pvts,0)>array.get(pvts,2) and array.get(pvts,2)>array.get(pvts,4) and array.get(pvts,3)>array.get(pvts,2)
  66. first = bar_index-array.get(idx,4)
  67. sec = bar_index-array.get(idx,3)
  68. if bar_index-array.get(idx,1)>=prd
  69. for i=first to sec
  70. if close[i]>array.get(pvts,2) and array.get(idx,2)-bar_index[i]>=dst
  71. if showPattern
  72. line.new(bar_index-i,array.get(pvts,2),array.get(idx,2),array.get(pvts,2),color=chart.fg_color,style=line.style_dashed)
  73. mid = math.round(math.avg(bar_index-i,array.get(idx,2)))
  74. label.new(mid,array.get(pvts,2),text="First Hook",color=color(na),textcolor=chart.fg_color,style=label.style_label_up)
  75. Hook := true
  76. break
  77. else
  78. Hook := false
  79. if Hook
  80. if showBreak
  81. label.new(bar_index,high,style=shape,color=colBull,size=size)
  82. if showHook
  83. line.new(array.get(idx,3),array.get(pvts,3),bar_index,array.get(pvts,3),color=chart.fg_color,style=line.style_dashed)
  84. label.new(math.round(math.avg(bar_index,array.get(idx,3))),array.get(pvts,3),text="Ross Hook",color=color(na),textcolor=chart.fg_color,style=label.style_label_up)
  85. if showPattern
  86. line.new(array.get(idx,1),array.get(pvts,1),bar_index,array.get(pvts,1),color=chart.fg_color,style=line.style_dashed)
  87. label.new(math.round(math.avg(bar_index,array.get(idx,1))),array.get(pvts,1),text="Second Hook",color=color(na),textcolor=chart.fg_color,style=label.style_label_down)
  88. label.new(array.get(idx,4),array.get(pvts,4),text="1",color=color(na),textcolor=chart.fg_color,style=label.style_label_up)
  89. label.new(array.get(idx,3),array.get(pvts,3),text="2",color=color(na),textcolor=chart.fg_color,style=label.style_label_down)
  90. label.new(array.get(idx,2),array.get(pvts,2),text="3",color=color(na),textcolor=chart.fg_color,style=label.style_label_up)
  91. for i=array.size(pvts)-2 to 2
  92. line.new(array.get(idx,i),array.get(pvts,i),array.get(idx,i+1),array.get(pvts,i+1),color=chart.fg_color)
  93. alert("Bullish Ross Hook Pattern Identified on: "+syminfo.ticker,alert.freq_once_per_bar_close)
  94. Hook := false
  95. if ta.crossunder(low,array.get(pvts,1)) and Hook
  96. if array.get(pvts,0)>array.get(pvts,1)
  97. if array.get(pvts,1)<array.get(pvts,3) and array.get(pvts,0)<array.get(pvts,2) and array.get(pvts,2)<array.get(pvts,4) and array.get(pvts,3)<array.get(pvts,2)
  98. first = bar_index-array.get(idx,4)
  99. sec = bar_index-array.get(idx,3)
  100. if bar_index-array.get(idx,1)>=prd
  101. for i=first to sec
  102. if close[i]<array.get(pvts,2) and array.get(idx,2)-bar_index[i]>=dst
  103. if showPattern
  104. line.new(bar_index-i,array.get(pvts,2),array.get(idx,2),array.get(pvts,2),color=chart.fg_color,style=line.style_dashed)
  105. mid = math.round(math.avg(bar_index-i,array.get(idx,2)))
  106. label.new(mid,array.get(pvts,2),text="First Hook",color=color(na),textcolor=chart.fg_color,style=label.style_label_down)
  107. Hook := true
  108. break
  109. else
  110. Hook := false
  111. if Hook
  112. if showBreak
  113. label.new(bar_index,low,style=shape,color=colBear,size=size)
  114. if showHook
  115. line.new(array.get(idx,3),array.get(pvts,3),bar_index,array.get(pvts,3),color=chart.fg_color,style=line.style_dashed)
  116. label.new(math.round(math.avg(bar_index,array.get(idx,3))),array.get(pvts,3),text="Ross Hook",color=color(na),textcolor=chart.fg_color,style=label.style_label_down)
  117. if showPattern
  118. line.new(array.get(idx,1),array.get(pvts,1),bar_index,array.get(pvts,1),color=chart.fg_color,style=line.style_dashed)
  119. label.new(math.round(math.avg(bar_index,array.get(idx,1))),array.get(pvts,1),text="Second Hook",color=color(na),textcolor=chart.fg_color,style=label.style_label_up)
  120. label.new(array.get(idx,4),array.get(pvts,4),text="1",color=color(na),textcolor=chart.fg_color,style=label.style_label_down)
  121. label.new(array.get(idx,3),array.get(pvts,3),text="2",color=color(na),textcolor=chart.fg_color,style=label.style_label_up)
  122. label.new(array.get(idx,2),array.get(pvts,2),text="3",color=color(na),textcolor=chart.fg_color,style=label.style_label_down)
  123. for i=array.size(pvts)-2 to 2
  124. line.new(array.get(idx,i),array.get(pvts,i),array.get(idx,i+1),array.get(pvts,i+1),color=chart.fg_color)
  125. alert("Bearish Ross Hook Pattern Identified on: "+syminfo.ticker,alert.freq_once_per_bar_close)
  126. Hook := false
  127. // ~~ }
  128. // ~~ Debugger only check break once {
  129. if ta.change(array.get(pvts,1))
  130. Hook := true
  131. // ~~ }
  132.  
Advertisement
Add Comment
Please, Sign In to add comment