Advertisement
xmd79

Pivot Points High Low & Missed Reversal Levels [LuxAlgo]

May 25th, 2023
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  2. // © LuxAlgo
  3.  
  4. //@version=5
  5. indicator("Pivot Points High Low & Missed Reversal Levels [LuxAlgo]",overlay=true,max_labels_count=500,max_lines_count=500,max_bars_back=500)
  6. length = input(50,'Pivot Length')
  7.  
  8. show_reg = input.bool(true,'Regular Pivots',inline='inline1')
  9. reg_ph_css = input.color(#ef5350,'High',inline='inline1')
  10. reg_pl_css = input.color(#26a69a,'Low',inline='inline1')
  11.  
  12. show_miss = input.bool(true,'Missed Pivots',inline='inline2')
  13. miss_ph_css = input.color(#ef5350,'High',inline='inline2')
  14. miss_pl_css = input.color(#26a69a,'Low',inline='inline2')
  15.  
  16. label_css = input.color(color.white,'Text Label Color')
  17. //------------------------------------------------------------------------------
  18. var line zigzag = na
  19. var line ghost_level = na
  20. var max = 0.,var min = 0.
  21. var max_x1 = 0,var min_x1 = 0
  22. var follow_max = 0.,var follow_max_x1 = 0
  23. var follow_min = 0.,var follow_min_x1 = 0
  24. var os = 0,var py1 = 0.,var px1 = 0
  25. //------------------------------------------------------------------------------
  26.  
  27. n = bar_index
  28. ph = ta.pivothigh(length,length)
  29. pl = ta.pivotlow(length,length)
  30.  
  31. max := math.max(high[length],max)
  32. min := math.min(low[length],min)
  33. follow_max := math.max(high[length],follow_max)
  34. follow_min := math.min(low[length],follow_min)
  35.  
  36. if max > max[1]
  37. max_x1 := n-length
  38. follow_min := low[length]
  39. if min < min[1]
  40. min_x1 := n-length
  41. follow_max := high[length]
  42.  
  43. if follow_min < follow_min[1]
  44. follow_min_x1 := n-length
  45. if follow_max > follow_max[1]
  46. follow_max_x1 := n-length
  47.  
  48. //------------------------------------------------------------------------------
  49. line.set_x2(ghost_level[1],n)
  50.  
  51. if ph
  52. if show_miss
  53. if os[1] == 1
  54. label.new(min_x1,min,'👻',color=miss_pl_css,style=label.style_label_up,size=size.small,
  55. tooltip=str.tostring(min,'#.####'))
  56.  
  57. zigzag := line.new(px1,py1,min_x1,min,color=miss_ph_css,style=line.style_dashed)
  58. px1 := min_x1,py1 := min
  59.  
  60. line.set_x2(ghost_level[1],px1)
  61. ghost_level := line.new(px1,py1,px1,py1,color=color.new(reg_pl_css,50),width=2)
  62. else if ph < max
  63. label.new(max_x1,max,'👻',color=miss_ph_css,style=label.style_label_down,size=size.small,
  64. tooltip=str.tostring(max,'#.####'))
  65. label.new(follow_min_x1,follow_min,'👻',color=miss_pl_css,style=label.style_label_up,size=size.small,
  66. tooltip=str.tostring(min,'#.####'))
  67.  
  68. zigzag := line.new(px1,py1,max_x1,max,color=miss_pl_css,style=line.style_dashed)
  69. px1 := max_x1,py1 := max
  70. line.set_x2(ghost_level[1],px1)
  71. ghost_level := line.new(px1,py1,px1,py1,color=color.new(reg_ph_css,50),width=2)
  72.  
  73. zigzag := line.new(px1,py1,follow_min_x1,follow_min,color=miss_ph_css,style=line.style_dashed)
  74. px1 := follow_min_x1,py1 := follow_min
  75. line.set_x2(ghost_level,px1)
  76. ghost_level := line.new(px1,py1,px1,py1,color=color.new(reg_pl_css,50),width=2)
  77.  
  78. if show_reg
  79. label.new(n-length,ph,'▼',textcolor=label_css,color=reg_ph_css,style=label.style_label_down,size=size.small,
  80. tooltip=str.tostring(ph,'#.####'))
  81. zigzag := line.new(px1,py1,n-length,ph,color=miss_pl_css,style=ph < max or os[1] == 1 ? line.style_dashed : line.style_solid)
  82.  
  83.  
  84. py1 := ph,px1 := n-length,os := 1,max := ph,min := ph
  85. //------------------------------------------------------------------------------
  86. if pl
  87. if show_miss
  88. if os[1] == 0
  89. label.new(max_x1,max,'👻',color=miss_ph_css,style=label.style_label_down,size=size.small,
  90. tooltip=str.tostring(max,'#.####'))
  91.  
  92. zigzag := line.new(px1,py1,max_x1,max,color=miss_pl_css,style=line.style_dashed)
  93. px1 := max_x1,py1 := max
  94.  
  95. line.set_x2(ghost_level[1],px1)
  96. ghost_level := line.new(px1,py1,px1,py1,color=color.new(reg_ph_css,50),width=2)
  97. else if pl > min
  98. label.new(follow_max_x1,follow_max,'👻',color=miss_ph_css,style=label.style_label_down,size=size.small,
  99. tooltip=str.tostring(max,'#.####'))
  100. label.new(min_x1,min,'👻',color=miss_pl_css,style=label.style_label_up,size=size.small,
  101. tooltip=str.tostring(min,'#.####'))
  102.  
  103. zigzag := line.new(px1,py1,min_x1,min,color=miss_ph_css,style=line.style_dashed)
  104. px1 := min_x1,py1 := min
  105. line.set_x2(ghost_level[1],px1)
  106. ghost_level := line.new(px1,py1,px1,py1,color=color.new(reg_pl_css,50),width=2)
  107.  
  108. zigzag := line.new(px1,py1,follow_max_x1,follow_max,color=miss_pl_css,style=line.style_dashed)
  109. px1 := follow_max_x1,py1 := follow_max
  110. line.set_x2(ghost_level,px1)
  111. ghost_level := line.new(px1,py1,px1,py1,color=color.new(reg_ph_css,50),width=2)
  112.  
  113. if show_reg
  114. label.new(n-length,pl,'▲',textcolor=label_css,color=reg_pl_css,style=label.style_label_up,size=size.small,
  115. tooltip=str.tostring(pl,'#.####'))
  116. zigzag := line.new(px1,py1,n-length,pl,color=miss_ph_css,style=pl > min or os[1] == 0 ? line.style_dashed : line.style_solid)
  117.  
  118.  
  119. py1 := pl,px1 := n-length,os := 0,max := pl,min := pl
  120. //------------------------------------------------------------------------------
  121. var label lbl = na
  122. if barstate.islast
  123. x = 0,y = 0.
  124.  
  125. prices = array.new_float(0)
  126. prices_x = array.new_int(0)
  127.  
  128. for i = 0 to n-px1-1
  129. array.push(prices,os==1?low[i]:high[i])
  130. array.push(prices_x,n-i)
  131.  
  132. label.delete(lbl[1])
  133.  
  134. if os == 1
  135. y := array.min(prices)
  136. x := array.get(prices_x,array.indexof(prices,y))
  137.  
  138. if show_miss
  139. lbl := label.new(x,y,'👻',color=miss_pl_css,style=label.style_label_up,size=size.small,
  140. tooltip=str.tostring(y,'#.####'))
  141. else
  142. y := array.max(prices)
  143. x := array.get(prices_x,array.indexof(prices,y))
  144.  
  145. if show_miss
  146. lbl := label.new(x,y,'👻',color=miss_ph_css,style=label.style_label_down,size=size.small,
  147. tooltip=str.tostring(y,'#.####'))
  148.  
  149. if show_miss
  150. line.delete(line.new(px1,py1,x,y,color=os == 1 ? miss_ph_css : miss_pl_css,style=line.style_dashed)[1])
  151.  
  152. line.delete(line.new(x,y,n,y,color = color.new(os == 1 ? miss_ph_css : miss_pl_css,50),width=2)[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement