xmd79

Quasimodo Pattern

Dec 31st, 2022
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 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. // © budi_79
  3.  
  4. //@version=5
  5. indicator("Quasimodo Pattern", "Sants8-L", overlay=true, max_bars_back=5000, max_labels_count=500, max_lines_count=500)
  6.  
  7. zigzag_len = input.int(5, "ZigZag Length")
  8.  
  9. var float[] high_points_arr = array.new_float(5)
  10. var int[] high_index_arr = array.new_int(5)
  11. var float[] low_points_arr = array.new_float(5)
  12. var int[] low_index_arr = array.new_int(5)
  13.  
  14. to_up = high >= ta.highest(zigzag_len)
  15. to_down = low <= ta.lowest(zigzag_len)
  16.  
  17. trend = 1
  18. trend := nz(trend[1], 1)
  19. trend := trend == 1 and to_down ? -1 : trend == -1 and to_up ? 1 : trend
  20.  
  21. last_trend_up_since = ta.barssince(to_up[1])
  22. low_val = ta.lowest(nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1))
  23. low_index = bar_index - ta.barssince(low_val == low)
  24.  
  25. last_trend_down_since = ta.barssince(to_down[1])
  26. high_val = ta.highest(nz(last_trend_down_since > 0 ? last_trend_down_since : 1, 1))
  27. high_index = bar_index - ta.barssince(high_val == high)
  28.  
  29. if ta.change(trend) != 0
  30. if trend == 1
  31. array.push(low_points_arr, low_val)
  32. array.push(low_index_arr, low_index)
  33. if trend == -1
  34. array.push(high_points_arr, high_val)
  35. array.push(high_index_arr, high_index)
  36.  
  37.  
  38. f_get_high(ind) =>
  39. [array.get(high_points_arr, array.size(high_points_arr) - 1 - ind), array.get(high_index_arr, array.size(high_index_arr) - 1 - ind)]
  40.  
  41.  
  42. f_get_low(ind) =>
  43. [array.get(low_points_arr, array.size(low_points_arr) - 1 - ind), array.get(low_index_arr, array.size(low_index_arr) - 1 - ind)]
  44.  
  45.  
  46. [h0, h0i] = f_get_high(0)
  47. [l0, l0i] = f_get_low(0)
  48. [h1, h1i] = f_get_high(1)
  49. [l1, l1i] = f_get_low(1)
  50. [h2, h2i] = f_get_high(2)
  51. [l2, l2i] = f_get_low(2)
  52.  
  53. bu_cond = trend == -1 and h2 > h1 and l1 > l0 and h0 > h1 and close > l1
  54. be_cond = trend == 1 and l2 < l1 and h1 < h0 and l0 < l1 and close < h1
  55.  
  56. if bu_cond and not bu_cond[1]
  57. line.new(h2i, h2, l1i, l1, color=color.blue, width=1)
  58. line.new(l1i, l1, h1i, h1, color=color.blue, width=1)
  59. line.new(h1i, h1, l0i, l0, color=color.blue, width=1)
  60. line.new(l0i, l0, h0i, h0, color=color.blue, width=1)
  61. line.new(l1i, l1, bar_index, l1, color=color.blue, width=1)
  62. label.new(bar_index, l1, "Sants8!", style=label.style_label_up, textcolor=color.white, color=color.blue, size=size.tiny)
  63. alert("Bullish Sants8!", alert.freq_once_per_bar)
  64.  
  65. if be_cond and not be_cond[1]
  66. line.new(l2i, l2, h1i, h1, color=color.purple, width=1)
  67. line.new(h1i, h1, l1i, l1, color=color.purple, width=1)
  68. line.new(l1i, l1, h0i, h0, color=color.purple, width=1)
  69. line.new(h0i, h0, l0i, l0, color=color.purple, width=1)
  70. line.new(h1i, h1, bar_index, h1, color=color.purple, width=1)
  71. label.new(bar_index, h1, "Sants8!", style=label.style_label_down, textcolor=color.white, color=color.purple, size=size.tiny)
  72. alert("Bearish Sants8!", alert.freq_once_per_bar)
  73.  
Advertisement
Add Comment
Please, Sign In to add comment