Advertisement
xmd79

EA - 3 Indicators

Oct 21st, 2023
585
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.72 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. // © HeWhoMustNotBeNamed
  3.  
  4. // __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
  5. // / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
  6. // $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
  7. // $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
  8. // $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
  9. // $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
  10. // $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
  11. // $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
  12. // $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
  13. //
  14. //
  15. //
  16. //@version=4
  17. study("EA - 3 Indicators", shorttitle="EA - 3 Indicators", overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=1000)
  18. length = input(10, step=5, minval=5)
  19. showZigzag = input(false)
  20. showPivots = input(true)
  21. showStats = input(true)
  22. bullishColor = input(color.green)
  23. bullTrapColor = input(color.orange)
  24. bearishColor = input(color.red)
  25. bearTrapColor = input(color.lime)
  26. textColor = input(color.black)
  27.  
  28. MaxRiskPerReward = input(30, step=5, minval=5, maxval=100)
  29. DisplayRiskPerReward = input(true)
  30. var zigzagvalues = array.new_float(0)
  31. var zigzagindexes = array.new_int(0)
  32. var zigzagdir = array.new_int(0)
  33.  
  34. var doubleTopBottomValues = array.new_float(3)
  35. var doubleTopBottomIndexes = array.new_int(3)
  36. var doubleTopBottomDir = array.new_int(3)
  37.  
  38. int max_array_size = 10
  39. max_bars_back(high, 1000)
  40. max_bars_back(low, 1000)
  41.  
  42. var lineArray = array.new_line(0)
  43. var labelArray = array.new_label(0)
  44.  
  45. // declare my variables
  46. var mPriceOfDoubleBottom = 0.0
  47. var mPriceOfNeckLine = 0.0
  48.  
  49. pivots(length)=>
  50. float ph = highestbars(high, length) == 0 ? high : na
  51. float pl = lowestbars(low, length) == 0 ? low : na
  52. dir = 0
  53. dir := iff(ph and na(pl), 1, iff(pl and na(ph), -1, dir[1]))
  54. [dir, ph, pl]
  55.  
  56. add_to_array(value, index, dir)=>
  57. mult = array.size(zigzagvalues) < 2? 1 :
  58. (dir*value > dir*array.get(zigzagvalues,1))? 2 : 1
  59. array.unshift(zigzagindexes, index)
  60. array.unshift(zigzagvalues, value)
  61. array.unshift(zigzagdir, dir*mult)
  62. if array.size(zigzagindexes) > max_array_size
  63. array.pop(zigzagindexes)
  64. array.pop(zigzagvalues)
  65. array.pop(zigzagdir)
  66.  
  67. add_to_zigzag(dir, dirchanged, ph, pl, index)=>
  68. value = (dir == 1? ph : pl)
  69. if array.size(zigzagvalues) == 0 or dirchanged
  70. add_to_array(value, index, dir)
  71. else if(dir == 1 and value > array.get(zigzagvalues, 0)) or (dir == -1 and value < array.get(zigzagvalues, 0))
  72. array.shift(zigzagvalues)
  73. array.shift(zigzagindexes)
  74. array.shift(zigzagdir)
  75. add_to_array(value, index, dir)
  76.  
  77. zigzag(length)=>
  78. [dir, ph, pl] = pivots(length)
  79. dirchanged = change(dir)
  80. if(ph or pl)
  81. add_to_zigzag(dir, dirchanged, ph, pl, bar_index)
  82.  
  83. calculate_double_pattern()=>
  84. doubleTop = false
  85. doubleTopConfirmation = 0
  86. doubleBottom = false
  87. doubleBottomConfirmation = 0
  88. priceOfDoubleBottom = 0.0
  89.  
  90. if(array.size(zigzagvalues) >= 4)
  91. index = array.get(zigzagindexes, 1)
  92. value = array.get(zigzagvalues, 1)
  93. highLow = array.get(zigzagdir, 1)
  94.  
  95. lindex = array.get(zigzagindexes, 2)
  96. lvalue = array.get(zigzagvalues, 2)
  97. lhighLow = array.get(zigzagdir, 2)
  98.  
  99. llindex = array.get(zigzagindexes, 3)
  100. llvalue = array.get(zigzagvalues, 3)
  101. llhighLow = array.get(zigzagdir, 3)
  102. risk = abs(value-llvalue)
  103. reward = abs(value-lvalue)
  104. riskPerReward = risk*100/(risk+reward)
  105.  
  106. if(highLow == 1 and llhighLow == 2 and lhighLow < 0 and riskPerReward < MaxRiskPerReward)
  107. doubleTop := true
  108. if(highLow == -1 and llhighLow == -2 and lhighLow > 0 and riskPerReward < MaxRiskPerReward)
  109. doubleBottom := true
  110.  
  111. if(doubleTop or doubleBottom)
  112. array.set(doubleTopBottomValues, 0, value)
  113. array.set(doubleTopBottomValues, 1, lvalue)
  114. array.set(doubleTopBottomValues, 2, llvalue)
  115.  
  116. array.set(doubleTopBottomIndexes, 0, index)
  117. array.set(doubleTopBottomIndexes, 1, lindex)
  118. array.set(doubleTopBottomIndexes, 2, llindex)
  119.  
  120. array.set(doubleTopBottomDir, 0, highLow)
  121. array.set(doubleTopBottomDir, 1, lhighLow)
  122. array.set(doubleTopBottomDir, 2, llhighLow)
  123.  
  124. // if(doubleBottom)
  125. // mPriceOfNeckLine := lvalue
  126.  
  127. [doubleTop, doubleBottom]
  128.  
  129. get_crossover_info(doubleTop, doubleBottom)=>
  130. index = array.get(doubleTopBottomIndexes, 0)
  131. value = array.get(doubleTopBottomValues, 0)
  132. highLow = array.get(doubleTopBottomDir, 0)
  133.  
  134. lindex = array.get(doubleTopBottomIndexes, 1)
  135. lvalue = array.get(doubleTopBottomValues, 1)
  136. lhighLow = array.get(doubleTopBottomDir, 1)
  137.  
  138. llindex = array.get(doubleTopBottomIndexes, 2)
  139. llvalue = array.get(doubleTopBottomValues, 2)
  140. llhighLow = array.get(doubleTopBottomDir, 2)
  141.  
  142. latestDoubleTop = false
  143. latestDoubleBottom = false
  144. latestDoubleTop := doubleTop ? true : doubleBottom? false : latestDoubleTop[1]
  145. latestDoubleBottom := doubleBottom? true : doubleTop? false : latestDoubleBottom[1]
  146.  
  147. doubleTopConfirmation = 0
  148. doubleBottomConfirmation = 0
  149. doubleTopConfirmation := latestDoubleTop? (crossunder(low, lvalue) ? 1 : crossover(high, llvalue) ? -1 : 0) : 0
  150. doubleBottomConfirmation := latestDoubleBottom? (crossover(high, lvalue) ? 1 : crossunder(low, llvalue) ? -1 : 0) : 0
  151. [doubleTopConfirmation, doubleBottomConfirmation]
  152.  
  153. draw_double_pattern(doubleTop,doubleBottom,doubleTopConfirmation,doubleBottomConfirmation)=>
  154. index = array.get(doubleTopBottomIndexes, 0)
  155. value = array.get(doubleTopBottomValues, 0)
  156. highLow = array.get(doubleTopBottomDir, 0)
  157.  
  158. lindex = array.get(doubleTopBottomIndexes, 1)
  159. lvalue = array.get(doubleTopBottomValues, 1)
  160. lhighLow = array.get(doubleTopBottomDir, 1)
  161.  
  162. llindex = array.get(doubleTopBottomIndexes, 2)
  163. llvalue = array.get(doubleTopBottomValues, 2)
  164. llhighLow = array.get(doubleTopBottomDir, 2)
  165.  
  166. isBullish = true
  167. isBullish := (doubleTop or doubleBottom)? doubleTop : isBullish[1]
  168.  
  169. risk = abs(value-llvalue)
  170. reward = abs(value-lvalue)
  171. riskPerReward = risk*100/(risk+reward)
  172.  
  173. base = line.new(x1=index, y1=value,
  174. x2 = llindex, y2=llvalue,
  175. color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_solid)
  176. l1 = line.new(x1=index, y1=value,
  177. x2 = lindex, y2=lvalue,
  178. color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_dotted)
  179. l2 = line.new(x1=lindex, y1=lvalue,
  180. x2 = llindex, y2=llvalue,
  181. color=doubleTop? bearishColor : bullishColor, width=2, style=line.style_dotted)
  182. labelText = (doubleTop? "Double Top" : "Double Bottom") + (DisplayRiskPerReward ? " RR - "+tostring(riskPerReward) : "")
  183.  
  184. baseLabel = label.new(x=index, y=value, text=labelText, yloc=doubleTop?yloc.abovebar:yloc.belowbar,
  185. color=doubleTop?bearishColor:bullishColor,
  186. style=doubleTop?label.style_label_down:label.style_label_up,
  187. textcolor=textColor, size=size.normal)
  188.  
  189. if not (doubleTop or doubleBottom)
  190. line.delete(base)
  191. line.delete(l1)
  192. line.delete(l2)
  193. label.delete(baseLabel)
  194.  
  195. var doubleTopCount = 0
  196. var doubleBottomCount = 0
  197. doubleTopCount := doubleTop? nz(doubleTopCount[1],0) + 1 : nz(doubleTopCount[1],0)
  198. doubleBottomCount := doubleBottom? nz(doubleBottomCount[1],0) + 1 : nz(doubleBottomCount[1],0)
  199.  
  200. if(line.get_x2(base) == line.get_x2(base[1]))
  201. line.delete(base[1])
  202. line.delete(l1[1])
  203. line.delete(l2[1])
  204. label.delete(baseLabel[1])
  205. doubleTopCount := doubleTop? doubleTopCount -1 : doubleTopCount
  206. doubleBottomCount := doubleBottom? doubleBottomCount -1 : doubleBottomCount
  207.  
  208.  
  209. if(barstate.islast)
  210. lres = line.new(x1=bar_index, y1=lvalue,
  211. x2 = lindex, y2=lvalue,
  212. color=isBullish? bearishColor : bullishColor, width=2, style=line.style_dashed, extend=extend.left)
  213. lsup = line.new(x1=bar_index, y1=llvalue,
  214. x2 = llindex, y2=llvalue,
  215. color=isBullish? bullishColor : bearishColor , width=2, style=line.style_dashed, extend=extend.left)
  216.  
  217. // plot lvalue and llvalue
  218. // // update price of last Support & Resistance
  219. // mPriceOfLastSupport := llvalue
  220. // mPriceOfLastResistance := lvalue
  221.  
  222. // alert("debug message")
  223.  
  224.  
  225.  
  226. doubleTopConfirmationCount = doubleTopConfirmation>0? 1 : 0
  227. doubleBottomConfirmationCount = doubleBottomConfirmation>0? 1:0
  228. doubleTopInvalidationCount = doubleTopConfirmation<0? 1 : 0
  229. doubleBottomInvalidationCount = doubleBottomConfirmation<0? 1:0
  230.  
  231. if(doubleTopConfirmation != 0 or doubleBottomConfirmation !=0)
  232. if(doubleTopConfirmation>0 or doubleBottomConfirmation > 0)
  233. lresbreak = line.new(x1=lindex, y1=lvalue,
  234. x2 = bar_index, y2=lvalue,
  235. color=isBullish? bearishColor : bullishColor, width=2, style=line.style_dashed)
  236. if(line.get_x1(lresbreak[1]) == line.get_x1(lresbreak))
  237. doubleTopConfirmationCount := 0
  238. doubleBottomConfirmationCount := 0
  239. doubleTopInvalidationCount := 0
  240. doubleBottomInvalidationCount := 0
  241. line.delete(lresbreak)
  242. lresbreak := lresbreak[1]
  243. else if(doubleTopConfirmation<0 or doubleBottomConfirmation < 0)
  244. lsupbreak = line.new(x1=llindex, y1=llvalue,
  245. x2 = bar_index, y2=llvalue,
  246. color=isBullish? bullishColor : bearishColor , width=2, style=line.style_dashed)
  247. if(line.get_x1(lsupbreak[1]) == line.get_x1(lsupbreak))
  248. doubleTopInvalidationCount := 0
  249. doubleBottomInvalidationCount := 0
  250. doubleTopConfirmationCount := 0
  251. doubleBottomConfirmationCount := 0
  252. line.delete(lsupbreak)
  253. lsupbreak := lsupbreak[1]
  254. doubleTopConfirmationCount := nz(doubleTopConfirmationCount[1],0)+doubleTopConfirmationCount
  255. doubleBottomConfirmationCount := nz(doubleBottomConfirmationCount[1],0)+doubleBottomConfirmationCount
  256. doubleTopInvalidationCount := nz(doubleTopInvalidationCount[1],0)+doubleTopInvalidationCount
  257. doubleBottomInvalidationCount := nz(doubleBottomInvalidationCount[1],0)+doubleBottomInvalidationCount
  258. [doubleTopCount, doubleBottomCount, doubleTopConfirmationCount, doubleBottomConfirmationCount, doubleTopInvalidationCount, doubleBottomInvalidationCount, lvalue, llvalue]
  259.  
  260. zigzag(length)
  261.  
  262. // ============= MY FUNCTION ============
  263. f_print(message)=>
  264. if barstate.islast
  265. label.new(bar_index, high, text=tostring(message), color=color.red, style=label.style_label_down, yloc=yloc.abovebar)
  266.  
  267.  
  268. // check neckline is break
  269. f_check_neckline_break()=>
  270. if (close > mPriceOfNeckLine)
  271. // Logic for when price breaks above neckline
  272. alert("neckline break")
  273.  
  274.  
  275.  
  276. // ========= HANDLE LOGIC ========
  277. [doubleTop, doubleBottom] = calculate_double_pattern()
  278. [doubleTopConfirmation, doubleBottomConfirmation] = get_crossover_info(doubleTop, doubleBottom)
  279. [doubleTopCount, doubleBottomCount,
  280. doubleTopConfirmationCount, doubleBottomConfirmationCount,
  281. doubleTopInvalidationCount, doubleBottomInvalidationCount,
  282. lvalue, llvalue] = draw_double_pattern(doubleTop,doubleBottom,doubleTopConfirmation,doubleBottomConfirmation)
  283. // function check if double bottom is fresh
  284. f_check_fresh_double_bottom(double_bottom_price) =>
  285. _result = false
  286. if double_bottom_price == na
  287. _result := false
  288. else if (close <= double_bottom_price )
  289. // Logic for when price breaks above neckline
  290. _result := false
  291. else
  292. _result := true
  293. _result
  294. // function check if double top is fresh
  295. f_check_fresh_double_top(double_top_price) =>
  296. _result = false
  297. if double_top_price == na
  298. _result := false
  299. else if (close >= double_top_price )
  300. // Logic for when price breaks above neckline
  301. _result := false
  302. else
  303. _result := true
  304. _result
  305.  
  306. // ====== SIGNAL 1 ========
  307. // ===== declare variables =====
  308. doubleBottomValue = array.get(doubleTopBottomValues,2)
  309. var int count_closing_above_neck_line = 0
  310. var float neck_line_price = 0.0
  311. MINIUM_AMOUNT_OF_CLOSE_ABOVE_NECK_LINE = 3
  312. var bool signal_1 = false
  313. var float top_price = na
  314. var float bottom_price = na
  315. var bool fresh_top = false
  316. var bool fresh_bottom = false
  317.  
  318. // find top price and bottom price ( sometimes it is reversed )
  319. temp_top_price = lvalue > llvalue ? lvalue : llvalue
  320. temp_bottom_price = lvalue < llvalue ? lvalue : llvalue
  321.  
  322. // ==== handle logic =====
  323.  
  324. // update price & status for TOP
  325. if bottom_price != temp_bottom_price
  326. fresh_bottom := true
  327. bottom_price := temp_bottom_price // replace lvalue with your actual value
  328. // update price & status for BOTTOM
  329. if top_price != temp_top_price
  330. fresh_top := true
  331. top_price := temp_top_price // replace llvalue with your actual value
  332.  
  333. // update neck line price
  334. neck_line_price := top_price
  335.  
  336. // check if double bottom is fresh
  337. if fresh_top
  338. fresh_top := f_check_fresh_double_top(top_price)
  339. // check if double top is fresh
  340. if fresh_bottom
  341. fresh_bottom := f_check_fresh_double_bottom(bottom_price)
  342.  
  343.  
  344. // only count closing above neck line if double bottom is fresh
  345. if fresh_bottom
  346. // check if price is above neck line price
  347. if close > neck_line_price
  348. count_closing_above_neck_line := count_closing_above_neck_line + 1
  349. else
  350. count_closing_above_neck_line := 0
  351. signal_1 := false
  352.  
  353. // check if count of close above neck line >= 3
  354. if count_closing_above_neck_line >= MINIUM_AMOUNT_OF_CLOSE_ABOVE_NECK_LINE
  355. signal_1 := true
  356.  
  357.  
  358.  
  359.  
  360. // ====== plot function ========
  361.  
  362. // // plot top price and bottom price
  363. // plot(series = barstate.islast ? top_price: na, color = color.green, title = "top_price - Top")
  364. // plot(series = barstate.islast ? bottom_price: na, color = color.green, title = "bottom_price - Bottom")
  365.  
  366. // get index of double top
  367. index_of_double_top = array.get(doubleTopBottomIndexes, 1)
  368. // get index of double bottom
  369. index_of_double_bottom = array.get(doubleTopBottomIndexes, 2)
  370.  
  371. // // plot doubleTopConfirmation, doubleBottomConfirmation blue x
  372. // plotshape(series = doubleTopConfirmation > 0, size = size.tiny, style = shape.xcross, color = color.blue, title = "doubleTopConfirmation", location = location.abovebar)
  373. // plotshape(series = doubleBottomConfirmation > 0, size = size.tiny, style = shape.xcross, color = color.red, title = "doubleBottomConfirmation", location = location.belowbar)
  374.  
  375.  
  376. // // plot index of double top and double bottom
  377. // plot(series = index_of_double_top, color = color.green, title = "index_of_double_top - Top")
  378. // plot(series = index_of_double_bottom, color = color.green, title = "index_of_double_bottom - Bottom")
  379.  
  380. // line.new(x1 = index_of_double_bottom, y1 = low, x2 = index_of_double_bottom, y2 = high, color=color.green, width = 3)
  381. // line.new(x1 = index_of_double_top, y1 = low, x2 = index_of_double_top, y2 = high, color=color.red, width = 3)
  382.  
  383. // if bar_index == index_of_double_bottom
  384. // line.new(x1 = index_of_double_bottom, y1 = low, x2 = index_of_double_bottom, y2 = high, color=color.green, width = 1)
  385. // if bar_index == index_of_double_top
  386. // line.new(x1 = index_of_double_top, y1 = low, x2 = index_of_double_top, y2 = high, color=color.red, width = 1)
  387.  
  388.  
  389. // // plot double top
  390. // plotshape(series = doubleTop, size = size.tiny, style = shape.xcross, color = color.green, title = "doubleTop", location = location.abovebar)
  391.  
  392. // // plot double bottom
  393. // plotshape(series = doubleBottom, size = size.tiny, style = shape.xcross, color = color.red, title = "doubleBottom", location = location.belowbar, transp=0)
  394. // // plot double top
  395. // plotshape(series = doubleTop, size = size.tiny, style = shape.xcross, color = color.green, title = "doubleTop", location = location.abovebar, transp=0)
  396.  
  397. // label function
  398. // if (barstate.islast and signal_1 == true)
  399.  
  400. // Plot arrow up when signal_1 is true
  401. // isExistDoubleTopOrDoubleBottom = doubleTop or doubleBottom
  402. // signal_1 := isExistDoubleTopOrDoubleBottom and signal_1
  403. plotshape(series=signal_1, style=shape.diamond, color=color.green, size=size.tiny)
  404.  
  405. // // plot label fresh TOP & BOTTOM
  406. // if fresh_top and barstate.islast
  407. // label.new(bar_index, top_price, text= "F_T", color=color.red, style=label.style_label_up, yloc=yloc.abovebar)
  408. // if fresh_bottom and barstate.islast
  409. // label.new(bar_index, bottom_price, text="F_B", color=color.red, style=label.style_label_down, yloc=yloc.belowbar)
  410.  
  411.  
  412. // ====== plot function ========
  413. // ====== SIGNAL 1 ========
  414.  
  415.  
  416.  
  417. // only create label at the last bar
  418. // plot a label at the last bar
  419. // if (barstate.islast)
  420. // label.new(bar_index, close, title="Count Closing above neckline", style=label.style_label_down, color=color.red, text=tostring(count_closing_above_neck_line))
  421. // label.new(barstate.islast? 1: na , high, "Last Bar", color=color.white)
  422.  
  423.  
  424. // plot count of close above neckline
  425. // plot(series = barstate.islast ? count_closing_above_neck_line : na, color = color.blue, title = "Count of Close Above Neckline" + tostring(count_closing_above_neck_line))
  426.  
  427. // ====== MY LOGIC ========
  428.  
  429. var stats = table.new(position = position.top_right, columns = 5, rows = 5, border_width = 1)
  430. if(1 == 2 and barstate.islast and showStats)
  431. // if(barstate.islast and showStats)
  432. colorWorst = color.rgb(255, 153, 51)
  433. colorBest = color.rgb(51, 204, 51)
  434. colorBad = color.rgb(255, 204, 153)
  435. colorGood = color.rgb(204, 255, 204)
  436. colorNeutral = color.rgb(255, 255, 204)
  437.  
  438. dtConfirmationPercent = doubleTopConfirmationCount+doubleTopInvalidationCount == 0? 0.5 : doubleTopConfirmationCount/(doubleTopConfirmationCount+doubleTopInvalidationCount)
  439. dbConfirmationPercent = (doubleBottomConfirmationCount+doubleBottomInvalidationCount) == 0? 0.5 : doubleBottomConfirmationCount/(doubleBottomConfirmationCount+doubleBottomInvalidationCount)
  440.  
  441. dtColor = dtConfirmationPercent >= 0.8? colorBest :
  442. dtConfirmationPercent >= 0.6? colorGood :
  443. dtConfirmationPercent >= 0.4? colorNeutral :
  444. dtConfirmationPercent >= 0.2? colorBad : colorWorst
  445. dbColor = dbConfirmationPercent >= 0.8? colorBest :
  446. dbConfirmationPercent >= 0.6? colorGood :
  447. dbConfirmationPercent >= 0.4? colorNeutral :
  448. dbConfirmationPercent >= 0.2? colorBad : colorWorst
  449. table.cell(table_id = stats, column = 0, row = 0 , text = "", bgcolor=color.black, text_color=color.white)
  450. table.cell(table_id = stats, column = 0, row = 1 , text = "Double Top", bgcolor=color.black, text_color=color.white)
  451. table.cell(table_id = stats, column = 0, row = 2 , text = "Double Bottom", bgcolor=color.black, text_color=color.white)
  452.  
  453. table.cell(table_id = stats, column = 1, row = 0 , text = "Count", bgcolor=color.black, text_color=color.white)
  454. table.cell(table_id = stats, column = 2, row = 0 , text = "Confirmation", bgcolor=color.black, text_color=color.white)
  455. table.cell(table_id = stats, column = 3, row = 0 , text = "Invalidation", bgcolor=color.black, text_color=color.white)
  456.  
  457. table.cell(table_id = stats, column = 1, row = 1, text = tostring(doubleTopCount), bgcolor=dtColor)
  458. table.cell(table_id = stats, column = 1, row = 2, text = tostring(doubleBottomCount), bgcolor=dbColor)
  459.  
  460. table.cell(table_id = stats, column = 2, row = 1, text = tostring(doubleTopConfirmationCount), bgcolor=dtColor)
  461. table.cell(table_id = stats, column = 3, row = 1, text = tostring(doubleTopInvalidationCount), bgcolor=dtColor)
  462.  
  463. table.cell(table_id = stats, column = 2, row = 2, text = tostring(doubleBottomConfirmationCount), bgcolor=dbColor)
  464. table.cell(table_id = stats, column = 3, row = 2, text = tostring(doubleBottomInvalidationCount), bgcolor=dbColor)
  465.  
  466. // if(barstate.islast and array.size(zigzagindexes) > 1)
  467. if(1 == 2 and barstate.islast and array.size(zigzagindexes) > 1)
  468. lastHigh = 0.0
  469. lastLow = 0.0
  470. for x = 0 to array.size(zigzagindexes)-1
  471. i = array.size(zigzagindexes)-1-x
  472. index = array.get(zigzagindexes, i)
  473. value = array.get(zigzagvalues, i)
  474. highLow = array.get(zigzagdir, i)
  475. index_offset = bar_index-index
  476.  
  477. labelText = highLow ==2 ? "HH" : highLow == 1? "LH" : highLow == -1? "HL" : "LL"
  478. labelColor = highLow ==2 ? bullishColor : highLow == 1? bullTrapColor : highLow == -1? bearTrapColor : bearishColor
  479. labelStyle = highLow > 0? label.style_label_down : label.style_label_up
  480. // labelLocation = highLow > 0? yloc.abovebar : yloc.belowbar
  481. labelLocation = yloc.price
  482. if(showPivots)
  483. l = label.new(x=index, y = value, text=labelText, xloc=xloc.bar_index, yloc=labelLocation, style=labelStyle, size=size.tiny,
  484. color=labelColor, textcolor=textColor)
  485. array.unshift(labelArray, l)
  486. if(array.size(labelArray) > 100)
  487. label.delete(array.pop(labelArray))
  488. if(i < array.size(zigzagindexes)-1 and showZigzag)
  489. indexLast = array.get(zigzagindexes, i+1)
  490. valueLast = array.get(zigzagvalues, i+1)
  491. l = line.new(x1=index, y1=value,
  492. x2 = indexLast, y2=valueLast,
  493. // color=labelColor, width=2, style=line.style_solid)
  494. color=labelColor, width=2, style=line.style_dotted)
  495.  
  496. array.unshift(lineArray, l)
  497. if(array.size(lineArray) > 100)
  498. line.delete(array.pop(lineArray))
  499.  
  500.  
  501. // ==== ALERT =====
  502. alertcondition(doubleBottom, "Double Bottom", "Probable double bottom observed for {{ticker}} on {{interval}} timeframe")
  503. alertcondition(doubleBottomConfirmation > 0, "Double Bottom Confirmation", "Double bottom confirmation observed for {{ticker}} on {{interval}} timeframe")
  504. alertcondition(doubleBottomConfirmation < 0, "Double Bottom Invalidation", "Double bottom invalidation observed for {{ticker}} on {{interval}} timeframe")
  505. alertcondition(doubleTop, "Double Top", "Probable double top observed for {{ticker}} on {{interval}} timeframe")
  506. alertcondition(doubleTopConfirmation > 0, "Double Top Confirmation", "Double top confirmation observed for {{ticker}} on {{interval}} timeframe")
  507. alertcondition(doubleTopConfirmation < 0, "Double Top Invalidation", "Double top invalidation observed for {{ticker}} on {{interval}} timeframe")
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement