xmd79

Multi-timeframe Harmonic Patterns

Dec 31st, 2022
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 113.47 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. // © dandrideng
  3.  
  4. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  5. //# * ══════════════════════════════════════════════════════════════════════════════════════════════
  6. //# *
  7. //# * Study : Multi-timeframe Harmonic Patterns
  8. //# * Author : © dandri deng
  9. //# *
  10. //# * Revision History
  11. //# * Initial : Nov. 24, 2022 Fist release version
  12. //# * Update : Dec. 30, 2022 Fist public version
  13. //# *
  14. //# * ══════════════════════════════════════════════════════════════════════════════════════════════
  15. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  16.  
  17. //@version=5
  18. indicator("Multi-timeframe Harmonic Patterns",
  19. shorttitle="MTF Harmonic Patterns",
  20. overlay=true,
  21. max_lines_count=500,
  22. max_labels_count=500,
  23. max_boxes_count=500,
  24. max_bars_back=2000)
  25.  
  26.  
  27. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  28. // ZigZag Functions -------------------------------------------------------------------------------- //
  29.  
  30. //calculate zigzag
  31. calculate_zigzag(simple string resolution, simple int period, float hsrc, float lsrc, int max_pivots) =>
  32. newbar = ta.change(time(resolution)) != 0
  33. bi = ta.valuewhen(newbar, bar_index, period - 1)
  34. len = bar_index - bi + 1
  35.  
  36. float ph = na
  37. float pl = na
  38. ph := ta.highestbars(hsrc, nz(len, 1)) == 0 ? hsrc : na
  39. pl := ta.lowestbars(lsrc, nz(len, 1)) == 0 ? lsrc : na
  40.  
  41. var dir = 0
  42. dir := ph and na(pl) ? 1 : pl and na(ph) ? -1 : dir
  43. var zigzag = array.new_float(0)
  44. oldzigzag = array.copy(zigzag)
  45.  
  46. bool dirchanged = (dir != dir[1])
  47. if ph or pl
  48. if dirchanged
  49. bindex = bar_index
  50. value = dir == 1 ? ph : pl
  51. array.unshift(zigzag, bindex)
  52. array.unshift(zigzag, value)
  53. if array.size(zigzag) > max_pivots
  54. array.pop(zigzag)
  55. array.pop(zigzag)
  56. else
  57. bindex = bar_index
  58. value = dir == 1 ? ph : pl
  59. if array.size(zigzag) == 0
  60. array.unshift(zigzag, bindex)
  61. array.unshift(zigzag, value)
  62. if array.size(zigzag) > max_pivots
  63. array.pop(zigzag)
  64. array.pop(zigzag)
  65. else
  66. if (dir == 1 and value > array.get(zigzag, 0)) or (dir == -1 and value < array.get(zigzag, 0))
  67. array.set(zigzag, 0, value)
  68. array.set(zigzag, 1, bindex)
  69.  
  70. [zigzag, oldzigzag, dir]
  71.  
  72. //is new zigzag
  73. is_newzigzag(float[] zigzag, float[] oldzigzag) =>
  74. res = false
  75. if array.size(zigzag) >= 4 and array.size(oldzigzag) >= 4
  76. cond1 = array.get(zigzag, 0) != array.get(oldzigzag, 0) or array.get(zigzag, 1) != array.get(oldzigzag, 1)
  77. cond2 = array.get(zigzag, 2) == array.get(oldzigzag, 2) and array.get(zigzag, 3) == math.round(array.get(oldzigzag, 3))
  78. res := cond1 and cond2
  79. res
  80.  
  81. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  82. // 5-point Harmonic Pattern Functions ------------------------------------------------------------- //
  83.  
  84. //draw trading lines
  85. draw_trading_lines(draw, start_barindex, entry_price, stop_loss, take_profit1, take_profit2, coluor, horizontal_length) =>
  86. var line line_ep = na
  87. var line line_sl = na
  88. var line line_tp1 = na
  89. var line line_tp2 = na
  90.  
  91. var label label_ep = na
  92. var label label_sl = na
  93. var label label_tp1 = na
  94. var label label_tp2 = na
  95.  
  96. if draw
  97. line.delete(line_ep)
  98. line.delete(line_sl)
  99. line.delete(line_tp1)
  100. line.delete(line_tp2)
  101.  
  102. label.delete(label_ep)
  103. label.delete(label_sl)
  104. label.delete(label_tp1)
  105. label.delete(label_tp2)
  106.  
  107. line_ep := line.new(x1=start_barindex, y1=entry_price, x2=start_barindex + horizontal_length, y2=entry_price, style=line.style_dashed, color=color.new(coluor, 30), width=2)
  108. line_sl := line.new(x1=start_barindex, y1=stop_loss, x2=start_barindex + horizontal_length, y2=stop_loss, style=line.style_dashed, color=color.new(coluor, 30), width=2)
  109. line_tp1 := line.new(x1=start_barindex, y1=take_profit1, x2=start_barindex + horizontal_length, y2=take_profit1, style=line.style_dashed, color=color.new(coluor, 30), width=2)
  110. line_tp2 := line.new(x1=start_barindex, y1=take_profit2, x2=start_barindex + horizontal_length, y2=take_profit2, style=line.style_dashed, color=color.new(coluor, 30), width=2)
  111.  
  112. label_ep := label.new(x=start_barindex + horizontal_length + 1, y=entry_price, style=label.style_label_left, text="ENT: " + str.tostring(entry_price), color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  113. label_sl := label.new(x=start_barindex + horizontal_length + 1, y=stop_loss, style=label.style_label_left, text="SL: " + str.tostring(stop_loss), color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  114. label_tp1 := label.new(x=start_barindex + horizontal_length + 1, y=take_profit1, style=label.style_label_left, text="TP1: " + str.tostring(take_profit1), color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  115. label_tp2 := label.new(x=start_barindex + horizontal_length + 1, y=take_profit2, style=label.style_label_left, text="TP2: " + str.tostring(take_profit2), color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  116. 0
  117. else
  118. if not na(label_ep) and (bar_index - label.get_x(label_ep)) * timeframe.multiplier > 30 * 24 * 60
  119. line.delete(line_ep)
  120. line.delete(line_sl)
  121. line.delete(line_tp1)
  122. line.delete(line_tp2)
  123.  
  124. label.delete(label_ep)
  125. label.delete(label_sl)
  126. label.delete(label_tp1)
  127. label.delete(label_tp2)
  128. 0
  129.  
  130. //draw harmonic pattern
  131. draw_harmonic_pattern(draw, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  132. var line line_XA = na
  133. var line line_AB = na
  134. var line line_XB = na
  135. var line line_BC = na
  136. var line line_CD = na
  137. var line line_BD = na
  138. var line line_XD = na
  139. var line line_AC = na
  140.  
  141. var label label_X = na
  142. var label label_A = na
  143. var label label_B = na
  144. var label label_C = na
  145. var label label_D = na
  146.  
  147. var label label_XB = na
  148. var label label_BD = na
  149. var label label_AC = na
  150. var label label_XD = na
  151.  
  152. if draw
  153. line.delete(line_XA)
  154. line.delete(line_AB)
  155. line.delete(line_XB)
  156. line.delete(line_BC)
  157. line.delete(line_CD)
  158. line.delete(line_BD)
  159. line.delete(line_XD)
  160. line.delete(line_AC)
  161.  
  162. label.delete(label_X)
  163. label.delete(label_A)
  164. label.delete(label_B)
  165. label.delete(label_C)
  166. label.delete(label_D)
  167.  
  168. label.delete(label_XB)
  169. label.delete(label_BD)
  170. label.delete(label_AC)
  171. label.delete(label_XD)
  172.  
  173. line_XA := line.new(x1=Xx, y1=Xy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=2)
  174. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  175. line_XB := line.new(x1=Xx, y1=Xy, x2=Bx, y2=By, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  176. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  177. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  178. line_BD := line.new(x1=Bx, y1=By, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  179. line_XD := line.new(x1=Xx, y1=Xy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  180. line_AC := line.new(x1=Ax, y1=Ay, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  181. linefill.new(line_XA, line_XB, color=color.new(coluor, 80))
  182. linefill.new(line_BC, line_BD, color=color.new(coluor, 80))
  183.  
  184. duration = ((Dx - Xx) * timeframe.multiplier) / (60.0 * 24.0)
  185. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  186.  
  187. label_X := label.new(x=Xx, y=Xy, text="X", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  188. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  189. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  190. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  191. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  192.  
  193. XA = math.abs(Xy - Ay)
  194. AB = math.abs(Ay - By)
  195. BC = math.abs(By - Cy)
  196. CD = math.abs(Cy - Dy)
  197. AD = math.abs(Ay - Dy)
  198. label_XB := label.new(x=int((Xx + Bx) / 2), y=(Xy + By) / 2, text=str.tostring(AB / XA, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  199. label_BD := label.new(x=int((Bx + Dx) / 2), y=(By + Dy) / 2, text=str.tostring(CD / BC, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  200. label_AC := label.new(x=int((Ax + Cx) / 2), y=(Ay + Cy) / 2, text=str.tostring(BC / AB, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  201. label_XD := label.new(x=int((Xx + Dx) / 2), y=(Xy + Dy) / 2, text=str.tostring(AD / XA, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  202. 0
  203. else
  204. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  205. line.delete(line_XA)
  206. line.delete(line_AB)
  207. line.delete(line_XB)
  208. line.delete(line_BC)
  209. line.delete(line_CD)
  210. line.delete(line_BD)
  211. line.delete(line_XD)
  212. line.delete(line_AC)
  213.  
  214. label.delete(label_X)
  215. label.delete(label_A)
  216. label.delete(label_B)
  217. label.delete(label_C)
  218. label.delete(label_D)
  219.  
  220. label.delete(label_XB)
  221. label.delete(label_BD)
  222. label.delete(label_AC)
  223. label.delete(label_XD)
  224. 0
  225.  
  226. //get 5-points
  227. get_5_points(zigzag, oldzigzag, zigzagdir, confirm) =>
  228. if array.size(zigzag) >= 10 and ta.barssince(is_newzigzag(zigzag, oldzigzag)) == confirm
  229. Xx = math.round(array.get(zigzag, 9))
  230. Xy = array.get(zigzag, 8)
  231. Xd = zigzagdir[bar_index - Xx]
  232.  
  233. Ax = math.round(array.get(zigzag, 7))
  234. Ay = array.get(zigzag, 6)
  235. Ad = zigzagdir[bar_index - Ax]
  236.  
  237. Bx = math.round(array.get(zigzag, 5))
  238. By = array.get(zigzag, 4)
  239. Bd = zigzagdir[bar_index - Bx]
  240.  
  241. Cx = math.round(array.get(zigzag, 3))
  242. Cy = array.get(zigzag, 2)
  243. Cd = zigzagdir[bar_index - Cx]
  244.  
  245. Dx = math.round(array.get(zigzag, 1))
  246. Dy = array.get(zigzag, 0)
  247. Dd = zigzagdir[bar_index - Dx]
  248.  
  249. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd]
  250. else
  251. [na, na, na, na, na, na, na, na, na, na, na, na, na, na, na]
  252.  
  253. //gartlay pattern
  254. gartlay_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  255. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  256.  
  257. XA = math.abs(Xy - Ay)
  258. XC = math.abs(Xy - Cy)
  259. AB = math.abs(Ay - By)
  260. BC = math.abs(By - Cy)
  261. CD = math.abs(Cy - Dy)
  262. AD = math.abs(Ay - Dy)
  263.  
  264. _XB = math.abs(Xx - Bx)
  265. _BD = math.abs(Bx - Dx)
  266.  
  267. cond1 = AB / XA >= 0.518 and AB / XA <= 0.718 //best 0.618 (±0.1)
  268. cond2 = BC / AB >= 0.382 and BC / AB <= 0.886
  269. cond3 = CD / BC >= 1.272 and CD / BC <= 1.618
  270. cond4 = AD / XA >= 0.686 and AD / XA <= 0.886 //best 0.786 (±0.1)
  271. cond5 = CD / AB >= 0.800 and CD / AB <= 1.200 //best 1 (±0.2)
  272. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  273. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  274.  
  275. entry_price = Dy
  276. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  277. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  278. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  279.  
  280. coluor = Dd == 1 ? bearcolor : bullcolor
  281. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  282. name = "Gartlay " + (Dd == 1 ? "▼" : "▲")
  283. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  284. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  285.  
  286. [cond, -Dd, trendy]
  287.  
  288. //cypher pattern
  289. cypher_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  290. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  291.  
  292. XA = math.abs(Xy - Ay)
  293. XC = math.abs(Xy - Cy)
  294. AB = math.abs(Ay - By)
  295. BC = math.abs(By - Cy)
  296. CD = math.abs(Cy - Dy)
  297. AD = math.abs(Ay - Dy)
  298.  
  299. _XB = math.abs(Xx - Bx)
  300. _BD = math.abs(Bx - Dx)
  301.  
  302. cond1 = AB / XA >= 0.382 and AB / XA <= 0.618
  303. cond2 = XC / XA >= 1.272 and XC / XA <= 1.414
  304. cond3 = CD / XC >= 0.686 and CD / XC <= 0.886 //best 0.786 (±0.1)
  305. cond4 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  306. cond = cond1 and cond2 and cond3 and cond4
  307.  
  308. entry_price = Dy
  309. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  310. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  311. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  312.  
  313. coluor = Dd == 1 ? bearcolor : bullcolor
  314. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  315. name = "Cypher " + (Dd == 1 ? "▼" : "▲")
  316. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  317. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  318.  
  319. [cond, -Dd, trendy]
  320.  
  321. //bat pattern
  322. bat_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  323. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  324.  
  325. XA = math.abs(Xy - Ay)
  326. XC = math.abs(Xy - Cy)
  327. AB = math.abs(Ay - By)
  328. BC = math.abs(By - Cy)
  329. CD = math.abs(Cy - Dy)
  330. AD = math.abs(Ay - Dy)
  331.  
  332. _XB = math.abs(Xx - Bx)
  333. _BD = math.abs(Bx - Dx)
  334.  
  335. cond1 = AB / XA >= 0.382 and AB / XA <= 0.500
  336. cond2 = BC / AB >= 0.382 and BC / AB <= 0.886
  337. cond3 = CD / BC >= 1.618 and CD / BC <= 2.618
  338. cond4 = AD / XA >= 0.786 and AD / XA <= 0.986 //best 0.886 (±0.1)
  339. cond5 = CD / AB >= 1.072 and CD / AB <= 1.472 //best 1.272 (±0.2)
  340. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  341. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  342.  
  343. entry_price = Dy
  344. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  345. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  346. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  347.  
  348. coluor = Dd == 1 ? bearcolor : bullcolor
  349. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  350. name = "Bat " + (Dd == 1 ? "▼" : "▲")
  351. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  352. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  353.  
  354. [cond, -Dd, trendy]
  355.  
  356. //deepcrab pattern
  357. deepcrab_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  358. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  359.  
  360. XA = math.abs(Xy - Ay)
  361. XC = math.abs(Xy - Cy)
  362. AB = math.abs(Ay - By)
  363. BC = math.abs(By - Cy)
  364. CD = math.abs(Cy - Dy)
  365. AD = math.abs(Ay - Dy)
  366.  
  367. _XB = math.abs(Xx - Bx)
  368. _BD = math.abs(Bx - Dx)
  369.  
  370. cond1 = AB / XA >= 0.786 and AB / XA <= 0.986 // best 0.886 (±0.1)
  371. cond2 = BC / AB >= 0.382 and BC / AB <= 0.886
  372. cond3 = CD / BC >= 2.242 and CD / BC <= 3.618
  373. cond4 = AD / XA >= 1.518 and AD / XA <= 1.718 //best 1.618 (±0.1)
  374. cond5 = CD / AB >= 1.072 and CD / AB <= 1.818 //best 1.272-1.618 (±0.2)
  375. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  376. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  377.  
  378. entry_price = Dy
  379. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  380. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  381. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  382.  
  383. coluor = Dd == 1 ? bearcolor : bullcolor
  384. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  385. name = "DeepCrab " + (Dd == 1 ? "▼" : "▲")
  386. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  387. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  388.  
  389. [cond, -Dd, trendy]
  390.  
  391. //crab pattern
  392. crab_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  393. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  394.  
  395. XA = math.abs(Xy - Ay)
  396. XC = math.abs(Xy - Cy)
  397. AB = math.abs(Ay - By)
  398. BC = math.abs(By - Cy)
  399. CD = math.abs(Cy - Dy)
  400. AD = math.abs(Ay - Dy)
  401.  
  402. _XB = math.abs(Xx - Bx)
  403. _BD = math.abs(Bx - Dx)
  404.  
  405. cond1 = AB / XA >= 0.382 and AB / XA <= 0.618
  406. cond2 = BC / AB >= 0.382 and BC / AB <= 0.886
  407. cond3 = CD / BC >= 2.242 and CD / BC <= 3.618
  408. cond4 = AD / XA >= 1.518 and AD / XA <= 1.718 //best 1.618 (±0.1)
  409. cond5 = CD / AB >= 1.072 and CD / AB <= 1.818 //best 1.272-1.618 (±0.2)
  410. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  411. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  412.  
  413. entry_price = Dy
  414. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  415. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  416. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  417.  
  418. coluor = Dd == 1 ? bearcolor : bullcolor
  419. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  420. name = "Crab " + (Dd == 1 ? "▼" : "▲")
  421. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  422. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  423.  
  424. [cond, -Dd, trendy]
  425.  
  426. //butterfly pattern
  427. butterfly_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  428. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  429.  
  430. XA = math.abs(Xy - Ay)
  431. XC = math.abs(Xy - Cy)
  432. AB = math.abs(Ay - By)
  433. BC = math.abs(By - Cy)
  434. CD = math.abs(Cy - Dy)
  435. AD = math.abs(Ay - Dy)
  436.  
  437. _XB = math.abs(Xx - Bx)
  438. _BD = math.abs(Bx - Dx)
  439.  
  440. cond1 = AB / XA >= 0.686 and AB / XA <= 0.886 //best 0.786 (±0.1)
  441. cond2 = BC / AB >= 0.382 and BC / AB <= 0.886
  442. cond3 = CD / BC >= 1.618 and CD / BC <= 2.618
  443. cond4 = AD / XA >= 1.272 and AD / XA <= 1.618
  444. cond5 = CD / AB >= 0.800 and CD / AB <= 1.472 //best 1-1.272 (±0.2)
  445. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  446. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  447.  
  448. entry_price = Dy
  449. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  450. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  451. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  452.  
  453. coluor = Dd == 1 ? bearcolor : bullcolor
  454. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  455. name = "Butterfly " + (Dd == 1 ? "▼" : "▲")
  456. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  457. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  458.  
  459. [cond, -Dd, trendy]
  460.  
  461. //shark pattern
  462. shark_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  463. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  464.  
  465. XA = math.abs(Xy - Ay)
  466. XC = math.abs(Xy - Cy)
  467. AB = math.abs(Ay - By)
  468. BC = math.abs(By - Cy)
  469. CD = math.abs(Cy - Dy)
  470. AD = math.abs(Ay - Dy)
  471.  
  472. _XB = math.abs(Xx - Bx)
  473. _BD = math.abs(Bx - Dx)
  474.  
  475. cond1 = AB / XA >= 0.382 and AB / XA <= 0.618
  476. cond2 = BC / AB >= 1.130 and BC / AB <= 1.618
  477. cond3 = CD / BC >= 1.618 and CD / BC <= 2.240
  478. cond4 = CD / XC >= 0.886 and CD / XC <= 1.130
  479. cond5 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  480. cond = cond1 and cond2 and cond3 and cond4 and cond5
  481.  
  482. entry_price = Dy
  483. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  484. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  485. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  486.  
  487. coluor = Dd == 1 ? bearcolor : bullcolor
  488. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  489. name = "Shark " + (Dd == 1 ? "▼" : "▲")
  490. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  491. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  492.  
  493. [cond, -Dd, trendy]
  494.  
  495. //anti-gartlay pattern
  496. anti_gartlay_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  497. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  498.  
  499. XA = math.abs(Xy - Ay)
  500. XC = math.abs(Xy - Cy)
  501. AB = math.abs(Ay - By)
  502. BC = math.abs(By - Cy)
  503. CD = math.abs(Cy - Dy)
  504. AD = math.abs(Ay - Dy)
  505.  
  506. _XB = math.abs(Xx - Bx)
  507. _BD = math.abs(Bx - Dx)
  508.  
  509. cond1 = BC / CD >= 0.518 and BC / CD <= 0.718 //best 0.618 (±0.1)
  510. cond2 = AB / BC >= 0.382 and AB / BC <= 0.886
  511. cond3 = XA / AB >= 1.272 and XA / AB <= 1.618
  512. cond4 = XC / CD >= 0.686 and XC / CD <= 0.886 //best 0.786 (±0.1)
  513. cond5 = XA / BC >= 0.800 and XA / BC <= 1.200 //best 1 (±0.2)
  514. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  515. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  516.  
  517. entry_price = Dy
  518. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  519. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  520. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  521.  
  522. coluor = Dd == 1 ? bearcolor : bullcolor
  523. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  524. name = "Anti-Gartlay " + (Dd == 1 ? "▼" : "▲")
  525. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  526. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  527.  
  528. [cond, -Dd, trendy]
  529.  
  530. //anti cypher pattern
  531. anti_cypher_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  532. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  533.  
  534. XA = math.abs(Xy - Ay)
  535. XC = math.abs(Xy - Cy)
  536. AB = math.abs(Ay - By)
  537. BC = math.abs(By - Cy)
  538. CD = math.abs(Cy - Dy)
  539. AD = math.abs(Ay - Dy)
  540.  
  541. _XB = math.abs(Xx - Bx)
  542. _BD = math.abs(Bx - Dx)
  543.  
  544. cond1 = BC / CD >= 0.382 and BC / CD <= 0.618
  545. cond2 = AD / CD >= 1.272 and AD / CD <= 1.414
  546. cond3 = XA / AD >= 0.686 and XA / AD <= 0.886 //best 0.786 (±0.1)
  547. cond4 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  548. cond = cond1 and cond2 and cond3 and cond4
  549.  
  550. entry_price = Dy
  551. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  552. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  553. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  554.  
  555. coluor = Dd == 1 ? bearcolor : bullcolor
  556. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  557. name = "Anti-Cypher " + (Dd == 1 ? "▼" : "▲")
  558. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  559. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  560.  
  561. [cond, -Dd, trendy]
  562.  
  563. //anti_bat pattern
  564. anti_bat_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  565. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  566.  
  567. XA = math.abs(Xy - Ay)
  568. XC = math.abs(Xy - Cy)
  569. AB = math.abs(Ay - By)
  570. BC = math.abs(By - Cy)
  571. CD = math.abs(Cy - Dy)
  572. AD = math.abs(Ay - Dy)
  573.  
  574. _XB = math.abs(Xx - Bx)
  575. _BD = math.abs(Bx - Dx)
  576.  
  577. cond1 = BC / CD >= 0.382 and BC / CD <= 0.500
  578. cond2 = AB / BC >= 0.382 and AB / BC <= 0.886
  579. cond3 = XA / AB >= 1.618 and XA / AB <= 2.618
  580. cond4 = XC / CD >= 0.786 and XC / CD <= 0.986 //best 0.886 (±0.1)
  581. cond5 = XA / BC >= 1.072 and XA / BC <= 1.472 //best 1.272 (±0.2)
  582. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  583. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  584.  
  585. entry_price = Dy
  586. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  587. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  588. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  589.  
  590. coluor = Dd == 1 ? bearcolor : bullcolor
  591. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  592. name = "Anti-Bat " + (Dd == 1 ? "▼" : "▲")
  593. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  594. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  595.  
  596. [cond, -Dd, trendy]
  597.  
  598. //anti crab pattern
  599. anti_crab_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  600. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  601.  
  602. XA = math.abs(Xy - Ay)
  603. XC = math.abs(Xy - Cy)
  604. AB = math.abs(Ay - By)
  605. BC = math.abs(By - Cy)
  606. CD = math.abs(Cy - Dy)
  607. AD = math.abs(Ay - Dy)
  608.  
  609. _XB = math.abs(Xx - Bx)
  610. _BD = math.abs(Bx - Dx)
  611.  
  612. cond1 = BC / CD >= 0.382 and BC / CD <= 0.618
  613. cond2 = AB / BC >= 0.382 and AB / BC <= 0.886
  614. cond3 = XA / AB >= 2.242 and XA / AB <= 3.618
  615. cond4 = XC / CD >= 1.518 and XC / CD <= 1.718 //best 1.618 (±0.1)
  616. cond5 = XA / BC >= 1.072 and XA / BC <= 1.818 //best 1.272-1.618 (±0.2)
  617. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  618. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  619.  
  620. entry_price = Dy
  621. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  622. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  623. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  624.  
  625. coluor = Dd == 1 ? bearcolor : bullcolor
  626. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  627. name = "Anti-Crab " + (Dd == 1 ? "▼" : "▲")
  628. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  629. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  630.  
  631. [cond, -Dd, trendy]
  632.  
  633. //anti butterfly pattern
  634. anti_butterfly_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  635. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  636.  
  637. XA = math.abs(Xy - Ay)
  638. XC = math.abs(Xy - Cy)
  639. AB = math.abs(Ay - By)
  640. BC = math.abs(By - Cy)
  641. CD = math.abs(Cy - Dy)
  642. AD = math.abs(Ay - Dy)
  643.  
  644. _XB = math.abs(Xx - Bx)
  645. _BD = math.abs(Bx - Dx)
  646.  
  647. cond1 = BC / CD >= 0.686 and BC / CD <= 0.886 //best 0.786 (±0.1)
  648. cond2 = AB / BC >= 0.382 and AB / BC <= 0.886
  649. cond3 = XA / AB >= 1.618 and XA / AB <= 2.618
  650. cond4 = XC / CD >= 1.272 and XC / CD <= 1.618
  651. cond5 = XA / BC >= 0.800 and XA / BC <= 1.472 //best 1-1.272 (±0.2)
  652. cond6 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  653. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  654.  
  655. entry_price = Dy
  656. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  657. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  658. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  659.  
  660. coluor = Dd == 1 ? bearcolor : bullcolor
  661. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  662. name = "Anti-Butterfly " + (Dd == 1 ? "▼" : "▲")
  663. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  664. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  665.  
  666. [cond, -Dd, trendy]
  667.  
  668. //anti shark pattern
  669. anti_shark_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  670. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  671.  
  672. XA = math.abs(Xy - Ay)
  673. XC = math.abs(Xy - Cy)
  674. AB = math.abs(Ay - By)
  675. BC = math.abs(By - Cy)
  676. CD = math.abs(Cy - Dy)
  677. AD = math.abs(Ay - Dy)
  678.  
  679. _XB = math.abs(Xx - Bx)
  680. _BD = math.abs(Bx - Dx)
  681.  
  682. cond1 = BC / CD >= 0.382 and BC / CD <= 0.618
  683. cond2 = AB / BC >= 1.130 and AB / BC <= 1.618
  684. cond3 = XA / AB >= 1.618 and XA / AB <= 2.240
  685. cond4 = XA / AD >= 0.886 and XA / AD <= 1.130
  686. cond5 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  687. cond = cond1 and cond2 and cond3 and cond4 and cond5
  688.  
  689. entry_price = Dy
  690. stop_loss = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? 1 : -1))
  691. take_profit1 = math.round_to_mintick(Dy + AD * 0.382 * (Dd == 1 ? -1 : 1))
  692. take_profit2 = math.round_to_mintick(Dy + AD * 0.618 * (Dd == 1 ? -1 : 1))
  693.  
  694. coluor = Dd == 1 ? bearcolor : bullcolor
  695. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  696. name = "Anti-Shark " + (Dd == 1 ? "▼" : "▲")
  697. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  698. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  699.  
  700. [cond, -Dd, trendy]
  701.  
  702. //black swan pattern
  703. black_swan_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  704. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  705.  
  706. XA = math.abs(Xy - Ay)
  707. XB = math.abs(Xy - By)
  708. XC = math.abs(Xy - Cy)
  709. XD = math.abs(Xy - Dy)
  710. AB = math.abs(Ay - By)
  711. BC = math.abs(By - Cy)
  712. CD = math.abs(Cy - Dy)
  713. AD = math.abs(Ay - Dy)
  714.  
  715. _XB = math.abs(Xx - Bx)
  716. _XD = math.abs(Xx - Dx)
  717. _BD = math.abs(Bx - Dx)
  718.  
  719. cond1 = AB / XA >= 0.382 and AB / XA <= 0.724
  720. cond2 = BC / AB >= 2.000 and BC / AB <= 4.237
  721. cond3 = CD / BC >= 0.500 and CD / BC <= 0.886
  722. cond4 = CD / XC >= 0.382 and CD / XC <= 0.886
  723. cond5 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  724. cond6 = XB / _XB >= XD / _XD
  725. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  726.  
  727. entry_price = Dy
  728. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  729. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  730. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  731.  
  732. coluor = Dd == 1 ? bearcolor : bullcolor
  733. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  734. name = "Black-Swan " + (Dd == 1 ? "▼" : "▲")
  735. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  736. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  737.  
  738. [cond, -Dd, trendy]
  739.  
  740. //white swan pattern
  741. white_swan_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  742. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  743.  
  744. XA = math.abs(Xy - Ay)
  745. XB = math.abs(Xy - By)
  746. XC = math.abs(Xy - Cy)
  747. XD = math.abs(Xy - Dy)
  748. AB = math.abs(Ay - By)
  749. BC = math.abs(By - Cy)
  750. CD = math.abs(Cy - Dy)
  751. AD = math.abs(Ay - Dy)
  752.  
  753. _XB = math.abs(Xx - Bx)
  754. _XD = math.abs(Xx - Dx)
  755. _BD = math.abs(Bx - Dx)
  756.  
  757. cond1 = AB / XA >= 1.382 and AB / XA <= 2.618
  758. cond2 = BC / AB >= 0.236 and BC / AB <= 0.500
  759. cond3 = CD / BC >= 1.128 and CD / BC <= 2.000
  760. cond4 = AD / XA >= 1.128 and AD / XA <= 2.618
  761. cond5 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  762. cond6 = XB / _XB <= XD / _XD
  763. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  764.  
  765. entry_price = Dy
  766. stop_loss = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? 1 : -1))
  767. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  768. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  769.  
  770. coluor = Dd == 1 ? bearcolor : bullcolor
  771. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  772. name = "White-Swan " + (Dd == 1 ? "▼" : "▲")
  773. draw_harmonic_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  774. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  775.  
  776. [cond, -Dd, trendy]
  777.  
  778.  
  779. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  780. // 0-5 Harmonic Pattern Functions ------------------------------------------------------------------ //
  781.  
  782. //draw 0-5 pattern
  783. draw_05_pattern(draw, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  784. var line line_ZX = na
  785. var line line_XA = na
  786. var line line_AB = na
  787. var line line_XB = na
  788. var line line_BC = na
  789. var line line_CD = na
  790. var line line_BD = na
  791. var line line_ZA = na
  792. var line line_AC = na
  793.  
  794. var label label_Z = na
  795. var label label_X = na
  796. var label label_A = na
  797. var label label_B = na
  798. var label label_C = na
  799. var label label_D = na
  800.  
  801. var label label_ZA = na
  802. var label label_XB = na
  803. var label label_BD = na
  804. var label label_AC = na
  805.  
  806. if draw
  807. line.delete(line_ZX)
  808. line.delete(line_XA)
  809. line.delete(line_AB)
  810. line.delete(line_XB)
  811. line.delete(line_BC)
  812. line.delete(line_CD)
  813. line.delete(line_BD)
  814. line.delete(line_ZA)
  815. line.delete(line_AC)
  816.  
  817. label.delete(label_Z)
  818. label.delete(label_X)
  819. label.delete(label_A)
  820. label.delete(label_B)
  821. label.delete(label_C)
  822. label.delete(label_D)
  823.  
  824. label.delete(label_ZA)
  825. label.delete(label_XB)
  826. label.delete(label_BD)
  827. label.delete(label_AC)
  828.  
  829. duration = ((Dx - Zx) * timeframe.multiplier) / (60.0 * 24.0)
  830. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  831.  
  832. line_ZX := line.new(x1=Zx, y1=Zy, x2=Xx, y2=Xy, color=color.new(coluor, 30), width=2, style=line.style_dotted)
  833. line_XA := line.new(x1=Xx, y1=Xy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=2)
  834. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  835. line_XB := line.new(x1=Xx, y1=Xy, x2=Bx, y2=By, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  836. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  837. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  838. line_BD := line.new(x1=Bx, y1=By, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  839. line_ZA := line.new(x1=Zx, y1=Zy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  840. line_AC := line.new(x1=Ax, y1=Ay, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  841. linefill.new(line_XA, line_XB, color=color.new(coluor, 80))
  842. linefill.new(line_BC, line_BD, color=color.new(coluor, 80))
  843.  
  844. label_Z := label.new(x=Zx, y=Zy, text="0", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  845. label_X := label.new(x=Xx, y=Xy, text="X", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  846. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  847. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  848. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  849. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  850.  
  851. ZX = math.abs(Zy - Xy)
  852. XA = math.abs(Xy - Ay)
  853. AB = math.abs(Ay - By)
  854. BC = math.abs(By - Cy)
  855. CD = math.abs(Cy - Dy)
  856. label_ZA := label.new(x=int((Zx + Ax) / 2), y=(Zy + Ay) / 2, text=str.tostring(XA / ZX, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  857. label_XB := label.new(x=int((Xx + Bx) / 2), y=(Xy + By) / 2, text=str.tostring(AB / XA, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  858. label_BD := label.new(x=int((Bx + Dx) / 2), y=(By + Dy) / 2, text=str.tostring(CD / BC, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  859. label_AC := label.new(x=int((Ax + Cx) / 2), y=(Ay + Cy) / 2, text=str.tostring(BC / AB, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  860. 0
  861. else
  862. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  863. line.delete(line_ZX)
  864. line.delete(line_XA)
  865. line.delete(line_AB)
  866. line.delete(line_XB)
  867. line.delete(line_BC)
  868. line.delete(line_CD)
  869. line.delete(line_BD)
  870. line.delete(line_ZA)
  871. line.delete(line_AC)
  872.  
  873. label.delete(label_Z)
  874. label.delete(label_X)
  875. label.delete(label_A)
  876. label.delete(label_B)
  877. label.delete(label_C)
  878. label.delete(label_D)
  879.  
  880. label.delete(label_ZA)
  881. label.delete(label_XB)
  882. label.delete(label_BD)
  883. label.delete(label_AC)
  884. 0
  885.  
  886. //get 6-points
  887. get_6_points(zigzag, oldzigzag, zigzagdir, confirm) =>
  888. if array.size(zigzag) >= 12 and ta.barssince(is_newzigzag(zigzag, oldzigzag)) == confirm
  889. Zx = math.round(array.get(zigzag, 11))
  890. Zy = array.get(zigzag, 10)
  891. Zd = zigzagdir[bar_index - Zx]
  892.  
  893. Xx = math.round(array.get(zigzag, 9))
  894. Xy = array.get(zigzag, 8)
  895. Xd = zigzagdir[bar_index - Xx]
  896.  
  897. Ax = math.round(array.get(zigzag, 7))
  898. Ay = array.get(zigzag, 6)
  899. Ad = zigzagdir[bar_index - Ax]
  900.  
  901. Bx = math.round(array.get(zigzag, 5))
  902. By = array.get(zigzag, 4)
  903. Bd = zigzagdir[bar_index - Bx]
  904.  
  905. Cx = math.round(array.get(zigzag, 3))
  906. Cy = array.get(zigzag, 2)
  907. Cd = zigzagdir[bar_index - Cx]
  908.  
  909. Dx = math.round(array.get(zigzag, 1))
  910. Dy = array.get(zigzag, 0)
  911. Dd = zigzagdir[bar_index - Dx]
  912.  
  913. [Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd]
  914. else
  915. [na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na]
  916.  
  917. //0-5 Pattern
  918. zero5_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  919. [Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_6_points(zigzag, oldzigzag, zigzagdir, confirm)
  920.  
  921. ZX = math.abs(Zy - Xy)
  922. XA = math.abs(Xy - Ay)
  923. AB = math.abs(Ay - By)
  924. BC = math.abs(By - Cy)
  925. CD = math.abs(Cy - Dy)
  926. AD = math.abs(Ay - Dy)
  927.  
  928. cond1 = XA / ZX >= 0.130 and XA / ZX <= 0.618
  929. cond2 = AB / XA >= 1.130 and AB / XA <= 1.618
  930. cond3 = BC / AB >= 1.618 and BC / AB <= 2.24
  931. cond4 = CD / BC >= 0.400 and CD / BC <= 0.600 // best 0.5(±0.1)
  932. cond5 = CD / AB >= 0.800 and CD / AB <= 1.200 // best 1(±0.2)
  933. cond = cond1 and cond2 and cond3 and cond4 and cond5
  934.  
  935. entry_price = Dy
  936. stop_loss = math.round_to_mintick(Cy + BC * 0.782 * (Dd == 1 ? 1 : -1))
  937. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  938. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  939.  
  940. coluor = Dd == 1 ? bearcolor : bullcolor
  941. trendy = Dd == 1 ? Xy > Dy : Xy < Dy
  942. name = "0-5 " + (Dd == 1 ? "▼" : "▲")
  943. draw_05_pattern(cond and show_pattern, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  944. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  945.  
  946. [cond, -Dd, trendy]
  947.  
  948.  
  949. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  950. // AB=CD Pattern Functions ---------------------------------------------------------------------- //
  951.  
  952. //draw abcd pattern
  953. draw_abcd_pattern(draw, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  954. var line line_AB = na
  955. var line line_BC = na
  956. var line line_CD = na
  957. var line line_BD = na
  958. var line line_AC = na
  959.  
  960. var label label_A = na
  961. var label label_B = na
  962. var label label_C = na
  963. var label label_D = na
  964.  
  965. var label label_BD = na
  966. var label label_AC = na
  967.  
  968. if draw
  969. line.delete(line_AB)
  970. line.delete(line_BC)
  971. line.delete(line_CD)
  972. line.delete(line_BD)
  973. line.delete(line_AC)
  974.  
  975. label.delete(label_A)
  976. label.delete(label_B)
  977. label.delete(label_C)
  978. label.delete(label_D)
  979.  
  980. label.delete(label_BD)
  981. label.delete(label_AC)
  982.  
  983. duration = ((Dx - Ax) * timeframe.multiplier) / (60.0 * 24.0)
  984. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  985.  
  986. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  987. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  988. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  989. line_BD := line.new(x1=Bx, y1=By, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  990. line_AC := line.new(x1=Ax, y1=Ay, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  991.  
  992. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  993. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  994. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  995. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10))
  996.  
  997. AB = math.abs(Ay - By)
  998. BC = math.abs(By - Cy)
  999. CD = math.abs(Cy - Dy)
  1000. label_BD := label.new(x=int((Bx + Dx) / 2), y=(By + Dy) / 2, text=str.tostring(CD / BC, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1001. label_AC := label.new(x=int((Ax + Cx) / 2), y=(Ay + Cy) / 2, text=str.tostring(BC / AB, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1002. 0
  1003. else
  1004. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  1005. line.delete(line_AB)
  1006. line.delete(line_BC)
  1007. line.delete(line_CD)
  1008. line.delete(line_BD)
  1009. line.delete(line_AC)
  1010.  
  1011. label.delete(label_A)
  1012. label.delete(label_B)
  1013. label.delete(label_C)
  1014. label.delete(label_D)
  1015.  
  1016. label.delete(label_BD)
  1017. label.delete(label_AC)
  1018. 0
  1019.  
  1020. //get 4-points
  1021. get_4_points(zigzag, oldzigzag, zigzagdir, confirm) =>
  1022. if array.size(zigzag) >= 8 and ta.barssince(is_newzigzag(zigzag, oldzigzag)) == confirm
  1023. Ax = math.round(array.get(zigzag, 7))
  1024. Ay = array.get(zigzag, 6)
  1025. Ad = zigzagdir[bar_index - Ax]
  1026.  
  1027. Bx = math.round(array.get(zigzag, 5))
  1028. By = array.get(zigzag, 4)
  1029. Bd = zigzagdir[bar_index - Bx]
  1030.  
  1031. Cx = math.round(array.get(zigzag, 3))
  1032. Cy = array.get(zigzag, 2)
  1033. Cd = zigzagdir[bar_index - Cx]
  1034.  
  1035. Dx = math.round(array.get(zigzag, 1))
  1036. Dy = array.get(zigzag, 0)
  1037. Dd = zigzagdir[bar_index - Dx]
  1038.  
  1039. [Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd]
  1040. else
  1041. [na, na, na, na, na, na, na, na, na, na, na, na]
  1042.  
  1043. //AB=CD Pattern
  1044. abcd_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1045. [Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_4_points(zigzag, oldzigzag, zigzagdir, confirm)
  1046.  
  1047. AB = math.abs(Ay - By)
  1048. BC = math.abs(By - Cy)
  1049. CD = math.abs(Cy - Dy)
  1050.  
  1051. _AB = math.abs(Ax - Bx)
  1052. _CD = math.abs(Cx - Dx)
  1053.  
  1054. cond1 = BC / AB >= 0.518 and BC / AB <= 0.718 // best 0.618(±0.1)
  1055. cond2 = CD / BC >= 1.518 and CD / BC <= 1.718 // best 1.618(±0.1)
  1056. cond3 = CD / AB >= 0.800 and CD / AB <= 1.200 // best 1(±0.2)
  1057. cond4 = _CD / _AB >= 0.800 and _CD / _AB <= 1.200 // best 1(±0.2)
  1058. cond = cond1 and cond2 and cond3 and cond4
  1059.  
  1060. entry_price = Dy
  1061. stop_loss = math.round_to_mintick(By + BC * 1.000 * (Dd == 1 ? 1 : -1))
  1062. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  1063. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  1064.  
  1065. coluor = Dd == 1 ? bearcolor : bullcolor
  1066. trendy = false
  1067. name = "AB=CD " + (Dd == 1 ? "▼" : "▲")
  1068. draw_abcd_pattern(cond and show_pattern, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1069. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1070.  
  1071. [cond, -Dd, trendy]
  1072.  
  1073.  
  1074. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1075. // 3-Drives Pattern Functions ---------------------------------------------------------------------- //
  1076.  
  1077. //draw 3-Drives pattern
  1078. draw_threedrives_pattern(draw, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  1079. var line line_ZX = na
  1080. var line line_XA = na
  1081. var line line_AB = na
  1082. var line line_XB = na
  1083. var line line_BC = na
  1084. var line line_CD = na
  1085. var line line_BD = na
  1086. var line line_ZA = na
  1087. var line line_AC = na
  1088.  
  1089. var label label_Z = na
  1090. var label label_X = na
  1091. var label label_A = na
  1092. var label label_B = na
  1093. var label label_C = na
  1094. var label label_D = na
  1095.  
  1096. var label label_ZA = na
  1097. var label label_XB = na
  1098. var label label_BD = na
  1099. var label label_AC = na
  1100.  
  1101. if draw
  1102. line.delete(line_ZX)
  1103. line.delete(line_XA)
  1104. line.delete(line_AB)
  1105. line.delete(line_XB)
  1106. line.delete(line_BC)
  1107. line.delete(line_CD)
  1108. line.delete(line_BD)
  1109. line.delete(line_ZA)
  1110. line.delete(line_AC)
  1111.  
  1112. label.delete(label_Z)
  1113. label.delete(label_X)
  1114. label.delete(label_A)
  1115. label.delete(label_B)
  1116. label.delete(label_C)
  1117. label.delete(label_D)
  1118.  
  1119. label.delete(label_ZA)
  1120. label.delete(label_XB)
  1121. label.delete(label_BD)
  1122. label.delete(label_AC)
  1123.  
  1124. duration = ((Dx - Zx) * timeframe.multiplier) / (60.0 * 24.0)
  1125. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  1126.  
  1127. line_ZX := line.new(x1=Zx, y1=Zy, x2=Xx, y2=Xy, color=color.new(coluor, 30), width=2, style=line.style_dotted)
  1128. line_XA := line.new(x1=Xx, y1=Xy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=2)
  1129. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  1130. line_XB := line.new(x1=Xx, y1=Xy, x2=Bx, y2=By, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1131. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  1132. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  1133. line_BD := line.new(x1=Bx, y1=By, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1134. line_ZA := line.new(x1=Zx, y1=Zy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1135. line_AC := line.new(x1=Ax, y1=Ay, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1136.  
  1137. label_Z := label.new(x=Zx, y=Zy, text="0", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1138. label_X := label.new(x=Xx, y=Xy, text="X", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1139. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1140. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1141. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1142. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1143.  
  1144. ZX = math.abs(Zy - Xy)
  1145. XA = math.abs(Xy - Ay)
  1146. AB = math.abs(Ay - By)
  1147. BC = math.abs(By - Cy)
  1148. CD = math.abs(Cy - Dy)
  1149. label_ZA := label.new(x=int((Zx + Ax) / 2), y=(Zy + Ay) / 2, text=str.tostring(XA / ZX, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1150. label_XB := label.new(x=int((Xx + Bx) / 2), y=(Xy + By) / 2, text=str.tostring(AB / XA, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1151. label_BD := label.new(x=int((Bx + Dx) / 2), y=(By + Dy) / 2, text=str.tostring(CD / BC, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1152. label_AC := label.new(x=int((Ax + Cx) / 2), y=(Ay + Cy) / 2, text=str.tostring(BC / AB, "#.###"), style=label.style_label_center, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1153. 0
  1154. else
  1155. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  1156. line.delete(line_ZX)
  1157. line.delete(line_XA)
  1158. line.delete(line_AB)
  1159. line.delete(line_XB)
  1160. line.delete(line_BC)
  1161. line.delete(line_CD)
  1162. line.delete(line_BD)
  1163. line.delete(line_ZA)
  1164. line.delete(line_AC)
  1165.  
  1166. label.delete(label_Z)
  1167. label.delete(label_X)
  1168. label.delete(label_A)
  1169. label.delete(label_B)
  1170. label.delete(label_C)
  1171. label.delete(label_D)
  1172.  
  1173. label.delete(label_ZA)
  1174. label.delete(label_XB)
  1175. label.delete(label_BD)
  1176. label.delete(label_AC)
  1177. 0
  1178.  
  1179. //3-Drive Pattern
  1180. threedrives_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1181. [Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_6_points(zigzag, oldzigzag, zigzagdir, confirm)
  1182.  
  1183. ZX = math.abs(Zy - Xy)
  1184. XA = math.abs(Xy - Ay)
  1185. AB = math.abs(Ay - By)
  1186. BC = math.abs(By - Cy)
  1187. CD = math.abs(Cy - Dy)
  1188.  
  1189. _ZX = math.abs(Zx - Xx)
  1190. _AB = math.abs(Ax - Bx)
  1191. _CD = math.abs(Cx - Dx)
  1192.  
  1193. cond1 = XA / ZX >= 0.518 and XA / ZX <= 0.718 // best 0.618(±0.1)
  1194. cond2 = BC / AB >= 0.518 and BC / AB <= 0.718 // best 0.618(±0.1)
  1195. cond3 = AB / XA >= 1.518 and AB / XA <= 1.718 // best 1.618(±0.1)
  1196. cond4 = CD / BC >= 1.518 and CD / BC <= 1.718 // best 1.618(±0.1)
  1197. cond5 = AB / ZX >= 0.800 and AB / ZX <= 1.200 // best 1(±0.2)
  1198. cond6 = CD / AB >= 0.800 and CD / AB <= 1.200 // best 1(±0.2)
  1199. cond7 = _AB / _ZX >= 0.800 and _AB / _ZX <= 1.200 // best 1(±0.2)
  1200. cond8 = _CD / _AB >= 0.800 and _CD / _AB <= 1.200 // best 1(±0.2)
  1201. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6 and cond7 and cond8
  1202.  
  1203. entry_price = Dy
  1204. stop_loss = math.round_to_mintick(By + BC * 1.000 * (Dd == 1 ? 1 : -1))
  1205. take_profit1 = math.round_to_mintick(Dy + CD * 0.382 * (Dd == 1 ? -1 : 1))
  1206. take_profit2 = math.round_to_mintick(Dy + CD * 0.618 * (Dd == 1 ? -1 : 1))
  1207.  
  1208. coluor = Dd == 1 ? bearcolor : bullcolor
  1209. trendy = false
  1210. name = "Three-Drives " + (Dd == 1 ? "▼" : "▲")
  1211. draw_threedrives_pattern(cond and show_pattern, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1212. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1213.  
  1214. [cond, -Dd, trendy]
  1215.  
  1216.  
  1217. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1218. // Triangle Pattern Functions ---------------------------------------------------------------------- //
  1219.  
  1220. //draw triangle pattern
  1221. draw_triangle_pattern(draw, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  1222. var line line_ZX = na
  1223. var line line_XA = na
  1224. var line line_AB = na
  1225. var line line_BC = na
  1226. var line line_CD = na
  1227.  
  1228. var label label_Z = na
  1229. var label label_X = na
  1230. var label label_A = na
  1231. var label label_B = na
  1232. var label label_C = na
  1233. var label label_D = na
  1234.  
  1235. var line line_XN = na
  1236. var line line_MC = na
  1237.  
  1238. if draw
  1239. line.delete(line_ZX)
  1240. line.delete(line_XA)
  1241. line.delete(line_AB)
  1242. line.delete(line_BC)
  1243. line.delete(line_CD)
  1244.  
  1245. label.delete(label_Z)
  1246. label.delete(label_X)
  1247. label.delete(label_A)
  1248. label.delete(label_B)
  1249. label.delete(label_C)
  1250. label.delete(label_D)
  1251.  
  1252. line.delete(line_XN)
  1253. line.delete(line_MC)
  1254.  
  1255. duration = ((Dx - Zx) * timeframe.multiplier) / (60.0 * 24.0)
  1256. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  1257.  
  1258. line_ZX := line.new(x1=Zx, y1=Zy, x2=Xx, y2=Xy, color=color.new(coluor, 30), width=2)
  1259. line_XA := line.new(x1=Xx, y1=Xy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=2)
  1260. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  1261. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  1262. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  1263.  
  1264. label_Z := label.new(x=Zx, y=Zy, text="0", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1265. label_X := label.new(x=Xx, y=Xy, text="X", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1266. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1267. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1268. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1269. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1270.  
  1271. xb_a = (Xy - By) / (Xx - Bx)
  1272. xb_b = Xy - xb_a * Xx
  1273.  
  1274. ac_a = (Ay - Cy) / (Ax - Cx)
  1275. ac_b = Ay - ac_a * Ax
  1276.  
  1277. cd_a = (Cy - Dy) / (Cx - Dx)
  1278. cd_b = Cy - cd_a * Cx
  1279.  
  1280. zx_a = (Zy - Xy) / (Zx - Xx)
  1281. zx_b = Zy - zx_a * Zx
  1282.  
  1283. Mx = math.floor(-(zx_b - ac_b) / (zx_a - ac_a))
  1284. My = Mx * zx_a + zx_b
  1285.  
  1286. Nx = math.ceil(-(cd_b - xb_b) / (cd_a - xb_a))
  1287. Ny = Nx * cd_a + cd_b
  1288.  
  1289. line_XN := line.new(x1=Xx, y1=Xy, x2=Nx, y2=Ny, color=color.new(coluor, 30), width=2, style=line.style_dotted)
  1290. line_MC := line.new(x1=Mx, y1=My, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2, style=line.style_dotted)
  1291. linefill.new(line_XN, line_MC, color=color.new(coluor, 80))
  1292. 0
  1293. else
  1294. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  1295. line.delete(line_ZX)
  1296. line.delete(line_XA)
  1297. line.delete(line_AB)
  1298. line.delete(line_BC)
  1299. line.delete(line_CD)
  1300.  
  1301. label.delete(label_Z)
  1302. label.delete(label_X)
  1303. label.delete(label_A)
  1304. label.delete(label_B)
  1305. label.delete(label_C)
  1306. label.delete(label_D)
  1307.  
  1308. line.delete(line_XN)
  1309. line.delete(line_MC)
  1310. 0
  1311.  
  1312. //descending triangle
  1313. desc_triangle_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1314. [Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_6_points(zigzag, oldzigzag, zigzagdir, confirm)
  1315.  
  1316. ZX = math.abs(Zy - Xy)
  1317. XA = math.abs(Xy - Ay)
  1318. AB = math.abs(Ay - By)
  1319. BC = math.abs(By - Cy)
  1320. CD = math.abs(Cy - Dy)
  1321. AD = math.abs(Ay - Dy)
  1322.  
  1323. xb_a = (Xy - By) / (Xx - Bx)
  1324. xb_b = Xy - xb_a * Xx
  1325.  
  1326. ac_a = (Ay - Cy) / (Ax - Cx)
  1327. ac_b = Ay - ac_a * Ax
  1328.  
  1329. cd_a = (Cy - Dy) / (Cx - Dx)
  1330. cd_b = Cy - cd_a * Cx
  1331.  
  1332. zx_a = (Zy - Xy) / (Zx - Xx)
  1333. zx_b = Zy - zx_a * Zx
  1334.  
  1335. Mx = math.floor(-(zx_b - ac_b) / (zx_a - ac_a))
  1336. My = Mx * zx_a + zx_b
  1337.  
  1338. Nx = math.ceil(-(cd_b - xb_b) / (cd_a - xb_a))
  1339. Ny = Nx * cd_a + cd_b
  1340.  
  1341. cond = false
  1342. if Dd == 1
  1343. cond1 = XA / ZX >= 0.328 and XA / ZX <= 0.886
  1344. cond2 = AB / XA >= 0.618 and AB / XA <= 0.886
  1345. cond3 = BC / AB >= 1.130 and BC / AB <= 1.618
  1346. cond4 = CD / BC >= 1.242 and CD / BC <= 1.382
  1347. cond5 = Zy <= My and Dy >= Ny
  1348. cond6 = ac_a < 0 and xb_a < 0 and xb_a / ac_a > 1
  1349. cond := cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  1350. else
  1351. cond1 = XA / ZX >= 0.328 and XA / ZX <= 0.886
  1352. cond2 = AB / XA >= 1.130 and AB / XA <= 1.618
  1353. cond3 = BC / AB >= 0.618 and BC / AB <= 0.886
  1354. cond4 = CD / BC >= 1.242 and CD / BC <= 1.382
  1355. cond5 = Zy >= My and Dy <= Ny
  1356. cond6 = ac_a < 0 and xb_a < 0 and ac_a / xb_a > 1
  1357. cond := cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  1358.  
  1359. entry_price = math.round_to_mintick(Ny)
  1360. stop_loss = Cy
  1361. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1362. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1363.  
  1364. coluor = Dd == 1 ? bullcolor : bearcolor
  1365. trendy = Dd == 1 ? Cy > Zy : Dd == -1 ? Cy < Zy : false
  1366. name = "Descending-Triangle " + (Dd == 1 ? "▲" : "▼")
  1367. draw_triangle_pattern(cond and show_pattern, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1368. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1369.  
  1370. [cond, Dd, trendy]
  1371.  
  1372. //ascending triangle
  1373. asc_triangle_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1374. [Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_6_points(zigzag, oldzigzag, zigzagdir, confirm)
  1375.  
  1376. ZX = math.abs(Zy - Xy)
  1377. XA = math.abs(Xy - Ay)
  1378. AB = math.abs(Ay - By)
  1379. BC = math.abs(By - Cy)
  1380. CD = math.abs(Cy - Dy)
  1381. AD = math.abs(Ay - Dy)
  1382.  
  1383. xb_a = (Xy - By) / (Xx - Bx)
  1384. xb_b = Xy - xb_a * Xx
  1385.  
  1386. ac_a = (Ay - Cy) / (Ax - Cx)
  1387. ac_b = Ay - ac_a * Ax
  1388.  
  1389. cd_a = (Cy - Dy) / (Cx - Dx)
  1390. cd_b = Cy - cd_a * Cx
  1391.  
  1392. zx_a = (Zy - Xy) / (Zx - Xx)
  1393. zx_b = Zy - zx_a * Zx
  1394.  
  1395. Mx = math.floor(-(zx_b - ac_b) / (zx_a - ac_a))
  1396. My = Mx * zx_a + zx_b
  1397.  
  1398. Nx = math.ceil(-(cd_b - xb_b) / (cd_a - xb_a))
  1399. Ny = Nx * cd_a + cd_b
  1400.  
  1401. cond = false
  1402. if Dd == 1
  1403. cond1 = XA / ZX >= 0.328 and XA / ZX <= 0.886
  1404. cond2 = AB / XA >= 1.130 and AB / XA <= 1.618
  1405. cond3 = BC / AB >= 0.618 and BC / AB <= 0.886
  1406. cond4 = CD / BC >= 1.242 and CD / BC <= 1.382
  1407. cond5 = Zy <= My and Dy >= Ny
  1408. cond6 = ac_a > 0 and xb_a > 0 and xb_a / ac_a < 1
  1409. cond := cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  1410. else
  1411. cond1 = XA / ZX >= 0.328 and XA / ZX <= 0.886
  1412. cond2 = AB / XA >= 0.618 and AB / XA <= 0.886
  1413. cond3 = BC / AB >= 1.130 and BC / AB <= 1.618
  1414. cond4 = CD / BC >= 1.242 and CD / BC <= 1.382
  1415. cond5 = Zy >= My and Dy <= Ny
  1416. cond6 = ac_a > 0 and xb_a > 0 and ac_a / xb_a < 1
  1417. cond := cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  1418.  
  1419. entry_price = math.round_to_mintick(Ny)
  1420. stop_loss = Cy
  1421. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1422. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1423.  
  1424. coluor = Dd == 1 ? bullcolor : bearcolor
  1425. trendy = Dd == 1 ? Cy > Zy : Dd == -1 ? Cy < Zy : false
  1426. name = "Ascending-Triangle " + (Dd == 1 ? "▲" : "▼")
  1427. draw_triangle_pattern(cond and show_pattern, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1428. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1429.  
  1430. [cond, Dd, trendy]
  1431.  
  1432. //symmetrical triangle
  1433. sym_triangle_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1434. [Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_6_points(zigzag, oldzigzag, zigzagdir, confirm)
  1435.  
  1436. ZX = math.abs(Zy - Xy)
  1437. XA = math.abs(Xy - Ay)
  1438. AB = math.abs(Ay - By)
  1439. BC = math.abs(By - Cy)
  1440. CD = math.abs(Cy - Dy)
  1441. AD = math.abs(Ay - Dy)
  1442.  
  1443. xb_a = (Xy - By) / (Xx - Bx)
  1444. xb_b = Xy - xb_a * Xx
  1445.  
  1446. ac_a = (Ay - Cy) / (Ax - Cx)
  1447. ac_b = Ay - ac_a * Ax
  1448.  
  1449. cd_a = (Cy - Dy) / (Cx - Dx)
  1450. cd_b = Cy - cd_a * Cx
  1451.  
  1452. zx_a = (Zy - Xy) / (Zx - Xx)
  1453. zx_b = Zy - zx_a * Zx
  1454.  
  1455. Mx = math.floor(-(zx_b - ac_b) / (zx_a - ac_a))
  1456. My = Mx * zx_a + zx_b
  1457.  
  1458. Nx = math.ceil(-(cd_b - xb_b) / (cd_a - xb_a))
  1459. Ny = Nx * cd_a + cd_b
  1460.  
  1461. cond1 = XA / ZX >= 0.328 and XA / ZX <= 0.886
  1462. cond2 = AB / XA >= 0.618 and AB / XA <= 0.886
  1463. cond3 = BC / AB >= 0.618 and BC / AB <= 0.886
  1464. cond4 = CD / BC >= 1.242 and CD / BC <= 1.382
  1465. cond5 = ac_a * xb_a < 0
  1466. cond6 = Dd == 1 ? Zy <= My : Zy >= My
  1467. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6
  1468.  
  1469. entry_price = math.round_to_mintick(Ny)
  1470. stop_loss = Cy
  1471. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1472. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1473.  
  1474. coluor = Dd == 1 ? bullcolor : bearcolor
  1475. trendy = true
  1476. name = "Symmetrical-Triangle " + (Dd == 1 ? "▲" : "▼")
  1477. draw_triangle_pattern(cond and show_pattern, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1478. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1479.  
  1480. [cond, Dd, trendy]
  1481.  
  1482.  
  1483. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1484. // Header&Shoulders Functions ---------------------------------------------------------------------- //
  1485.  
  1486. //draw header&shoulder pattern
  1487. draw_hs_pattern(draw, Sx, Sy, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  1488. var line line_SZ = na
  1489. var line line_ZX = na
  1490. var line line_XA = na
  1491. var line line_AB = na
  1492. var line line_BC = na
  1493. var line line_CD = na
  1494. var line line_XB = na
  1495. var line line_MX = na
  1496. var line line_BN = na
  1497.  
  1498. var label label_S = na
  1499. var label label_Z = na
  1500. var label label_X = na
  1501. var label label_A = na
  1502. var label label_B = na
  1503. var label label_C = na
  1504. var label label_D = na
  1505.  
  1506. if draw
  1507. line.delete(line_SZ)
  1508. line.delete(line_ZX)
  1509. line.delete(line_XA)
  1510. line.delete(line_AB)
  1511. line.delete(line_BC)
  1512. line.delete(line_CD)
  1513. line.delete(line_XB)
  1514. line.delete(line_MX)
  1515. line.delete(line_BN)
  1516.  
  1517. label.delete(label_S)
  1518. label.delete(label_Z)
  1519. label.delete(label_X)
  1520. label.delete(label_A)
  1521. label.delete(label_B)
  1522. label.delete(label_C)
  1523. label.delete(label_D)
  1524.  
  1525. duration = ((Dx - Sx) * timeframe.multiplier) / (60.0 * 24.0)
  1526. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  1527.  
  1528. line_SZ := line.new(x1=Sx, y1=Sy, x2=Zx, y2=Zy, color=color.new(coluor, 30), width=2)
  1529. line_ZX := line.new(x1=Zx, y1=Zy, x2=Xx, y2=Xy, color=color.new(coluor, 30), width=2)
  1530. line_XA := line.new(x1=Xx, y1=Xy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=2)
  1531. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  1532. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  1533. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  1534.  
  1535. label_S := label.new(x=Sx, y=Sy, text="S", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1536. label_Z := label.new(x=Zx, y=Zy, text="0", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1537. label_X := label.new(x=Xx, y=Xy, text="X", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1538. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1539. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1540. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1541. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1542.  
  1543. xb_a = (Xy - By) / (Xx - Bx)
  1544. xb_b = Xy - xb_a * Xx
  1545.  
  1546. sz_a = (Sy - Zy) / (Sx - Zx)
  1547. sz_b = Sy - sz_a * Sx
  1548.  
  1549. cd_a = (Cy - Dy) / (Cx - Dx)
  1550. cd_b = Cy - cd_a * Cx
  1551.  
  1552. Mx = math.floor(-(xb_b - sz_b) / (xb_a - sz_a))
  1553. My = Mx * xb_a + xb_b
  1554.  
  1555. Nx = math.ceil(-(xb_b - cd_b) / (xb_a - cd_a))
  1556. Ny = Nx * xb_a + xb_b
  1557.  
  1558. line_XB := line.new(x1=Xx, y1=Xy, x2=Bx, y2=By, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1559. line_MX := line.new(x1=Mx, y1=My, x2=Xx, y2=Xy, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1560. line_BN := line.new(x1=Bx, y1=By, x2=Nx, y2=Ny, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1561. linefill.new(line_SZ, line_MX, color=color.new(coluor, 80))
  1562. linefill.new(line_XA, line_XB, color=color.new(coluor, 80))
  1563. linefill.new(line_BC, line_BN, color=color.new(coluor, 80))
  1564. 0
  1565. else
  1566. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  1567. line.delete(line_SZ)
  1568. line.delete(line_ZX)
  1569. line.delete(line_XA)
  1570. line.delete(line_AB)
  1571. line.delete(line_BC)
  1572. line.delete(line_CD)
  1573. line.delete(line_XB)
  1574. line.delete(line_MX)
  1575. line.delete(line_BN)
  1576.  
  1577. label.delete(label_S)
  1578. label.delete(label_Z)
  1579. label.delete(label_X)
  1580. label.delete(label_A)
  1581. label.delete(label_B)
  1582. label.delete(label_C)
  1583. label.delete(label_D)
  1584. 0
  1585.  
  1586. //get 7-points
  1587. get_7_points(zigzag, oldzigzag, zigzagdir, confirm) =>
  1588. if array.size(zigzag) >= 14 and ta.barssince(is_newzigzag(zigzag, oldzigzag)) == confirm
  1589. Sx = math.round(array.get(zigzag, 13))
  1590. Sy = array.get(zigzag, 12)
  1591. Sd = zigzagdir[bar_index - Sx]
  1592.  
  1593. Zx = math.round(array.get(zigzag, 11))
  1594. Zy = array.get(zigzag, 10)
  1595. Zd = zigzagdir[bar_index - Zx]
  1596.  
  1597. Xx = math.round(array.get(zigzag, 9))
  1598. Xy = array.get(zigzag, 8)
  1599. Xd = zigzagdir[bar_index - Xx]
  1600.  
  1601. Ax = math.round(array.get(zigzag, 7))
  1602. Ay = array.get(zigzag, 6)
  1603. Ad = zigzagdir[bar_index - Ax]
  1604.  
  1605. Bx = math.round(array.get(zigzag, 5))
  1606. By = array.get(zigzag, 4)
  1607. Bd = zigzagdir[bar_index - Bx]
  1608.  
  1609. Cx = math.round(array.get(zigzag, 3))
  1610. Cy = array.get(zigzag, 2)
  1611. Cd = zigzagdir[bar_index - Cx]
  1612.  
  1613. Dx = math.round(array.get(zigzag, 1))
  1614. Dy = array.get(zigzag, 0)
  1615. Dd = zigzagdir[bar_index - Dx]
  1616.  
  1617. [Sx, Sy, Sd, Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd]
  1618. else
  1619. [na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na, na]
  1620.  
  1621. //header and shoulder pattern
  1622. norm_hs_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1623. [Sx, Sy, Sd, Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_7_points(zigzag, oldzigzag, zigzagdir, confirm)
  1624.  
  1625. ZX = math.abs(Zy - Xy)
  1626. XA = math.abs(Xy - Ay)
  1627. AB = math.abs(Ay - By)
  1628. BC = math.abs(By - Cy)
  1629. CD = math.abs(Cy - Dy)
  1630. ZB = math.abs(Zy - By)
  1631. XC = math.abs(Xy - Cy)
  1632.  
  1633. xb_a = (Xy - By) / (Xx - Bx)
  1634. xb_b = Xy - xb_a * Xx
  1635.  
  1636. sz_a = (Sy - Zy) / (Sx - Zx)
  1637. sz_b = Sy - sz_a * Sx
  1638.  
  1639. cd_a = (Cy - Dy) / (Cx - Dx)
  1640. cd_b = Cy - cd_a * Cx
  1641.  
  1642. Mx = math.floor(-(xb_b - sz_b) / (xb_a - sz_a))
  1643. My = Mx * xb_a + xb_b
  1644.  
  1645. Nx = math.ceil(-(xb_b - cd_b) / (xb_a - cd_a))
  1646. Ny = Nx * xb_a + xb_b
  1647.  
  1648. cond1 = XA / ZX >= 1.272 and XA / ZX <= 2.618
  1649. cond2 = ZB / ZX >= 0.786 and ZB / ZX <= 1.272
  1650. cond3 = AB / BC >= 1.272 and AB / BC <= 2.618
  1651. cond4 = XC / BC >= 0.786 and XC / BC <= 1.272
  1652. cond5 = CD / BC >= 1.242 and CD / BC <= 1.382
  1653. cond6 = Dd == -1
  1654. cond7 = Mx >= Sx and My >= Sy
  1655. cond8 = Nx <= Dx and Ny >= Dy
  1656. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6 and cond7 and cond8
  1657.  
  1658. entry_price = math.round_to_mintick(Ny)
  1659. stop_loss = Cy
  1660. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1661. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1662.  
  1663. coluor = bearcolor
  1664. trendy = true
  1665. name = "Header&Shoulder ▼"
  1666. draw_hs_pattern(cond and show_pattern, Sx, Sy, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1667. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1668.  
  1669. [cond, Dd, trendy]
  1670.  
  1671. //header and shoulder pattern
  1672. inve_hs_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1673. [Sx, Sy, Sd, Zx, Zy, Zd, Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_7_points(zigzag, oldzigzag, zigzagdir, confirm)
  1674.  
  1675. ZX = math.abs(Zy - Xy)
  1676. XA = math.abs(Xy - Ay)
  1677. AB = math.abs(Ay - By)
  1678. BC = math.abs(By - Cy)
  1679. CD = math.abs(Cy - Dy)
  1680. ZB = math.abs(Zy - By)
  1681. XC = math.abs(Xy - Cy)
  1682.  
  1683. xb_a = (Xy - By) / (Xx - Bx)
  1684. xb_b = Xy - xb_a * Xx
  1685.  
  1686. sz_a = (Sy - Zy) / (Sx - Zx)
  1687. sz_b = Sy - sz_a * Sx
  1688.  
  1689. cd_a = (Cy - Dy) / (Cx - Dx)
  1690. cd_b = Cy - cd_a * Cx
  1691.  
  1692. Mx = math.floor(-(xb_b - sz_b) / (xb_a - sz_a))
  1693. My = Mx * xb_a + xb_b
  1694.  
  1695. Nx = math.ceil(-(xb_b - cd_b) / (xb_a - cd_a))
  1696. Ny = Nx * xb_a + xb_b
  1697.  
  1698. cond1 = XA / ZX >= 1.272 and XA / ZX <= 2.618
  1699. cond2 = ZB / ZX >= 0.786 and ZB / ZX <= 1.272
  1700. cond3 = AB / BC >= 1.272 and AB / BC <= 2.618
  1701. cond4 = XC / BC >= 0.786 and XC / BC <= 1.272
  1702. cond5 = CD / BC >= 1.242 and CD / BC <= 1.382
  1703. cond6 = Dd == 1
  1704. cond7 = Mx >= Sx and My <= Sy
  1705. cond8 = Nx <= Dx and Ny <= Dy
  1706. cond = cond1 and cond2 and cond3 and cond4 and cond5 and cond6 and cond7 and cond8
  1707.  
  1708. entry_price = math.round_to_mintick(Ny)
  1709. stop_loss = Cy
  1710. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1711. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1712.  
  1713. coluor = bullcolor
  1714. trendy = true
  1715. name = "Inverse-Header&Shoulder ▲"
  1716. draw_hs_pattern(cond and show_pattern, Sx, Sy, Zx, Zy, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1717. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1718.  
  1719. [cond, Dd, trendy]
  1720.  
  1721.  
  1722. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1723. // Double-top/bottom Pattern Functions ------------------------------------------------------------- //
  1724.  
  1725. //draw double top/btm pattern
  1726. draw_double_top_btm_pattern(draw, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor) =>
  1727. var line line_XA = na
  1728. var line line_AB = na
  1729. var line line_BC = na
  1730. var line line_CD = na
  1731. var line line_MB = na
  1732. var line line_BN = na
  1733.  
  1734. var label label_X = na
  1735. var label label_A = na
  1736. var label label_B = na
  1737. var label label_C = na
  1738. var label label_D = na
  1739.  
  1740. if draw
  1741. line.delete(line_XA)
  1742. line.delete(line_AB)
  1743. line.delete(line_BC)
  1744. line.delete(line_CD)
  1745. line.delete(line_MB)
  1746. line.delete(line_BN)
  1747.  
  1748. label.delete(label_X)
  1749. label.delete(label_A)
  1750. label.delete(label_B)
  1751. label.delete(label_C)
  1752. label.delete(label_D)
  1753.  
  1754. duration = ((Dx - Xx) * timeframe.multiplier) / (60.0 * 24.0)
  1755. tooltip = "timeframe: " + reso + "\n" + "pattern: " + name + "\n" + "duration: " + str.tostring(duration, "#.###") + " Day" + "\n" + "trendy: " + (trendy ? "true" : "false") + "\n"
  1756.  
  1757. line_XA := line.new(x1=Xx, y1=Xy, x2=Ax, y2=Ay, color=color.new(coluor, 30), width=2)
  1758. line_AB := line.new(x1=Ax, y1=Ay, x2=Bx, y2=By, color=color.new(coluor, 30), width=2)
  1759. line_BC := line.new(x1=Bx, y1=By, x2=Cx, y2=Cy, color=color.new(coluor, 30), width=2)
  1760. line_CD := line.new(x1=Cx, y1=Cy, x2=Dx, y2=Dy, color=color.new(coluor, 30), width=2)
  1761.  
  1762. label_X := label.new(x=Xx, y=Xy, text="X", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1763. label_A := label.new(x=Ax, y=Ay, text="A", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1764. label_B := label.new(x=Bx, y=By, text="B", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1765. label_C := label.new(x=Cx, y=Cy, text="C", style=Dd == -1 ? label.style_label_down : label.style_label_up, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1766. label_D := label.new(x=Dx, y=Dy, text="D", style=Dd == -1 ? label.style_label_up : label.style_label_down, color=color.new(color.blue, 100), textcolor=color.new(coluor, 10), tooltip=tooltip)
  1767.  
  1768. xa_a = (Xy - Ay) / (Xx - Ax)
  1769. xa_b = Xy - xa_a * Xx
  1770. cd_a = (Cy - Dy) / (Cx - Dx)
  1771. cd_b = Cy - cd_a * Cx
  1772.  
  1773. Mx = math.floor((By - xa_b) / xa_a)
  1774. Nx = math.ceil((By - cd_b) / cd_a)
  1775. line_MB := line.new(x1=Mx, y1=By, x2=Bx, y2=By, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1776. line_BN := line.new(x1=Bx, y1=By, x2=Nx, y2=By, color=color.new(coluor, 30), width=1, style=line.style_dotted)
  1777. linefill.new(line_MB, line_XA, color=color.new(coluor, 80))
  1778. linefill.new(line_BN, line_BC, color=color.new(coluor, 80))
  1779. 0
  1780. else
  1781. if not na(label_D) and (bar_index - label.get_x(label_D)) * timeframe.multiplier > 30 * 24 * 60
  1782. line.delete(line_XA)
  1783. line.delete(line_AB)
  1784. line.delete(line_BC)
  1785. line.delete(line_CD)
  1786. line.delete(line_MB)
  1787. line.delete(line_BN)
  1788.  
  1789. label.delete(label_X)
  1790. label.delete(label_A)
  1791. label.delete(label_B)
  1792. label.delete(label_C)
  1793. label.delete(label_D)
  1794. 0
  1795.  
  1796. //double top pattern
  1797. double_top_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1798. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  1799.  
  1800. XA = math.abs(Xy - Ay)
  1801. XC = math.abs(Xy - Cy)
  1802. AB = math.abs(Ay - By)
  1803. BC = math.abs(By - Cy)
  1804. CD = math.abs(Cy - Dy)
  1805. AD = math.abs(Ay - Dy)
  1806.  
  1807. _XB = math.abs(Xx - Bx)
  1808. _BD = math.abs(Bx - Dx)
  1809.  
  1810. cd_a = (Cy - Dy) / (Cx - Dx)
  1811. cd_b = Cy - cd_a * Cx
  1812.  
  1813. Nx = (By - cd_b) / cd_a
  1814. Ny = By
  1815.  
  1816. cond1 = AB / XA >= 0.382 and AB / XA <= 0.886
  1817. cond2 = BC / AB >= 0.786 and BC / AB <= 1.000
  1818. cond3 = CD / BC >= 1.242 and CD / BC <= 1.382
  1819. cond4 = Dd == -1
  1820. cond5 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  1821. cond = cond1 and cond2 and cond3 and cond4 and cond5
  1822.  
  1823. entry_price = math.round_to_mintick(Ny)
  1824. stop_loss = Cy
  1825. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1826. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1827.  
  1828. coluor = bearcolor
  1829. trendy = true
  1830. name = "Double-Top ▼"
  1831. draw_double_top_btm_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1832. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1833.  
  1834. [cond, Dd, trendy]
  1835.  
  1836. //double bottom pattern
  1837. double_btm_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcolor, bearcolor, show_pattern, show_price) =>
  1838. [Xx, Xy, Xd, Ax, Ay, Ad, Bx, By, Bd, Cx, Cy, Cd, Dx, Dy, Dd] = get_5_points(zigzag, oldzigzag, zigzagdir, confirm)
  1839.  
  1840. XA = math.abs(Xy - Ay)
  1841. XC = math.abs(Xy - Cy)
  1842. AB = math.abs(Ay - By)
  1843. BC = math.abs(By - Cy)
  1844. CD = math.abs(Cy - Dy)
  1845. AD = math.abs(Ay - Dy)
  1846.  
  1847. _XB = math.abs(Xx - Bx)
  1848. _BD = math.abs(Bx - Dx)
  1849.  
  1850. cd_a = (Cy - Dy) / (Cx - Dx)
  1851. cd_b = Cy - cd_a * Cx
  1852.  
  1853. Nx = (By - cd_b) / cd_a
  1854. Ny = By
  1855.  
  1856. cond1 = AB / XA >= 0.382 and AB / XA <= 0.886
  1857. cond2 = BC / AB >= 0.786 and BC / AB <= 1.000
  1858. cond3 = CD / BC >= 1.242 and CD / BC <= 1.382
  1859. cond4 = Dd == 1
  1860. cond5 = _XB / _BD >= 0.333 and _XB / _BD <= 3.000
  1861. cond = cond1 and cond2 and cond3 and cond4 and cond5
  1862.  
  1863. entry_price = math.round_to_mintick(Ny)
  1864. stop_loss = Cy
  1865. take_profit1 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.000 * (Dd == 1 ? 1 : -1))
  1866. take_profit2 = math.round_to_mintick(Ny + math.abs(Ny - Cy) * 1.500 * (Dd == 1 ? 1 : -1))
  1867.  
  1868. coluor = bullcolor
  1869. trendy = true
  1870. name = "Double-Bottom ▲"
  1871. draw_double_top_btm_pattern(cond and show_pattern, Xx, Xy, Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, Dd, reso, name, trendy, coluor)
  1872. draw_trading_lines(cond and show_price, Dx, entry_price, stop_loss, take_profit1, take_profit2, coluor, 20)
  1873.  
  1874. [cond, Dd, trendy]
  1875.  
  1876.  
  1877. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1878. // Multi-Timeframe Zigzag -------------------------------------------------------------------------- //
  1879.  
  1880. zz_reso1 = input.timeframe(defval="30", title="timeframe resolution", group="Multi-Timeframe A")
  1881. zz_src1 = input.string(defval="HM2/LM2", title="pivot high/low source", options=["HIGH/LOW", "CLOSE", "HM2/LM2"], tooltip="HM2 = (high + max(open, close)) / 2\nLM2 = (low + min(open, close)) / 2", group="Multi-Timeframe A")
  1882. zz_perd1 = input.int(defval=5, title="timeframe pivot period", minval=0, group="Multi-Timeframe A")
  1883. zz_confirm1 = input.int(defval=3, title="delay for confirmations", minval=0, group="Multi-Timeframe A")
  1884. zz_bull_color1 = input.color(defval=color.new(#9FEE01, 30), title="bullish/bearish colors  ", inline="ZZAA", group="Multi-Timeframe A")
  1885. zz_bear_color1 = input.color(defval=color.new(#CC0074, 30), title="", inline="ZZAA", group="Multi-Timeframe A")
  1886. zz_enable_tf1 = input.bool(defval=true, title="enable harmonic patterns", group="Multi-Timeframe A")
  1887. zz_show_ptrn1 = input.bool(defval=true, title="show harmonic patterns", tooltip="All drawings in each timeframe will be preserved for 30 days, and only the last pattern of each pattern will be shown", group="Multi-Timeframe A")
  1888. zz_show_prce1 = input.bool(defval=false, title="show trading prices of patterns", tooltip="Including entry price, take profit 1, take profit 2, and stop loss price", group="Multi-Timeframe A")
  1889.  
  1890. zz_reso2 = input.timeframe(defval="45", title="timeframe resolution", group="Multi-Timeframe B")
  1891. zz_src2 = input.string(defval="HM2/LM2", title="pivot high/low source", options=["HIGH/LOW", "CLOSE", "HM2/LM2"], tooltip="HM2 = (high + max(open, close)) / 2\nLM2 = (low + min(open, close)) / 2", group="Multi-Timeframe B")
  1892. zz_perd2 = input.int(defval=5, title="timeframe pivot period", minval=0, group="Multi-Timeframe B")
  1893. zz_confirm2 = input.int(defval=3, title="delay for confirmations", minval=0, group="Multi-Timeframe B")
  1894. zz_bull_color2 = input.color(defval=color.new(#00CC00, 30), title="bullish/bearish colors  ", inline="ZZBB", group="Multi-Timeframe B")
  1895. zz_bear_color2 = input.color(defval=color.new(#FF0101, 30), title="", inline="ZZBB", group="Multi-Timeframe B")
  1896. zz_enable_tf2 = input.bool(defval=true, title="enable harmonic patterns", group="Multi-Timeframe B")
  1897. zz_show_ptrn2 = input.bool(defval=true, title="show harmonic patterns", tooltip="All drawings in each timeframe will be preserved for 30 days, and only the last pattern of each pattern will be shown", group="Multi-Timeframe B")
  1898. zz_show_prce2 = input.bool(defval=false, title="show trading prices of patterns", tooltip="Including entry price, take profit 1, take profit 2, and stop loss price", group="Multi-Timeframe B")
  1899.  
  1900. zz_reso3 = input.timeframe(defval="60", title="timeframe resolution", group="Multi-Timeframe C")
  1901. zz_src3 = input.string(defval="HM2/LM2", title="pivot high/low source", options=["HIGH/LOW", "CLOSE", "HM2/LM2"], tooltip="HM2 = (high + max(open, close)) / 2\nLM2 = (low + min(open, close)) / 2", group="Multi-Timeframe C")
  1902. zz_perd3 = input.int(defval=5, title="timeframe pivot period", minval=0, group="Multi-Timeframe C")
  1903. zz_confirm3 = input.int(defval=3, title="delay for confirmations", minval=0, group="Multi-Timeframe C")
  1904. zz_bull_color3 = input.color(defval=color.new(#009999, 30), title="bullish/bearish colors  ", inline="ZZAA", group="Multi-Timeframe C")
  1905. zz_bear_color3 = input.color(defval=color.new(#FF7401, 30), title="", inline="ZZAA", group="Multi-Timeframe C")
  1906. zz_enable_tf3 = input.bool(defval=true, title="enable harmonic patterns", group="Multi-Timeframe C")
  1907. zz_show_ptrn3 = input.bool(defval=true, title="show harmonic patterns", tooltip="All drawings in each timeframe will be preserved for 30 days, and only the last pattern of each pattern will be shown", group="Multi-Timeframe C")
  1908. zz_show_prce3 = input.bool(defval=false, title="show trading prices of patterns", tooltip="Including entry price, take profit 1, take profit 2, and stop loss price", group="Multi-Timeframe C")
  1909.  
  1910. zz_reso4 = input.timeframe(defval="120", title="timeframe resolution", group="Multi-Timeframe D")
  1911. zz_src4 = input.string(defval="HM2/LM2", title="pivot high/low source", options=["HIGH/LOW", "CLOSE", "HM2/LM2"], tooltip="HM2 = (high + max(open, close)) / 2\nLM2 = (low + min(open, close)) / 2", group="Multi-Timeframe D")
  1912. zz_perd4 = input.int(defval=5, title="timeframe pivot period", minval=0, group="Multi-Timeframe D")
  1913. zz_confirm4 = input.int(defval=3, title="delay for confirmations", minval=0, group="Multi-Timeframe D")
  1914. zz_bull_color4 = input.color(defval=color.new(#1240AB, 30), title="bullish/bearish colors  ", inline="ZZBB", group="Multi-Timeframe D")
  1915. zz_bear_color4 = input.color(defval=color.new(#FFAA01, 30), title="", inline="ZZBB", group="Multi-Timeframe D")
  1916. zz_enable_tf4 = input.bool(defval=true, title="enable harmonic patterns", group="Multi-Timeframe D")
  1917. zz_show_ptrn4 = input.bool(defval=true, title="show harmonic patterns", tooltip="All drawings in each timeframe will be preserved for 30 days, and only the last pattern of each pattern will be shown", group="Multi-Timeframe D")
  1918. zz_show_prce4 = input.bool(defval=false, title="show trading prices of patterns", tooltip="Including entry price, take profit 1, take profit 2, and stop loss price", group="Multi-Timeframe D")
  1919.  
  1920. zz_reso5 = input.timeframe(defval="180", title="timeframe resolution", group="Multi-Timeframe E")
  1921. zz_src5 = input.string(defval="HM2/LM2", title="pivot high/low source", options=["HIGH/LOW", "CLOSE", "HM2/LM2"], tooltip="HM2 = (high + max(open, close)) / 2\nLM2 = (low + min(open, close)) / 2", group="Multi-Timeframe E")
  1922. zz_perd5 = input.int(defval=5, title="timeframe pivot period", minval=0, group="Multi-Timeframe E")
  1923. zz_confirm5 = input.int(defval=3, title="delay for confirmations", minval=0, group="Multi-Timeframe E")
  1924. zz_bull_color5 = input.color(defval=color.new(#3715B0, 30), title="bullish/bearish colors  ", inline="ZZBB", group="Multi-Timeframe E")
  1925. zz_bear_color5 = input.color(defval=color.new(#FFD201, 30), title="", inline="ZZBB", group="Multi-Timeframe E")
  1926. zz_enable_tf5 = input.bool(defval=true, title="enable harmonic patterns", group="Multi-Timeframe E")
  1927. zz_show_ptrn5 = input.bool(defval=true, title="show harmonic patterns", tooltip="All drawings in each timeframe will be preserved for 30 days, and only the last pattern of each pattern will be shown", group="Multi-Timeframe E")
  1928. zz_show_prce5 = input.bool(defval=false, title="show trading prices of patterns", tooltip="Including entry price, take profit 1, take profit 2, and stop loss price", group="Multi-Timeframe E")
  1929.  
  1930. zz_reso6 = input.timeframe(defval="240", title="timeframe resolution", group="Multi-Timeframe F")
  1931. zz_src6 = input.string(defval="HM2/LM2", title="pivot high/low source", options=["HIGH/LOW", "CLOSE", "HM2/LM2"], tooltip="HM2 = (high + max(open, close)) / 2\nLM2 = (low + min(open, close)) / 2", group="Multi-Timeframe F")
  1932. zz_perd6 = input.int(defval=5, title="timeframe pivot period", minval=0, group="Multi-Timeframe F")
  1933. zz_confirm6 = input.int(defval=3, title="delay for confirmations", minval=0, group="Multi-Timeframe F")
  1934. zz_bull_color6 = input.color(defval=color.new(#7109AA, 30), title="bullish/bearish colors  ", inline="ZZBB", group="Multi-Timeframe F")
  1935. zz_bear_color6 = input.color(defval=color.new(#FFFF01, 30), title="", inline="ZZBB", group="Multi-Timeframe F")
  1936. zz_enable_tf6 = input.bool(defval=true, title="enable harmonic patterns", group="Multi-Timeframe F")
  1937. zz_show_ptrn6 = input.bool(defval=true, title="show harmonic patterns", tooltip="All drawings in each timeframe will be preserved for 30 days, and only the last pattern of each pattern will be shown", group="Multi-Timeframe F")
  1938. zz_show_prce6 = input.bool(defval=false, title="show trading prices of patterns", tooltip="Including entry price, take profit 1, take profit 2, and stop loss price", group="Multi-Timeframe F")
  1939.  
  1940. hm = (math.max(open, close) + high) / 2
  1941. lm = (math.min(open, close) + low) / 2
  1942.  
  1943. zz_hsrc1 = zz_src1 == "CLOSE" ? close : zz_src1 == "HM2/LM2" ? hm : high
  1944. zz_hsrc2 = zz_src2 == "CLOSE" ? close : zz_src2 == "HM2/LM2" ? hm : high
  1945. zz_hsrc3 = zz_src3 == "CLOSE" ? close : zz_src3 == "HM2/LM2" ? hm : high
  1946. zz_hsrc4 = zz_src4 == "CLOSE" ? close : zz_src4 == "HM2/LM2" ? hm : high
  1947. zz_hsrc5 = zz_src5 == "CLOSE" ? close : zz_src5 == "HM2/LM2" ? hm : high
  1948. zz_hsrc6 = zz_src6 == "CLOSE" ? close : zz_src6 == "HM2/LM2" ? hm : high
  1949.  
  1950. zz_lsrc1 = zz_src1 == "CLOSE" ? close : zz_src1 == "HM2/LM2" ? lm : low
  1951. zz_lsrc2 = zz_src2 == "CLOSE" ? close : zz_src2 == "HM2/LM2" ? lm : low
  1952. zz_lsrc3 = zz_src3 == "CLOSE" ? close : zz_src3 == "HM2/LM2" ? lm : low
  1953. zz_lsrc4 = zz_src4 == "CLOSE" ? close : zz_src4 == "HM2/LM2" ? lm : low
  1954. zz_lsrc5 = zz_src5 == "CLOSE" ? close : zz_src5 == "HM2/LM2" ? lm : low
  1955. zz_lsrc6 = zz_src6 == "CLOSE" ? close : zz_src6 == "HM2/LM2" ? lm : low
  1956.  
  1957. [zigzag1, oldzigzag1, zigzagdir1] = calculate_zigzag(zz_reso1, zz_perd1, zz_hsrc1, zz_lsrc1, 50)
  1958. [zigzag2, oldzigzag2, zigzagdir2] = calculate_zigzag(zz_reso2, zz_perd2, zz_hsrc2, zz_lsrc2, 50)
  1959. [zigzag3, oldzigzag3, zigzagdir3] = calculate_zigzag(zz_reso3, zz_perd3, zz_hsrc3, zz_lsrc3, 50)
  1960. [zigzag4, oldzigzag4, zigzagdir4] = calculate_zigzag(zz_reso4, zz_perd4, zz_hsrc4, zz_lsrc4, 50)
  1961. [zigzag5, oldzigzag5, zigzagdir5] = calculate_zigzag(zz_reso5, zz_perd5, zz_hsrc5, zz_lsrc5, 50)
  1962. [zigzag6, oldzigzag6, zigzagdir6] = calculate_zigzag(zz_reso6, zz_perd6, zz_hsrc6, zz_lsrc6, 50)
  1963.  
  1964.  
  1965. // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
  1966. // Harmonic Patterns -------------------------------------------------------------------------- //
  1967.  
  1968. hp_enable_gartlay = input.bool(defval=true, title="enable Gartlay pattern", group="Harmonic Patterns")
  1969. hp_enable_cypher = input.bool(defval=true, title="enable Cypher pattern", group="Harmonic Patterns")
  1970. hp_enable_bat = input.bool(defval=true, title="enable Bat pattern", group="Harmonic Patterns")
  1971. hp_enable_deepcrab = input.bool(defval=true, title="enable Deepcrab pattern", group="Harmonic Patterns")
  1972. hp_enable_crab = input.bool(defval=true, title="enable Crab pattern", group="Harmonic Patterns")
  1973. hp_enable_butterfly = input.bool(defval=true, title="enable Butterfly pattern", group="Harmonic Patterns")
  1974. hp_enable_shark = input.bool(defval=true, title="enable Shark pattern", group="Harmonic Patterns")
  1975. hp_enable_zero5 = input.bool(defval=true, title="enable 0-5 pattern", group="Harmonic Patterns")
  1976. hp_enable_abcd = input.bool(defval=true, title="enable AB=CD pattern", group="Harmonic Patterns")
  1977. hp_enable_3drives = input.bool(defval=true, title="enable 3-Drives pattern", group="Harmonic Patterns")
  1978. hp_enable_anti_gartlay = input.bool(defval=true, title="enable Anti-Gartlay pattern", group="Harmonic Patterns")
  1979. hp_enable_anti_cypher = input.bool(defval=true, title="enable Anti-Cypher pattern", group="Harmonic Patterns")
  1980. hp_enable_anti_bat = input.bool(defval=true, title="enable Anti-Bat pattern", group="Harmonic Patterns")
  1981. hp_enable_anti_crab = input.bool(defval=true, title="enable Anti-Crab pattern", group="Harmonic Patterns")
  1982. hp_enable_anti_butterfly = input.bool(defval=true, title="enable Anti-Butterfly pattern", group="Harmonic Patterns")
  1983. hp_enable_anti_shark = input.bool(defval=true, title="enable Anti-Shark pattern", group="Harmonic Patterns")
  1984. hp_enable_black_swan = input.bool(defval=true, title="enable Black-Swan pattern", group="Harmonic Patterns")
  1985. hp_enable_white_swan = input.bool(defval=true, title="enable White-Swan pattern", group="Harmonic Patterns")
  1986. hp_enable_desc_triangle = input.bool(defval=false, title="enable Descending-Triangle pattern", group="Harmonic Patterns")
  1987. hp_enable_asc_triangle = input.bool(defval=false, title="enable Ascending-Triangle pattern", group="Harmonic Patterns")
  1988. hp_enable_sym_triangle = input.bool(defval=false, title="enable Symmetrical-Triangle pattern", group="Harmonic Patterns")
  1989. hp_enable_norm_hs = input.bool(defval=false, title="enable Headers&Shoulders pattern", group="Harmonic Patterns")
  1990. hp_enable_inve_hs = input.bool(defval=false, title="enable Inverse-Headers&Shoulders pattern", group="Harmonic Patterns")
  1991. hp_enable_double_top = input.bool(defval=false, title="enable Double-Top pattern", group="Harmonic Patterns")
  1992. hp_enable_double_btm = input.bool(defval=false, title="enable Double-Bottom pattern", group="Harmonic Patterns")
  1993.  
  1994. get_harmonic_patterns(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price) =>
  1995. patterns = matrix.new<int>(25, 3, na)
  1996.  
  1997. if hp_enable_gartlay
  1998. [cond, dir, trend] = gartlay_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  1999. if cond
  2000. matrix.set(patterns, 0, 0, cond ? 1 : 0)
  2001. matrix.set(patterns, 0, 1, dir)
  2002. matrix.set(patterns, 0, 2, trend ? 1 : 0)
  2003.  
  2004. if hp_enable_bat
  2005. [cond, dir, trend] = bat_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2006. if cond
  2007. matrix.set(patterns, 1, 0, cond ? 1 : 0)
  2008. matrix.set(patterns, 1, 1, dir)
  2009. matrix.set(patterns, 1, 2, trend ? 1 : 0)
  2010.  
  2011. if hp_enable_cypher
  2012. [cond, dir, trend] = cypher_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2013. if cond
  2014. matrix.set(patterns, 2, 0, cond ? 1 : 0)
  2015. matrix.set(patterns, 2, 1, dir)
  2016. matrix.set(patterns, 2, 2, trend ? 1 : 0)
  2017.  
  2018. if hp_enable_deepcrab
  2019. [cond, dir, trend] = deepcrab_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2020. if cond
  2021. matrix.set(patterns, 3, 0, cond ? 1 : 0)
  2022. matrix.set(patterns, 3, 1, dir)
  2023. matrix.set(patterns, 3, 2, trend ? 1 : 0)
  2024.  
  2025. if hp_enable_crab
  2026. [cond, dir, trend] = crab_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2027. if cond
  2028. matrix.set(patterns, 4, 0, cond ? 1 : 0)
  2029. matrix.set(patterns, 4, 1, dir)
  2030. matrix.set(patterns, 4, 2, trend ? 1 : 0)
  2031.  
  2032. if hp_enable_butterfly
  2033. [cond, dir, trend] = butterfly_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2034. if cond
  2035. matrix.set(patterns, 5, 0, cond ? 1 : 0)
  2036. matrix.set(patterns, 5, 1, dir)
  2037. matrix.set(patterns, 5, 2, trend ? 1 : 0)
  2038.  
  2039. if hp_enable_shark
  2040. [cond, dir, trend] = shark_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2041. if cond
  2042. matrix.set(patterns, 6, 0, cond ? 1 : 0)
  2043. matrix.set(patterns, 6, 1, dir)
  2044. matrix.set(patterns, 6, 2, trend ? 1 : 0)
  2045.  
  2046. if hp_enable_zero5
  2047. [cond, dir, trend] = zero5_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2048. if cond
  2049. matrix.set(patterns, 7, 0, cond ? 1 : 0)
  2050. matrix.set(patterns, 7, 1, dir)
  2051. matrix.set(patterns, 7, 2, trend ? 1 : 0)
  2052.  
  2053. if hp_enable_abcd
  2054. [cond, dir, trend] = abcd_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2055. if cond
  2056. matrix.set(patterns, 8, 0, cond ? 1 : 0)
  2057. matrix.set(patterns, 8, 1, dir)
  2058. matrix.set(patterns, 8, 2, trend ? 1 : 0)
  2059.  
  2060. if hp_enable_3drives
  2061. [cond, dir, trend] = threedrives_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2062. if cond
  2063. matrix.set(patterns, 9, 0, cond ? 1 : 0)
  2064. matrix.set(patterns, 9, 1, dir)
  2065. matrix.set(patterns, 9, 2, trend ? 1 : 0)
  2066.  
  2067. if hp_enable_anti_gartlay
  2068. [cond, dir, trend] = anti_gartlay_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2069. if cond
  2070. matrix.set(patterns, 10, 0, cond ? 1 : 0)
  2071. matrix.set(patterns, 10, 1, dir)
  2072. matrix.set(patterns, 10, 2, trend ? 1 : 0)
  2073.  
  2074. if hp_enable_anti_bat
  2075. [cond, dir, trend] = anti_bat_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2076. if cond
  2077. matrix.set(patterns, 11, 0, cond ? 1 : 0)
  2078. matrix.set(patterns, 11, 1, dir)
  2079. matrix.set(patterns, 11, 2, trend ? 1 : 0)
  2080.  
  2081. if hp_enable_anti_cypher
  2082. [cond, dir, trend] = anti_cypher_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2083. if cond
  2084. matrix.set(patterns, 12, 0, cond ? 1 : 0)
  2085. matrix.set(patterns, 12, 1, dir)
  2086. matrix.set(patterns, 12, 2, trend ? 1 : 0)
  2087.  
  2088. if hp_enable_anti_crab
  2089. [cond, dir, trend] = anti_crab_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2090. if cond
  2091. matrix.set(patterns, 13, 0, cond ? 1 : 0)
  2092. matrix.set(patterns, 13, 1, dir)
  2093. matrix.set(patterns, 13, 2, trend ? 1 : 0)
  2094.  
  2095. if hp_enable_anti_butterfly
  2096. [cond, dir, trend] = anti_butterfly_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2097. if cond
  2098. matrix.set(patterns, 14, 0, cond ? 1 : 0)
  2099. matrix.set(patterns, 14, 1, dir)
  2100. matrix.set(patterns, 14, 2, trend ? 1 : 0)
  2101.  
  2102. if hp_enable_anti_shark
  2103. [cond, dir, trend] = anti_shark_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2104. if cond
  2105. matrix.set(patterns, 15, 0, cond ? 1 : 0)
  2106. matrix.set(patterns, 15, 1, dir)
  2107. matrix.set(patterns, 15, 2, trend ? 1 : 0)
  2108.  
  2109. if hp_enable_black_swan
  2110. [cond, dir, trend] = black_swan_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2111. if cond
  2112. matrix.set(patterns, 16, 0, cond ? 1 : 0)
  2113. matrix.set(patterns, 16, 1, dir)
  2114. matrix.set(patterns, 16, 2, trend ? 1 : 0)
  2115.  
  2116. if hp_enable_white_swan
  2117. [cond, dir, trend] = white_swan_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2118. if cond
  2119. matrix.set(patterns, 17, 0, cond ? 1 : 0)
  2120. matrix.set(patterns, 17, 1, dir)
  2121. matrix.set(patterns, 17, 2, trend ? 1 : 0)
  2122.  
  2123. if hp_enable_desc_triangle
  2124. [cond, dir, trend] = desc_triangle_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2125. if cond
  2126. matrix.set(patterns, 18, 0, cond ? 1 : 0)
  2127. matrix.set(patterns, 18, 1, dir)
  2128. matrix.set(patterns, 18, 2, trend ? 1 : 0)
  2129.  
  2130. if hp_enable_asc_triangle
  2131. [cond, dir, trend] = asc_triangle_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2132. if cond
  2133. matrix.set(patterns, 19, 0, cond ? 1 : 0)
  2134. matrix.set(patterns, 19, 1, dir)
  2135. matrix.set(patterns, 19, 2, trend ? 1 : 0)
  2136.  
  2137. if hp_enable_sym_triangle
  2138. [cond, dir, trend] = sym_triangle_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2139. if cond
  2140. matrix.set(patterns, 20, 0, cond ? 1 : 0)
  2141. matrix.set(patterns, 20, 1, dir)
  2142. matrix.set(patterns, 20, 2, trend ? 1 : 0)
  2143.  
  2144. if hp_enable_norm_hs
  2145. [cond, dir, trend] = norm_hs_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2146. if cond
  2147. matrix.set(patterns, 21, 0, cond ? 1 : 0)
  2148. matrix.set(patterns, 21, 1, dir)
  2149. matrix.set(patterns, 21, 2, trend ? 1 : 0)
  2150.  
  2151. if hp_enable_inve_hs
  2152. [cond, dir, trend] = inve_hs_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2153. if cond
  2154. matrix.set(patterns, 22, 0, cond ? 1 : 0)
  2155. matrix.set(patterns, 22, 1, dir)
  2156. matrix.set(patterns, 22, 2, trend ? 1 : 0)
  2157.  
  2158. if hp_enable_double_top
  2159. [cond, dir, trend] = double_top_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2160. if cond
  2161. matrix.set(patterns, 23, 0, cond ? 1 : 0)
  2162. matrix.set(patterns, 23, 1, dir)
  2163. matrix.set(patterns, 23, 2, trend ? 1 : 0)
  2164.  
  2165. if hp_enable_double_btm
  2166. [cond, dir, trend] = double_btm_pattern(reso, zigzag, oldzigzag, zigzagdir, confirm, bullcol, bearcol, show_pattern, show_price)
  2167. if cond
  2168. matrix.set(patterns, 24, 0, cond ? 1 : 0)
  2169. matrix.set(patterns, 24, 1, dir)
  2170. matrix.set(patterns, 24, 2, trend ? 1 : 0)
  2171.  
  2172. patterns
  2173.  
  2174.  
  2175. patterns_reso1 = zz_enable_tf1 ? get_harmonic_patterns(zz_reso1, zigzag1, oldzigzag1, zigzagdir1, zz_confirm1, zz_bull_color1, zz_bear_color1, zz_show_ptrn1, zz_show_prce1) : matrix.new<int>(25, 3, na)
  2176. patterns_reso2 = zz_enable_tf2 ? get_harmonic_patterns(zz_reso2, zigzag2, oldzigzag2, zigzagdir2, zz_confirm2, zz_bull_color2, zz_bear_color2, zz_show_ptrn2, zz_show_prce2) : matrix.new<int>(25, 3, na)
  2177. patterns_reso3 = zz_enable_tf3 ? get_harmonic_patterns(zz_reso3, zigzag3, oldzigzag3, zigzagdir3, zz_confirm3, zz_bull_color3, zz_bear_color3, zz_show_ptrn3, zz_show_prce3) : matrix.new<int>(25, 3, na)
  2178. patterns_reso4 = zz_enable_tf4 ? get_harmonic_patterns(zz_reso4, zigzag4, oldzigzag4, zigzagdir4, zz_confirm4, zz_bull_color4, zz_bear_color4, zz_show_ptrn4, zz_show_prce4) : matrix.new<int>(25, 3, na)
  2179. patterns_reso5 = zz_enable_tf5 ? get_harmonic_patterns(zz_reso5, zigzag5, oldzigzag5, zigzagdir5, zz_confirm5, zz_bull_color5, zz_bear_color5, zz_show_ptrn5, zz_show_prce5) : matrix.new<int>(25, 3, na)
  2180. patterns_reso6 = zz_enable_tf6 ? get_harmonic_patterns(zz_reso6, zigzag6, oldzigzag6, zigzagdir6, zz_confirm6, zz_bull_color6, zz_bear_color6, zz_show_ptrn6, zz_show_prce6) : matrix.new<int>(25, 3, na)
  2181.  
  2182. get_events(patterns) =>
  2183. simple_bull = 0
  2184. simple_bear = 0
  2185.  
  2186. trendy_bull = 0
  2187. trendy_bear = 0
  2188.  
  2189. for i = 0 to matrix.rows(patterns) - 1
  2190. cond = matrix.get(patterns, i, 0)
  2191. dir = matrix.get(patterns, i, 1)
  2192. trend = matrix.get(patterns, i, 2)
  2193. if cond == 1
  2194. if dir == 1
  2195. simple_bull := simple_bull + 1
  2196. else if dir == -1
  2197. simple_bear := simple_bear + 1
  2198.  
  2199. if dir == 1 and trend == 1
  2200. trendy_bull := trendy_bull + 1
  2201. else if dir == -1 and trend == 1
  2202. trendy_bear := trendy_bear + 1
  2203.  
  2204. [simple_bull, simple_bear, trendy_bull, trendy_bear]
  2205.  
  2206. [simple_bull_reso1, simple_bear_reso1, trendy_bull_reso1, trendy_bear_reso1] = get_events(patterns_reso1)
  2207. [simple_bull_reso2, simple_bear_reso2, trendy_bull_reso2, trendy_bear_reso2] = get_events(patterns_reso2)
  2208. [simple_bull_reso3, simple_bear_reso3, trendy_bull_reso3, trendy_bear_reso3] = get_events(patterns_reso3)
  2209. [simple_bull_reso4, simple_bear_reso4, trendy_bull_reso4, trendy_bear_reso4] = get_events(patterns_reso4)
  2210. [simple_bull_reso5, simple_bear_reso5, trendy_bull_reso5, trendy_bear_reso5] = get_events(patterns_reso5)
  2211. [simple_bull_reso6, simple_bear_reso6, trendy_bull_reso6, trendy_bear_reso6] = get_events(patterns_reso6)
  2212.  
  2213. simple_bull_case = (simple_bull_reso1 + simple_bull_reso2 + simple_bull_reso3 + simple_bull_reso4 + simple_bull_reso5 + simple_bull_reso6) > 0
  2214. trendy_bull_case = (trendy_bull_reso1 + trendy_bull_reso2 + trendy_bull_reso3 + trendy_bull_reso4 + trendy_bull_reso5 + trendy_bull_reso6) > 0
  2215. simple_bear_case = (simple_bear_reso1 + simple_bear_reso2 + simple_bear_reso3 + simple_bear_reso4 + simple_bear_reso5 + simple_bear_reso6) > 0
  2216. trendy_bear_case = (trendy_bear_reso1 + trendy_bear_reso2 + trendy_bear_reso3 + trendy_bear_reso4 + trendy_bear_reso5 + trendy_bear_reso6) > 0
  2217.  
  2218. simple_bull_bear_case_color = simple_bull_case and simple_bear_case ? color.purple : simple_bull_case ? color.green : simple_bear_case ? color.red : na
  2219. plotshape(simple_bull_case and simple_bear_case, style=shape.circle, location=location.bottom, color=color.new(simple_bull_bear_case_color, 20), size=size.tiny)
  2220. plotshape(simple_bull_case and not simple_bear_case, style=shape.circle, location=location.bottom, color=color.new(simple_bull_bear_case_color, 20), size=size.tiny)
  2221. plotshape(not simple_bull_case and simple_bear_case, style=shape.circle, location=location.bottom, color=color.new(simple_bull_bear_case_color, 20), size=size.tiny)
  2222.  
  2223. // trendy_bull_bear_case_color = trendy_bull_case and trendy_bear_case ? color.purple : trendy_bull_case ? color.green : trendy_bear_case ? color.red : na
  2224. // plotshape(trendy_bull_case and trendy_bear_case, style=shape.circle, location=location.bottom, color=color.new(trendy_bull_bear_case_color, 20), size=size.tiny)
  2225. // plotshape(trendy_bull_case and not trendy_bear_case, style=shape.circle, location=location.bottom, color=color.new(trendy_bull_bear_case_color, 20), size=size.tiny)
  2226. // plotshape(not trendy_bull_case and trendy_bear_case, style=shape.circle, location=location.bottom, color=color.new(trendy_bull_bear_case_color, 20), size=size.tiny)
  2227.  
  2228. int encode = (simple_bull_case ? 1 : 0) * 8 + (trendy_bull_case ? 1 : 0) * 4 + (simple_bear_case ? 1 : 0) * 2 + (trendy_bear_case ? 1 : 0) * 1
  2229. plot(encode, title="bincode", display=display.none)
  2230.  
  2231.  
  2232. //end of file
Advertisement
Add Comment
Please, Sign In to add comment