xmd79

Auto Harmonic Patterns - Open Source

Sep 29th, 2021
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.54 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. // © ArieTB
  3.  
  4. //@version=4
  5. study("Auto Harmonic Patterns - Open Source", shorttitle="Teras Bursa Harmonic P", overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500)
  6. Length = input(10, minval=0, step=5)
  7. DeviationThreshold = 0
  8. errorPercent = input(10, minval=5, step=5, maxval=20)
  9. showPivots = input(false)
  10. showRatios = input(false)
  11. showZigZag = input(false)
  12. bullishColor = input(color.green)
  13. bullTrapColor = input(color.orange)
  14. bearishColor = input(color.red)
  15. bearTrapColor = input(color.lime)
  16. MaxRiskPerReward = input(40, title="Max Risk Per Reward (Double Top/Bottom)", step=10, minval=0)
  17.  
  18. abcdClassic = input(true)
  19. abEQcd = input(true)
  20. abcdExt = input(true)
  21. doubleTopBottom = input(true)
  22. gartley=input(true)
  23. crab = input(true)
  24. deepCrab = input(true)
  25. bat = input(true)
  26. butterfly = input(true)
  27. shark=input(true)
  28. cypher = input(true)
  29. threeDrives = input(true)
  30. fiveZero = input(true)
  31.  
  32. var abcdlines = array.new_line(3)
  33. var abcdtype = array.new_int(2,1)
  34.  
  35. var wmlines = array.new_line(4)
  36. var wmtype = array.new_int(2,1)
  37. var wmLabels = array.new_bool(9, false)
  38.  
  39. var patterncount = array.new_int(26,0)
  40.  
  41.  
  42. var zigzaglines = array.new_line(0)
  43. var zigzaglabels = array.new_label(0)
  44. var zigzagdir = array.new_int(0)
  45. var zigzagratios = array.new_float(0)
  46.  
  47. int max_array_size = 10
  48. transparent = color.new(#FFFFFF, 100)
  49. err_min = (100-errorPercent)/100
  50. err_max = (100+errorPercent)/100
  51. pivots(length)=>
  52. float ph = highestbars(high, length) == 0 ? high : na
  53. float pl = lowestbars(low, length) == 0 ? low : na
  54. dir = 0
  55. dir := iff(ph and na(pl), 1, iff(pl and na(ph), -1, dir[1]))
  56. [dir, ph, pl]
  57.  
  58. get_edir(dir, y2)=>
  59. eDir = dir
  60. if(array.size(zigzaglines) > 0)
  61. lastLine = array.get(zigzaglines, 0)
  62. lastPivot = line.get_y1(lastLine)
  63. eDir := (dir*y2 > dir*lastPivot? 2 : 1) * dir
  64. lineColor = eDir == 2? bullishColor : eDir == 1? bullTrapColor : eDir == -1? bearTrapColor : bearishColor
  65. [eDir, lineColor]
  66.  
  67. add_to_zigzaglines(x1, y1 , x2, y2, dir)=>
  68. [eDir, lineColor] = get_edir(dir, y2)
  69. color = showZigZag? lineColor : color.new(#FFFFFF, 100)
  70. zline = line.new(x1=x1, y1=y1,
  71. x2 = x2, y2=y2,
  72. color=color, width=2, style=line.style_solid)
  73. array.unshift(zigzaglines, zline)
  74.  
  75. add_to_zigzaglabels(x1, x2, y1, y2, dir)=>
  76. [eDir, lineColor] = get_edir(dir, y2)
  77. pivotLabel = eDir == 2? "HH" : eDir == 1? "LH" : eDir == -1? "HL" : "LL"
  78. lastLineLen = 0.0
  79. currentLineLen = abs(y2-y1)
  80. if(array.size(zigzaglines) > 0)
  81. lastLine = array.get(zigzaglines, 0)
  82. lastLineLen := abs(line.get_y2(lastLine) - line.get_y1(lastLine))
  83.  
  84. ratio = round(lastLineLen != 0 ? currentLineLen/lastLineLen : 0, 3)
  85. labelText = (showPivots ? pivotLabel : "") +
  86. (showPivots and showRatios ? " - " : "") +
  87. (showRatios ? tostring(ratio) : "")
  88. yloc = dir > 0? yloc.abovebar : yloc.belowbar
  89. labelStyle = dir > 0? label.style_label_down : label.style_label_up
  90. labelSize = showRatios and showPivots? size.normal : size.small
  91. zlabel = label.new(x=x2, y=y2, text=labelText, xloc = xloc.bar_index, yloc = yloc,
  92. color=lineColor, size=labelSize, style=labelStyle)
  93.  
  94. array.unshift(zigzaglabels,zlabel)
  95. array.unshift(zigzagdir, eDir)
  96. array.unshift(zigzagratios, ratio)
  97. if(not showRatios and not showPivots)
  98. label.delete(zlabel)
  99.  
  100. add_to_zigzag(dir, dirchanged, ph, pl, index)=>
  101. value = (dir == 1? ph : pl)
  102.  
  103. y1= dir == 1? lowest(Length) : highest(Length)
  104. x1 = bar_index + (dir == 1? lowestbars(Length) : highestbars(Length))
  105. x2 = index
  106. y2 = value
  107. skip = false
  108. if(array.size(zigzaglines) > 0)
  109. if(not dirchanged)
  110. lastline = array.get(zigzaglines, 0)
  111. lasty2 = line.get_y2(lastline)
  112. if(lasty2*dir > y2*dir)
  113. skip := true
  114. else
  115. line.delete(array.shift(zigzaglines))
  116. label.delete(array.shift(zigzaglabels))
  117. array.shift(zigzagdir)
  118. array.shift(zigzagratios)
  119. skip := false
  120.  
  121. if(array.size(zigzaglines) > 0)
  122. lastLine = array.get(zigzaglines, 0)
  123. x1 := line.get_x2(lastLine)
  124. y1 := line.get_y2(lastLine)
  125.  
  126. outsideDeviationThreshold = ((abs(y1-y2)*100/y1) > DeviationThreshold)
  127. if(outsideDeviationThreshold and not skip)
  128. add_to_zigzaglabels(x1, x2, y1, y2, dir)
  129. add_to_zigzaglines(x1, y1 , x2, y2, dir)
  130. if array.size(zigzaglines) > max_array_size
  131. array.pop(zigzaglines)
  132. array.pop(zigzaglabels)
  133. array.pop(zigzagdir)
  134. array.pop(zigzagratios)
  135.  
  136. zigzag(length, DeviationThreshold)=>
  137. [dir, ph, pl] = pivots(length)
  138. dirchanged = change(dir)
  139. if(ph or pl)
  140. add_to_zigzag(dir, dirchanged, ph, pl, bar_index)
  141.  
  142. calculate_abcd()=>
  143. abcd=false
  144.  
  145. if(array.size(zigzagratios) >= 3 and array.size(zigzaglines)>=4)
  146. abcRatio = array.get(zigzagratios, 2)
  147. bcdRatio = array.get(zigzagratios, 1)
  148.  
  149. ab = array.get(zigzaglines, 3)
  150. bc = array.get(zigzaglines, 2)
  151. cd = array.get(zigzaglines, 1)
  152.  
  153. ab_time = abs(line.get_x1(ab) - line.get_x2(ab))
  154. ab_price = abs(line.get_y1(ab) - line.get_y2(ab))
  155.  
  156. cd_time = abs(line.get_x1(cd) - line.get_x2(cd))
  157. cd_price = abs(line.get_y1(cd) - line.get_y2(cd))
  158.  
  159. a = line.get_y1(ab)
  160. b = line.get_y2(ab)
  161.  
  162. c = line.get_y1(cd)
  163. d = line.get_y2(cd)
  164.  
  165. abcdDirection = (a < b and a < c and c < b and c < d and a < d and b < d) or (a > b and a > c and c > b and c > d and a > d and b > d)
  166. dir = (a < b and a < c and c < b and c < d and a < d and b < d)? 1 : (a > b and a > c and c > b and c > d and a > d and b > d) ? -1 : 0
  167. time_ratio = cd_time/ab_time
  168. price_ratio = cd_price/ab_price
  169.  
  170. // if (ab == ab[1] and bc == bc[1] and cd == cd[1])
  171. // abcd := false
  172. if(abcdClassic and abcRatio >= 0.618*err_min and abcRatio <= 0.786*err_max and bcdRatio >= 1.272*err_min and bcdRatio <= 1.618*err_max and abcdDirection)
  173. abcd := true
  174. array.set(abcdtype, 0, 1)
  175. if(abEQcd and time_ratio >= err_min and time_ratio <= err_max and price_ratio >= err_min and price_ratio <= err_max and abcdDirection)
  176. abcd := true
  177. array.set(abcdtype, 0, 2)
  178. if(abcdExt and price_ratio >= 1.272*err_min and price_ratio <= 1.618*err_max and abcRatio >= 0.618*err_min and abcRatio <= 0.786*err_max and abcdDirection)
  179. abcd := true
  180. array.set(abcdtype, 0, 3)
  181. if(abcd)
  182. array.set(abcdlines, 0, ab)
  183. array.set(abcdlines, 1, bc)
  184. array.set(abcdlines, 2, cd)
  185. array.set(abcdtype, 1, dir)
  186. abcd
  187.  
  188. draw_abcd()=>
  189. abcd = calculate_abcd()
  190. if(array.size(abcdlines)>2 and array.size(zigzaglines)>=4)
  191. ab = array.get(abcdlines, 0)
  192. bc = array.get(abcdlines, 1)
  193. cd = array.get(abcdlines, 2)
  194.  
  195. abcd_type = array.get(abcdtype, 0)
  196. dir = array.get(abcdtype, 1)
  197.  
  198. labelColor = dir > 0? bearishColor : bullishColor
  199. labelStyle = dir > 0? label.style_label_down : label.style_label_up
  200. yloc = dir > 0? yloc.abovebar : yloc.belowbar
  201.  
  202. labelText = abcd_type == 1? "ABCD" : abcd_type == 2? "AB=CD" : abcd_type == 3? "ABCD Ext" : ""
  203. ab_zg = array.get(zigzaglines, 3)
  204. bc_zg = array.get(zigzaglines, 2)
  205. cd_zg = array.get(zigzaglines, 1)
  206. count_index = (abcd_type*2 - 2) + (dir > 0 ? 1 : 0)
  207. abcdLabel = label.new(x=line.get_x2(cd), y=line.get_y2(cd), text=labelText, xloc = xloc.bar_index, yloc = yloc,
  208. color=labelColor, size=size.normal, style=labelStyle)
  209. array.set(patterncount, count_index, array.get(patterncount, count_index) + 1)
  210.  
  211. line.set_color(ab,labelColor)
  212. line.set_color(bc,labelColor)
  213. line.set_color(cd,labelColor)
  214.  
  215. if(abcd[1] and bc == bc_zg and ab == ab_zg)
  216. label.delete(abcdLabel[1])
  217. array.set(patterncount, count_index, array.get(patterncount, count_index) - 1)
  218. line.set_color(ab,transparent)
  219. line.set_color(bc,transparent)
  220. line.set_color(cd,transparent)
  221.  
  222. if(not abcd) or (label.get_x(abcdLabel) == label.get_x(abcdLabel[1]) and label.get_y(abcdLabel) == label.get_y(abcdLabel[1]))
  223. label.delete(abcdLabel)
  224. array.set(patterncount, count_index, array.get(patterncount, count_index) - 1)
  225. else
  226. line.set_color(ab,labelColor)
  227. line.set_color(bc,labelColor)
  228. line.set_color(cd,labelColor)
  229.  
  230. calculate_double_pattern()=>
  231. doubleTop = false
  232. doubleBottom = false
  233. if(array.size(zigzagdir) >= 4 and doubleTopBottom)
  234. value = line.get_y2(array.get(zigzaglines, 1))
  235. highLow = array.get(zigzagdir, 1)
  236.  
  237. lvalue = line.get_y2(array.get(zigzaglines, 2))
  238. lhighLow = array.get(zigzagdir, 2)
  239.  
  240. llvalue = line.get_y2(array.get(zigzaglines, 3))
  241. llhighLow = array.get(zigzagdir, 3)
  242.  
  243. risk = abs(value-llvalue)
  244. reward = abs(value-lvalue)
  245. riskPerReward = risk*100/(risk+reward)
  246.  
  247. if(highLow == 1 and llhighLow == 2 and lhighLow == -1 and riskPerReward < MaxRiskPerReward)
  248. doubleTop := true
  249. if(highLow == -1 and llhighLow == -2 and lhighLow == 1 and riskPerReward < MaxRiskPerReward)
  250. doubleBottom := true
  251.  
  252. [doubleTop, doubleBottom]
  253.  
  254.  
  255. draw_double_pattern(doubleTop, doubleBottom)=>
  256. if(array.size(zigzagdir) >= 4)
  257. line1 = array.get(zigzaglines, 1)
  258. line2 = array.get(zigzaglines, 2)
  259.  
  260. x1 = line.get_x1(line2)
  261. y1 = line.get_y1(line2)
  262. x2 = line.get_x2(line1)
  263. y2 = line.get_y2(line1)
  264.  
  265. midline = line.get_y1(line1)
  266. midlineIndex = line.get_x1(line1)
  267. risk = abs(y2-y1)
  268. reward = abs(y2-midline)
  269. riskPerReward = round(risk*100/(risk+reward), 2)
  270.  
  271. base = line.new(x1=x1, y1=y1,
  272. x2 = x2, y2=y2,
  273. color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_solid)
  274.  
  275. count_index = doubleTop? 7 : 6
  276. labelText = (doubleTop? "DT - " : "DB - ") + tostring(riskPerReward)
  277. array.set(patterncount, count_index, array.get(patterncount, count_index) + 1)
  278. baseLabel = label.new(x=x2, y=y2, text=labelText, yloc=doubleTop?yloc.abovebar:yloc.belowbar,
  279. color=doubleTop?bearishColor:bullishColor,
  280. style=doubleTop?label.style_label_down:label.style_label_up,
  281. textcolor=color.black, size=size.normal)
  282. if(line.get_x1(base) == line.get_x1(base[1]))
  283. line.delete(base[1])
  284. label.delete(baseLabel[1])
  285. array.set(patterncount, count_index, array.get(patterncount, count_index) - 1)
  286.  
  287. if not (doubleTop or doubleBottom)
  288. line.delete(base)
  289. label.delete(baseLabel)
  290. array.set(patterncount, count_index, array.get(patterncount, count_index) - 1)
  291.  
  292. calculate_wm_patterns()=>
  293. wm_pattern = false
  294. if(array.size(zigzagdir) >= 5)
  295. yxaRatio = array.get(zigzagratios, 4)
  296. xabRatio = array.get(zigzagratios, 3)
  297. abcRatio = array.get(zigzagratios, 2)
  298. bcdRatio = array.get(zigzagratios, 1)
  299.  
  300. xa = array.get(zigzaglines, 4)
  301. ab = array.get(zigzaglines, 3)
  302. bc = array.get(zigzaglines, 2)
  303. cd = array.get(zigzaglines, 1)
  304.  
  305. x = line.get_y1(xa)
  306. a = line.get_y2(xa)
  307. b = line.get_y2(ab)
  308. c = line.get_y1(cd)
  309. d = line.get_y2(cd)
  310.  
  311. xadRatio = round(abs(a-d)/abs(x-a),3)
  312. dir = a > d? 1 : -1
  313.  
  314. maxP1 = max(x,a)
  315. maxP2 = max(c,d)
  316. minP1 = min(x,a)
  317. minP2 = min(c,d)
  318.  
  319. highPoint = min(maxP1, maxP2)
  320. lowPoint = max(minP1, minP2)
  321.  
  322. if(b < highPoint and b > lowPoint)
  323. //gartley
  324. if(gartley and (xabRatio >= 0.618*err_min and xabRatio <= 0.618*err_max) and
  325. (abcRatio >= 0.382*err_min and abcRatio <= 0.886*err_max) and
  326. ((bcdRatio >= 1.272*err_min and bcdRatio <= 1.618*err_max) or (xadRatio >= 0.786*err_min and xadRatio <= 0.786*err_max)))
  327. wm_pattern := true
  328. array.set(wmtype, 1, 0)
  329. array.set(wmLabels, 0, true)
  330. else
  331. array.set(wmLabels, 0, false)
  332. //Crab
  333. if(crab and (xabRatio >= 0.382*err_min and xabRatio <= 0.618*err_max) and
  334. (abcRatio >= 0.382*err_min and abcRatio <= 0.886*err_max) and
  335. ((bcdRatio >= 2.24*err_min and bcdRatio <= 3.618*err_max) or (xadRatio >= 1.618*err_min and xadRatio <= 1.618*err_max)))
  336. wm_pattern := true
  337. array.set(wmtype, 1, 1)
  338. array.set(wmLabels, 1, true)
  339. else
  340. array.set(wmLabels, 1, false)
  341. //Deep Crab
  342. if(deepCrab and (xabRatio >= 0.886*err_min and xabRatio <= 0.886*err_max) and
  343. (abcRatio >= 0.382*err_min and abcRatio <= 0.886*err_max) and
  344. ((bcdRatio >= 2.00*err_min and bcdRatio <= 3.618*err_max) or (xadRatio >= 1.618*err_min and xadRatio <= 1.618*err_max)))
  345. wm_pattern := true
  346. array.set(wmtype, 1, 2)
  347. array.set(wmLabels, 2, true)
  348. else
  349. array.set(wmLabels, 2, false)
  350. //Bat
  351. if(bat and (xabRatio >= 0.382*err_min and xabRatio <= 0.50*err_max) and
  352. (abcRatio >= 0.382*err_min and abcRatio <= 0.886*err_max) and
  353. ((bcdRatio >= 1.618*err_min and bcdRatio <= 2.618*err_max) or (xadRatio >= 0.886*err_min and xadRatio <= 0.886*err_max)))
  354. wm_pattern := true
  355. array.set(wmtype, 1, 3)
  356. array.set(wmLabels, 3, true)
  357. else
  358. array.set(wmLabels, 3, false)
  359. //Butterfly
  360. if(butterfly and (xabRatio >= 0.786*err_min and xabRatio <= 0.786*err_max) and
  361. (abcRatio >= 0.382*err_min and abcRatio <= 0.886*err_max) and
  362. ((bcdRatio >= 1.618*err_min and bcdRatio <= 2.618*err_max) or (xadRatio >= 1.272*err_min and xadRatio <= 1.618*err_max)))
  363. wm_pattern := true
  364. array.set(wmtype, 1, 4)
  365. array.set(wmLabels, 4, true)
  366. else
  367. array.set(wmLabels, 4, false)
  368. //Shark
  369. if(shark and (abcRatio >= 1.13*err_min and abcRatio <= 1.618*err_max) and
  370. ((bcdRatio >= 1.618*err_min and bcdRatio <= 2.24*err_max) and (xadRatio >= 0.886*err_min and xadRatio <= 1.13*err_max)))
  371. wm_pattern := true
  372. array.set(wmtype, 1, 5)
  373. array.set(wmLabels, 5, true)
  374. else
  375. array.set(wmLabels, 5, false)
  376. //Cypher
  377. if(cypher and (xabRatio >= 0.382*err_min and xabRatio <= 0.618*err_max) and
  378. (abcRatio >= 1.13*err_min and abcRatio <= 1.414*err_max) and
  379. ((bcdRatio >= 1.272*err_min and bcdRatio <= 2.00*err_max) or (xadRatio >= 0.786*err_min and xadRatio <= 0.786*err_max)))
  380. wm_pattern := true
  381. array.set(wmtype, 1, 6)
  382. array.set(wmLabels, 6, true)
  383. else
  384. array.set(wmLabels, 6, false)
  385. //3 drive
  386. if(threeDrives and (yxaRatio >= 0.618*err_min and yxaRatio <= 0.618*err_max) and
  387. (xabRatio >= 1.27*err_min and xabRatio <= 1.618*err_max) and
  388. ((abcRatio >= 0.618*err_min and abcRatio <= 0.618*err_max) and (bcdRatio >= 1.27*err_min and bcdRatio <= 1.618*err_max)))
  389. wm_pattern := true
  390. array.set(wmtype, 1, 7)
  391. array.set(wmLabels, 7, true)
  392. else
  393. array.set(wmLabels, 7, false)
  394. //5-0
  395. if(fiveZero and (xabRatio >= 1.13*err_min and xabRatio <= 1.618*err_max) and
  396. (abcRatio >= 1.618*err_min and abcRatio <= 2.24*err_max) and
  397. (bcdRatio >= 0.5*err_min and bcdRatio <= 0.5*err_max))
  398. wm_pattern := true
  399. array.set(wmtype, 1, 8)
  400. array.set(wmLabels, 8, true)
  401. else
  402. array.set(wmLabels, 8, false)
  403. if(wm_pattern)
  404. array.set(wmlines, 0, xa)
  405. array.set(wmlines, 1, ab)
  406. array.set(wmlines, 2, bc)
  407. array.set(wmlines, 3, cd)
  408. array.set(wmtype, 0, dir)
  409. wm_pattern
  410.  
  411. draw_wm_patterns()=>
  412. wm_pattern = calculate_wm_patterns()
  413. if(array.size(wmlines) >= 4 and array.size(zigzaglines)>=5)
  414. xa = array.get(wmlines, 0)
  415. ab = array.get(wmlines, 1)
  416. bc = array.get(wmlines, 2)
  417. cd = array.get(wmlines, 3)
  418.  
  419. dir = array.get(wmtype, 0)
  420. type = array.get(wmtype, 1)
  421. trendColor=dir > 0? bullishColor: bearishColor
  422. x = line.get_y1(xa)
  423. xbar = line.get_x1(xa)
  424.  
  425. a = line.get_y2(xa)
  426. abar = line.get_x2(xa)
  427.  
  428. b = line.get_y2(ab)
  429. bbar = line.get_x2(ab)
  430.  
  431. c = line.get_y2(bc)
  432. cbar = line.get_x2(bc)
  433.  
  434. d = line.get_y2(cd)
  435. dbar = line.get_x2(cd)
  436.  
  437. line.set_color(xa, trendColor)
  438. line.set_color(ab, trendColor)
  439. line.set_color(bc, trendColor)
  440. line.set_color(cd, trendColor)
  441. ac = line.new(x1=abar, y1=a,
  442. x2 = cbar, y2=c,
  443. color=trendColor, width=2, style=line.style_solid)
  444. xb = line.new(x1=xbar, y1=x,
  445. x2 = bbar, y2=b,
  446. color=trendColor, width=2, style=line.style_solid)
  447. xd = line.new(x1=xbar, y1=x,
  448. x2 = dbar, y2=d,
  449. color=trendColor, width=2, style=line.style_solid)
  450. bd = line.new(x1=bbar, y1=b,
  451. x2 = dbar, y2=d,
  452. color=trendColor, width=2, style=line.style_solid)
  453.  
  454. isGartley = array.get(wmLabels, 0)
  455. isCrab = array.get(wmLabels, 1)
  456. isDeepCrab = array.get(wmLabels, 2)
  457. isBat = array.get(wmLabels, 3)
  458. isButterfly = array.get(wmLabels, 4)
  459. isShark = array.get(wmLabels, 5)
  460. isCypher = array.get(wmLabels, 6)
  461. is3Drives = array.get(wmLabels, 7)
  462. isFiveZero = array.get(wmLabels, 8)
  463.  
  464. labelText = isGartley ? "Gartley" : ""
  465. labelText := labelText+(isCrab? (labelText == ""? "" : "\n") + "Crab" : "")
  466. labelText := labelText+(isDeepCrab? (labelText == ""? "" : "\n") + "Deep Crab" : "")
  467. labelText := labelText+(isBat? (labelText == ""? "" : "\n") + "Bat" : "")
  468. labelText := labelText+(isButterfly? (labelText == ""? "" : "\n") + "Butterfly" : "")
  469. labelText := labelText+(isShark? (labelText == ""? "" : "\n") + "Shark" : "")
  470. labelText := labelText+(isCypher? (labelText == ""? "" : "\n") + "Cypher" : "")
  471. labelText := labelText+(is3Drives? (labelText == ""? "" : "\n") + "3 Drive" : "")
  472. labelText := labelText+(isFiveZero? (labelText == ""? "" : "\n") + "5-0" : "")
  473.  
  474. baseLabel = label.new(x=bbar, y=b, text=labelText, yloc=dir < 1?yloc.abovebar:yloc.belowbar,
  475. color=trendColor,
  476. style=dir < 1?label.style_label_down:label.style_label_up,
  477. textcolor=color.black, size=size.normal)
  478.  
  479. xa_zg = array.get(zigzaglines, 4)
  480. ab_zg = array.get(zigzaglines, 3)
  481. bc_zg = array.get(zigzaglines, 2)
  482. cd_zg = array.get(zigzaglines, 1)
  483.  
  484. for i=0 to 8
  485. count_index = (i*2 + 8) + (dir > 0 ? 0 : 1)
  486. if(array.get(wmLabels, i) and xa != xa[1] and ab != ab[1] and bc != bc[1])
  487. array.set(patterncount, count_index, array.get(patterncount, count_index) + 1)
  488. if(array.get(wmLabels, i)[1] and xa == xa_zg and ab == ab_zg and bc == bc_zg)
  489. array.set(patterncount, count_index, array.get(patterncount, count_index) - 1)
  490.  
  491. if(wm_pattern[1] and not wm_pattern and xa == xa_zg and ab == ab_zg and bc == bc_zg)
  492. line.delete(ac[1])
  493. line.delete(xb[1])
  494. line.delete(xd[1])
  495. line.delete(bd[1])
  496. line.set_color(xa[1], transparent)
  497. line.set_color(ab[1], transparent)
  498. line.set_color(bc[1], transparent)
  499. line.set_color(cd[1], transparent)
  500. label.delete(baseLabel[1])
  501. // array.set(patterncount, count_index, array.get(patterncount, count_index) - 1)
  502.  
  503. if(not wm_pattern) or (label.get_x(baseLabel) == label.get_x(baseLabel[1]) and label.get_y(baseLabel) == label.get_y(baseLabel[1]))
  504. line.delete(ac)
  505. line.delete(xb)
  506. line.delete(xd)
  507. line.delete(bd)
  508. label.delete(baseLabel)
  509.  
  510. zigzag(Length, DeviationThreshold)
  511. draw_abcd()
  512.  
  513. [doubleTop, doubleBottom] = calculate_double_pattern()
  514. draw_double_pattern(doubleTop,doubleBottom)
  515.  
  516. draw_wm_patterns()
  517.  
  518.  
Advertisement
Add Comment
Please, Sign In to add comment