Advertisement
andypartridge47

Pivot Points High Low & Missed Reversal Levels [LuxAlgo]

Nov 9th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. //@version=5
  2. strategy("Pivot Points High Low & Missed Reversal Levels [LuxAlgo]", overlay=true, max_labels_count=500, max_lines_count=500, max_bars_back=500)
  3. length = input(50, 'Pivot Length')
  4.  
  5. show_reg = input.bool(true, 'Regular Pivots', inline='inline1')
  6. reg_ph_css = input.color(#ef5350, 'High', inline='inline1')
  7. reg_pl_css = input.color(#26a69a, 'Low', inline='inline1')
  8.  
  9. show_miss = input.bool(true, 'Missed Pivots', inline='inline2')
  10. miss_ph_css = input.color(#ef5350, 'High', inline='inline2')
  11. miss_pl_css = input.color(#26a69a, 'Low', inline='inline2')
  12.  
  13. label_css = input.color(color.white, 'Text Label Color')
  14.  
  15. // Entry amount input
  16. entryAmount = input.float(200, title="Entry Amount ($)")
  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. n = bar_index
  27. ph = ta.pivothigh(length, length)
  28. pl = ta.pivotlow(length, length)
  29.  
  30. max := math.max(high[length], max)
  31. min := math.min(low[length], min)
  32. follow_max := math.max(high[length], follow_max)
  33. follow_min := math.min(low[length], follow_min)
  34.  
  35. if max > max[1]
  36. max_x1 := n - length
  37. follow_min := low[length]
  38. if min < min[1]
  39. min_x1 := n - length
  40. follow_max := high[length]
  41.  
  42. if follow_min < follow_min[1]
  43. follow_min_x1 := n - length
  44. if follow_max > follow_max[1]
  45. follow_max_x1 := n - length
  46.  
  47. line.set_x2(ghost_level[1], n)
  48.  
  49. if ph
  50. if show_miss
  51. if os[1] == 1
  52. label.new(min_x1, min, '👻', color=miss_pl_css, style=label.style_label_up, size=size.small,
  53. tooltip=str.tostring(min, '#.####'))
  54.  
  55. zigzag := line.new(px1, py1, min_x1, min, color=miss_ph_css, style=line.style_dashed)
  56. px1 := min_x1, py1 := min
  57.  
  58. line.set_x2(ghost_level[1], px1)
  59. ghost_level := line.new(px1, py1, px1, py1, color=color.new(reg_pl_css, 50), width=2)
  60. else if ph < max
  61. label.new(max_x1, max, '👻', color=miss_ph_css, style=label.style_label_down, size=size.small,
  62. tooltip=str.tostring(max, '#.####'))
  63. label.new(follow_min_x1, follow_min, '👻', color=miss_pl_css, style=label.style_label_up, size=size.small,
  64. tooltip=str.tostring(min, '#.####'))
  65.  
  66. zigzag := line.new(px1, py1, max_x1, max, color=miss_pl_css, style=line.style_dashed)
  67. px1 := max_x1, py1 := max
  68. line.set_x2(ghost_level[1], px1)
  69. ghost_level := line.new(px1, py1, px1, py1, color=color.new(reg_ph_css, 50), width=2)
  70.  
  71. zigzag := line.new(px1, py1, follow_min_x1, follow_min, color=miss_ph_css, style=line.style_dashed)
  72. px1 := follow_min_x1, py1 := follow_min
  73. line.set_x2(ghost_level, px1)
  74. ghost_level := line.new(px1, py1, px1, py1, color=color.new(reg_pl_css, 50), width=2)
  75.  
  76. if show_reg
  77. label.new(n - length, ph, 'â–¼', textcolor=label_css, color=reg_ph_css, style=label.style_label_down, size=size.small,
  78. tooltip=str.tostring(ph, '#.####'))
  79. 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)
  80.  
  81. py1 := ph, px1 := n - length, os := 1, max := ph, min := ph
  82.  
  83. if pl
  84. if show_miss
  85. if os[1] == 0
  86. label.new(max_x1, max, '👻', color=miss_ph_css, style=label.style_label_down, size=size.small,
  87. tooltip=str.tostring(max, '#.####'))
  88.  
  89. zigzag := line.new(px1, py1, max_x1, max, color=miss_pl_css, style=line.style_dashed)
  90. px1 := max_x1, py1 := max
  91.  
  92. line.set_x2(ghost_level[1], px1)
  93. ghost_level := line.new(px1, py1, px1, py1, color=color.new(reg_ph_css, 50), width=2)
  94. else if pl > min
  95. label.new(follow_max_x1, follow_max, '👻', color=miss_ph_css, style=label.style_label_down, size=size.small,
  96. tooltip=str.tostring(max, '#.####'))
  97. label.new(min_x1, min, '👻', color=miss_pl_css, style=label.style_label_up, size=size.small,
  98. tooltip=str.tostring(min, '#.####'))
  99.  
  100. zigzag := line.new(px1, py1, min_x1, min, color=miss_ph_css, style=line.style_dashed)
  101. px1 := min_x1, py1 := min
  102. line.set_x2(ghost_level[1], px1)
  103. ghost_level := line.new(px1, py1, px1, py1, color=color.new(reg_pl_css, 50), width=2)
  104.  
  105. zigzag := line.new(px1, py1, follow_max_x1, follow_max, color=miss_pl_css, style=line.style_dashed)
  106. px1 := follow_max_x1, py1 := follow_max
  107. line.set_x2(ghost_level, px1)
  108. ghost_level := line.new(px1, py1, px1, py1, color=color.new(reg_ph_css, 50), width=2)
  109.  
  110. if show_reg
  111. label.new(n - length, pl, 'â–²', textcolor=label_css, color=reg_pl_css, style=label.style_label_up, size=size.small,
  112. tooltip=str.tostring(pl, '#.####'))
  113. zigzag := line.new(px1, py1, n - length, pl, color=miss_pl_css, style=pl > min or os[1] == 0 ? line.style_dashed : line.style_solid)
  114.  
  115. py1 := pl, px1 := n - length, os := 0, max := pl, min := pl
  116.  
  117. // Long entry on missed pivot low
  118. if show_miss and os == 1 and ph
  119. strategy.entry("Long", strategy.long, qty=entryAmount / close)
  120.  
  121. // Short entry on missed pivot high
  122. if show_miss and os == 0 and pl
  123. strategy.entry("Short", strategy.short, qty=entryAmount / close)
  124.  
  125. var label lbl = na
  126. if barstate.islast
  127. x = 0, y = 0.
  128.  
  129. prices = array.new_float(0)
  130. prices_x = array.new_int(0)
  131.  
  132. for i = 0 to n - px1 - 1
  133. array.push(prices, os == 1 ? low[i] : high[i])
  134. array.push(prices_x, n - i)
  135.  
  136. label.delete(lbl[1])
  137.  
  138. if os == 1
  139. y := array.min(prices)
  140. x := array.get(prices_x, array.indexof(prices, y))
  141.  
  142. if show_miss
  143. lbl := label.new(x, y, '👻', color=miss_pl_css, style=label.style_label_up, size=size.small,
  144. tooltip=str.tostring(y, '#.####'))
  145. else
  146. y := array.max(prices)
  147. x := array.get(prices_x, array.indexof(prices, y))
  148.  
  149. if show_miss
  150. lbl := label.new(x, y, '👻', color=miss_ph_css, style=label.style_label_down, size=size.small,
  151. tooltip=str.tostring(y, '#.####'))
  152.  
  153. if show_miss
  154. line.delete(line.new(px1, py1, x, y, color=os == 1 ? miss_ph_css : miss_pl_css, style=line.style_dashed)[1])
  155.  
  156. line.delete(line.new(x, y, n, y, color=color.new(os == 1 ? miss_ph_css : miss_pl_css, 50), width=2)[1])
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement