xmd79

3rd Wave

Oct 9th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 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. // © LonesomeTheBlue
  3.  
  4. //@version=5
  5. indicator('3rd Wave', overlay=true, max_bars_back=500, max_lines_count=500, max_labels_count=500)
  6.  
  7. // import necessary functions to calculate and show the zigzag
  8. import LonesomeTheBlue/CreateAndShowZigzag/1 as ZigZag
  9.  
  10. prd = input.int(defval=8, title='ZigZag Period', minval=2, maxval=50, group='setup')
  11. ret_rate_min = input.float(defval=0.382, title='Min/Max Retracements', minval=0.100, maxval=0.900, inline='retrate', group='setup')
  12. ret_rate_max = input.float(defval=0.786, title='', minval=0.100, maxval=0.900, inline='retrate', group='setup')
  13. checkvol_support = input.bool(defval=true, title='Check Volume Support', group='setup')
  14. target1_enb = input.bool(defval=true, title='Target 1', inline='t1', group='targets')
  15. target1_ret = input.float(defval=1., title='', inline='t1', group='targets', tooltip = "%X of wave 1 from the begining of wave 2")
  16. target2_enb = input.bool(defval=true, title='Target 2', inline='t2', group='targets')
  17. target2_ret = input.float(defval=1.618, title='', inline='t2', group='targets', tooltip = "%X of wave 1 from the begining of wave 2")
  18. target3_enb = input.bool(defval=false, title='Target 3', inline='t3', group='targets')
  19. target3_ret = input.float(defval=2.618, title='', inline='t3', group='targets', tooltip = "%X of wave 1 from the begining of wave 2")
  20. target4_enb = input.bool(defval=false, title='Target 4', inline='t4', group='targets')
  21. target4_ret = input.float(defval=3.618, title='', inline='t4', group='targets', tooltip = "%X of wave 1 from the begining of wave 2")
  22. showwave12 = input.bool(defval=true, title='Show Wave 1 and 2', group='colors')
  23. showbo = input.bool(defval=true, title='Zone', inline='bocol', group='colors')
  24. bupcol = input.color(defval=color.rgb(0, 255, 0, 85), title='', inline='bocol', group='colors')
  25. bdncol = input.color(defval=color.rgb(255, 0, 0, 85), title='', inline='bocol', group='colors')
  26. showzigzag = input.bool(defval=false, title='Zig Zag', inline='zzcol', group='colors')
  27. upcol = input.color(defval=color.lime, title='', inline='zzcol', group='colors')
  28. dncol = input.color(defval=color.red, title='', inline='zzcol', group='colors')
  29.  
  30. // definitions for zigzag arrays
  31. var max_array_size = 10 // max length for zigzag array
  32. var zigzag = array.new_float(0)
  33. oldzigzag = array.copy(zigzag) // keep old zigzag
  34.  
  35. // get the zigzag
  36. dir = ZigZag.getZigzag(zigzag, prd, max_array_size)
  37. // show the zigzag
  38. if showzigzag
  39. ZigZag.showZigzag(zigzag, oldzigzag, dir, upcol, dncol)
  40.  
  41.  
  42. int len = array.size(zigzag) >= 8 ? bar_index - math.round(array.get(zigzag, 7)) : 1
  43. bool vol_support = (not checkvol_support or (checkvol_support and ta.linreg(volume, len, 0) - ta.linreg(volume, len, 1) > 0))
  44. var bool can_check_it = true
  45. bool thereisbo = false
  46. if (dir != dir[1])
  47. can_check_it := true
  48. can_check_it
  49.  
  50. // check if there is possible 3rd wave and show breakout if there is any
  51. if array.size(zigzag) >= 8 and can_check_it
  52. w12 = math.abs(array.get(zigzag, 2) - array.get(zigzag, 4)) / math.abs(array.get(zigzag, 4) - array.get(zigzag, 6))
  53. if w12 >= ret_rate_min and w12 <= ret_rate_max and (dir == 1 and high > array.get(zigzag, 4) or dir == -1 and low < array.get(zigzag, 4))
  54. can_check_it := false
  55. if vol_support
  56. thereisbo := true
  57. // draw bo
  58. if showbo
  59. box.new(left=math.round(array.get(zigzag, 7)), top=array.get(zigzag, 4), right=bar_index, bottom=array.get(zigzag, 6), border_color=color.blue, border_width=1, border_style=line.style_dotted, bgcolor=dir == 1 ? bupcol : bdncol)
  60.  
  61. if showwave12
  62. line.new(x1=math.round(array.get(zigzag, 7)), y1=array.get(zigzag, 6), x2=math.round(array.get(zigzag, 5)), y2=array.get(zigzag, 4))
  63. line.new(x1=math.round(array.get(zigzag, 5)), y1=array.get(zigzag, 4), x2=math.round(array.get(zigzag, 3)), y2=array.get(zigzag, 2))
  64. label.new(x=math.round(array.get(zigzag, 7)), y=array.get(zigzag, 6), text='0', color=color.new(color.white, 100), textcolor=color.blue, style=dir == 1 ? label.style_label_up : label.style_label_down)
  65. label.new(x=math.round(array.get(zigzag, 5)), y=array.get(zigzag, 4), text='1', color=color.new(color.white, 100), textcolor=color.blue, style=dir == 1 ? label.style_label_down : label.style_label_up)
  66. label.new(x=math.round(array.get(zigzag, 3)), y=array.get(zigzag, 2), text='2', color=color.new(color.white, 100), textcolor=color.blue, style=dir == 1 ? label.style_label_up : label.style_label_down)
  67.  
  68. // draw label
  69. label.new(x=bar_index, y=array.get(zigzag, 6), color=dir == 1 ? upcol : dncol, style=dir == 1 ? label.style_triangleup : label.style_triangledown, size=size.small)
  70.  
  71. base = array.get(zigzag, 2)
  72. wave1 = math.abs(array.get(zigzag, 4) - array.get(zigzag, 6))
  73. if target1_enb
  74. line.new(x1=bar_index, y1=math.max(base + dir * wave1 * target1_ret, 0), x2=math.round(array.get(zigzag, 7)), y2=math.max(base + dir * wave1 * target1_ret, 0), style=line.style_dashed)
  75. if target2_enb
  76. line.new(x1=bar_index, y1=math.max(base + dir * wave1 * target2_ret, 0), x2=math.round(array.get(zigzag, 7)), y2=math.max(base + dir * wave1 * target2_ret, 0), style=line.style_dashed)
  77. if target3_enb
  78. line.new(x1=bar_index, y1=math.max(base + dir * wave1 * target3_ret, 0), x2=math.round(array.get(zigzag, 7)), y2=math.max(base + dir * wave1 * target3_ret, 0), style=line.style_dashed)
  79. if target4_enb
  80. line.new(x1=bar_index, y1=math.max(base + dir * wave1 * target4_ret, 0), x2=math.round(array.get(zigzag, 7)), y2=math.max(base + dir * wave1 * target4_ret, 0), style=line.style_dashed)
  81.  
  82. alertcondition(thereisbo and dir == 1, title = "Breakout Long", message = "Breakout Long")
  83. alertcondition(thereisbo and dir == -1, title = "Breakout Short", message = "Breakout Short")
  84.  
Advertisement
Add Comment
Please, Sign In to add comment