Advertisement
xmd79

Ultimate Cypher A

Jun 23rd, 2022
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.17 KB | None | 0 0
  1.  
  2. //@version=5
  3. indicator('Ultimate Cypher A', overlay=true, max_bars_back=1000, max_lines_count=500, max_labels_count=500,max_boxes_count=500)
  4. import HeWhoMustNotBeNamed/eHarmonicpatternsExtended/3 as hp
  5. import HeWhoMustNotBeNamed/arrayutils/17 as pa
  6. import HeWhoMustNotBeNamed/mZigzag/5 as zigzag
  7. import HeWhoMustNotBeNamed/_matrix/2 as ma
  8. avoidOverlap = input.bool(false, 'Suppress Overlap', group='Generic')
  9. var themeColors =array.from(
  10. color.rgb(251, 244, 109),
  11. color.rgb(141, 186, 81),
  12. color.rgb(74, 159, 245),
  13. color.rgb(255, 153, 140),
  14. color.rgb(255, 149, 0),
  15. color.rgb(0, 234, 211),
  16. color.rgb(167, 153, 183),
  17. color.rgb(255, 210, 113),
  18. color.rgb(119, 217, 112),
  19. color.rgb(95, 129, 228),
  20. color.rgb(235, 146, 190),
  21. color.rgb(198, 139, 89),
  22. color.rgb(200, 149, 149),
  23. color.rgb(196, 182, 182),
  24. color.rgb(255, 190, 15),
  25. color.rgb(192, 226, 24),
  26. color.rgb(153, 140, 235),
  27. color.rgb(206, 31, 107),
  28. color.rgb(251, 54, 64),
  29. color.rgb(194, 255, 217),
  30. color.rgb(255, 219, 197),
  31. color.rgb(121, 180, 183)
  32. )
  33.  
  34. depthhh=input.int(10, title='depth', group='Zigzag')
  35. showZigZag1 = input.bool(true, title='L1', group='Zigzag', inline='z1')
  36. zigzag1Length = input.int(5, step=5, minval=3, title='', group='Zigzag', inline='z1')
  37.  
  38. showZigZag2 = input.bool(true, title='L2', group='Zigzag', inline='z1')
  39. zigzag2Length = input.int(8, step=5, minval=3, title='', group='Zigzag', inline='z1')
  40.  
  41. showZigZag3 = input.bool(true, title='L3', group='Zigzag', inline='z2')
  42. zigzag3Length = input.int(13, step=5, minval=3, title='', group='Zigzag', inline='z2')
  43.  
  44. showZigZag4 = input.bool(true, title='L4', group='Zigzag', inline='z2')
  45. zigzag4Length = input.int(21, step=5, minval=3, title='', group='Zigzag', inline='z2')
  46.  
  47.  
  48. showTAG=input(true, title='Show TAG', group='Display')
  49. showXABCD = input.bool(false, title='Show XABCD', group='Display', inline='showHide')
  50. showRatios = input.bool(true, title='Show Ratios', group='Display', inline='showHide')
  51.  
  52. fillMajorTriangles = input.bool(true, title="Fill XAB/BCD", group="Display", inline="fill1")
  53. majorFillTransparency = input.int(90, step=5, title="", group="Display", inline="fill1")
  54.  
  55. showPRZ=input(false,group='Miscellaneous')
  56. errorPercent = input.int(8, group="Miscellaneous")
  57. przType = input.string("XAD Range", "PRZ Type", options=["XAD Range", "BCD+XAD Range"], group='Miscellaneous')
  58. useCombinedPrz = (przType == "BCD+XAD Range")
  59.  
  60. classic = input.bool(true, title="Classic Patterns", group="Category", inline="ca")
  61. anti = input.bool(true, title="Anti/Alternate Patterns", group="Category", inline="ca")
  62. nonStandard = input.bool(true, title="Nonstandard", group="Category", inline="ca")
  63.  
  64. gartley = input.bool(true, title='Gartley       ', group='Classic Patterns', inline="c1")
  65. bat = input.bool(true, title='Bat      ', group='Classic Patterns', inline="c1")
  66. butterfly = input.bool(true, title='Butterfly   ', group='Classic Patterns', inline="c1")
  67. crab = input.bool(true, title='Crab', group='Classic Patterns', inline="c1")
  68. deepCrab = input.bool(true, title='Deep Crab   ', group='Classic Patterns', inline="c2")
  69. cypher = input.bool(true, title='Cypher   ', group='Classic Patterns', inline="c2")
  70. shark = input.bool(true, title='Shark      ', group='Classic Patterns', inline="c2")
  71. nenStar = input.bool(true, title='Nenstar', group='Classic Patterns', inline="c2")
  72.  
  73. antiNenStar = input.bool(true, title='Anti Nenstar   ', group='Anti Patterns', inline="a1")
  74. antiShark = input.bool(true, title='Anti Shark', group='Anti Patterns', inline="a1")
  75. antiCypher = input.bool(true, title='Anti Cypher ', group='Anti Patterns', inline="a1")
  76. antiCrab = input.bool(true, title='Anti Crab', group='Anti Patterns', inline="a1")
  77. antiButterfly = input.bool(true, title='Anti Butterfly', group='Anti Patterns', inline="a2")
  78. antiBat = input.bool(true, title='Anti Bat  ', group='Anti Patterns', inline="a2")
  79. antiGartley = input.bool(true, title='Anti Gartley', group='Anti Patterns', inline="a2")
  80. navarro200 = input.bool(true, title='Navarro 200', group='Anti Patterns', inline="a2")
  81.  
  82. fiveZero = input.bool(true, title='Five Zero', group='Non Standard', inline="a1")
  83. threeDrives = input.bool(true, title='Three Drives', group='Non Standard', inline="a1")
  84. whiteSwann = input.bool(true, title='White Swann', group='Non Standard', inline="a1")
  85. blackSwann = input.bool(true, title='Black Swann', group='Non Standard', inline="a1")
  86. seaPony = input.bool(true, title='Sea Pony', group='Non Standard', inline="a2")
  87. leonardo = input.bool(true, title='Leonardo', group='Non Standard', inline="a2")
  88. oneTwoOne = input.bool(true, title='121', group='Non Standard', inline="a2")
  89. snorm = input.bool(true, title='Snorm', group='Non Standard', inline="a2")
  90. totalPattern = input.bool(false, title='Total', group='Non Standard', inline="a2")
  91.  
  92. NUMBER_OF_PATTERNS = 25
  93. var pivotBarMatrix = matrix.new<int>()
  94. enableGartley = classic and gartley
  95. enableBat = classic and bat
  96. enableButterfly = classic and butterfly
  97. enableCrab = classic and crab
  98. enableDeepCrab = classic and deepCrab
  99. enableCypher = classic and cypher
  100. enableShark = classic and shark
  101. enableNenStar = classic and nenStar
  102.  
  103. enableAntiNenStar = anti and antiNenStar
  104. enableAntiShark = anti and antiShark
  105. enableAntiCypher = anti and antiCypher
  106. enableAntiCrab = anti and antiCrab
  107. enableAntiButterfly = anti and antiButterfly
  108. enableAntiBat = anti and antiBat
  109. enableAntiGartley = anti and antiGartley
  110. enableNavarro200 = anti and navarro200
  111. enableFiveZero = nonStandard and fiveZero
  112. enableThreeDrives = nonStandard and threeDrives
  113. enableWhiteSwann = nonStandard and whiteSwann
  114. enableBlackSwann = nonStandard and blackSwann
  115. enableSeaPony = nonStandard and seaPony
  116. enableLeonardo = nonStandard and leonardo
  117. enableOneTwoOne = nonStandard and oneTwoOne
  118. enableSnorm = nonStandard and snorm
  119. enableTotal = nonStandard and totalPattern
  120.  
  121.  
  122.  
  123. var zigzagpivots1 = array.new_float(0)
  124. var zigzagpivotbars1 = array.new_int(0)
  125. var zigzagpivotdirs1 = array.new_int(0)
  126.  
  127. var zigzagpivots2 = array.new_float(0)
  128. var zigzagpivotbars2 = array.new_int(0)
  129. var zigzagpivotdirs2 = array.new_int(0)
  130.  
  131. var zigzagpivots3 = array.new_float(0)
  132. var zigzagpivotbars3 = array.new_int(0)
  133. var zigzagpivotdirs3 = array.new_int(0)
  134.  
  135. var zigzagpivots4 = array.new_float(0)
  136. var zigzagpivotbars4 = array.new_int(0)
  137. var zigzagpivotdirs4 = array.new_int(0)
  138.  
  139. var wmlines1 = array.new_line(8)
  140. var wmtype1 = array.new_int(2, 1)
  141. var wmLabels1 = array.new_bool(21, false)
  142. var wmLabel1 = array.new_label(1)
  143.  
  144. var wmlines2 = array.new_line(8)
  145. var wmtype2 = array.new_int(2, 1)
  146. var wmLabels2 = array.new_bool(21, false)
  147. var wmLabel2 = array.new_label(1)
  148.  
  149. var wmlines3 = array.new_line(8)
  150. var wmtype3 = array.new_int(2, 1)
  151. var wmLabels3 = array.new_bool(21, false)
  152. var wmLabel3 = array.new_label(1)
  153.  
  154. var wmlines4 = array.new_line(8)
  155. var wmtype4 = array.new_int(2, 1)
  156. var wmLabels4 = array.new_bool(21, false)
  157. var wmLabel4 = array.new_label(1)
  158.  
  159.  
  160.  
  161. flags = array.new_bool()
  162. array.push(flags, enableGartley)
  163. array.push(flags, enableCrab)
  164. array.push(flags, enableDeepCrab)
  165. array.push(flags, enableBat)
  166. array.push(flags, enableButterfly)
  167. array.push(flags, enableShark)
  168. array.push(flags, enableCypher)
  169. array.push(flags, enableNenStar)
  170.  
  171. array.push(flags, enableAntiNenStar)
  172. array.push(flags, enableAntiShark)
  173. array.push(flags, enableAntiCypher)
  174. array.push(flags, enableAntiCrab)
  175. array.push(flags, enableAntiButterfly)
  176. array.push(flags, enableAntiBat)
  177. array.push(flags, enableAntiGartley)
  178. array.push(flags, enableNavarro200)
  179.  
  180. array.push(flags, enableFiveZero)
  181. array.push(flags, enableThreeDrives)
  182. array.push(flags, enableWhiteSwann)
  183. array.push(flags, enableBlackSwann)
  184. array.push(flags, enableSeaPony)
  185. array.push(flags, enableLeonardo)
  186. array.push(flags, enableOneTwoOne)
  187. array.push(flags, enableSnorm)
  188. array.push(flags, enableTotal)
  189.  
  190.  
  191.  
  192. maxPatternsReference = 10
  193.  
  194. var aBarArray = array.new_int()
  195. var bBarArray = array.new_int()
  196. var cBarArray = array.new_int()
  197. var dBarArray = array.new_int()
  198. var xBarArray = array.new_int()
  199.  
  200. get_prz_range(x, a, b, c, patterns, errorPercent, prc_entry=0, prc_stop=0)=>
  201. [boxStart, boxEnd] = if useCombinedPrz
  202. hp.get_prz_range(x, a, b, c, patterns, errorPercent, prc_entry, prc_stop)
  203. else
  204. hp.get_prz_range_xad(x, a, b, c, patterns, errorPercent, prc_entry, prc_stop)
  205. [boxStart, boxEnd]
  206.  
  207. f_draw_entry_box(y1, y2, x1, linecolor, labelColor, labelText) =>
  208. x2 = x1 + 20
  209. y = (y1 + y2) / 2
  210. xloc = xloc.bar_index
  211. transp = 85
  212. entryBox = box.new(x1, y1, x2, y2, linecolor, 1, line.style_dotted, xloc=xloc, bgcolor=color.new(labelColor, transp), text=labelText,
  213. text_color=color.white, text_size=size.small)
  214. entryBox
  215.  
  216. f_draw_pattern_line(y1, y2, x1, x2, lineColor, width, style) =>
  217. targetLine = line.new(y1=y1, y2=y2, x1=x1, x2=x2, color=lineColor, width=width, style=style)
  218. targetLine
  219.  
  220. f_draw_pattern_label(y, x, txt, textcolor, style, yloc, size) =>
  221. targetLabel = label.new(y=y, x=x, text=txt, textcolor=textcolor, style=style, yloc=yloc, size=size)
  222. targetLabel
  223.  
  224. draw_xabcd(x, a, b, c, d, xBar, aBar, bBar, cBar, dBar, dir, labelColor, patterns) =>
  225. hasPatterns = array.includes(patterns, true),
  226. isCypher = array.get(patterns, 6)
  227. if(hasPatterns)
  228. gap = ta.tr/10
  229. xLabel = showXABCD?f_draw_pattern_label(y=(dir>0?x-gap:x+gap), x=xBar, txt='X', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  230. aLabel = showXABCD?f_draw_pattern_label(y=(dir>0?a+gap:a-gap), x=aBar, txt='A', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  231. bLabel = showXABCD?f_draw_pattern_label(y=(dir>0?b-gap:b+gap), x=bBar, txt='B', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  232. cLabel = showXABCD?f_draw_pattern_label(y=(dir>0?c+gap:c-gap), x=cBar, txt='C', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  233. dLabel = showXABCD?f_draw_pattern_label(y=(dir>0?d-gap:d+gap), x=dBar, txt='D', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  234. xabRatio = math.round(math.abs(a - b) / math.abs(x - a), 3)
  235. xabRatioBar = (xBar + bBar) / 2
  236.  
  237. abcRatio = math.round(math.abs(b - c) / math.abs(a - b), 3)
  238. abcRatioBar = (aBar + cBar) / 2
  239.  
  240. bcdRatio = math.round(math.abs(c - d) / math.abs(b - c), 3)
  241. bcdRatioBar = (bBar + dBar) / 2
  242.  
  243. xadRatio = math.round(math.abs(a - d) / math.abs(x - a), 3)
  244. xadRatioBar = (xBar + dBar) / 2
  245.  
  246. axcRatio = math.round(math.abs(x - c) / math.abs(x - a), 3)
  247. xcdRatio = math.round(math.abs(d - c) / math.abs(x - c), 3)
  248.  
  249. xabRatioPrice = (x+b)/2
  250. abcRatioPrice = (a+c)/2
  251. bcdRatioPrice = (b+d)/2
  252. xadRatioPrice = (x+d)/2
  253.  
  254. abcRatioLabelText = str.tostring(abcRatio) + '(ABC)' + (isCypher ? '\n' + str.tostring(axcRatio) + '(AXC)' : '')
  255. xadRatioLabelText = str.tostring(xadRatio) + '(XAD)' + (isCypher ? '\n' + str.tostring(xcdRatio) + '(XCD)' : '')
  256. xabLabel = showRatios and showXABCD?f_draw_pattern_label(y=xabRatioPrice, x=xabRatioBar, txt=str.tostring(xabRatio) + '(XAB)', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  257. abcLabel = showRatios and showXABCD?f_draw_pattern_label(y=abcRatioPrice, x=abcRatioBar, txt=abcRatioLabelText, textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  258. bcdLabel = showRatios and showXABCD?f_draw_pattern_label(y=bcdRatioPrice, x=bcdRatioBar, txt=str.tostring(bcdRatio) + '(BCD)', textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  259. xadLabel = showRatios and showXABCD?f_draw_pattern_label(y=xadRatioPrice, x=xadRatioBar, txt=xadRatioLabelText, textcolor=color.white, style=label.style_none, yloc=yloc.price, size=size.small):na
  260.  
  261. xa = showXABCD?f_draw_pattern_line(y1=x, y2=a, x1=xBar, x2=aBar, lineColor=labelColor, width=1, style=line.style_solid):na
  262. ab = showXABCD?f_draw_pattern_line(y1=a, y2=b, x1=aBar, x2=bBar, lineColor=labelColor, width=1, style=line.style_solid):na
  263. bc = showXABCD?f_draw_pattern_line(y1=b, y2=c, x1=bBar, x2=cBar, lineColor=labelColor, width=1, style=line.style_solid):na
  264. cd = showXABCD?f_draw_pattern_line(y1=c, y2=d, x1=cBar, x2=dBar, lineColor=labelColor, width=1, style=line.style_solid):na
  265. xb = showXABCD?f_draw_pattern_line(y1=x, y2=b, x1=xBar, x2=bBar, lineColor=labelColor, width=1, style=line.style_dashed):na
  266. bd = showXABCD?f_draw_pattern_line(y1=b, y2=d, x1=bBar, x2=dBar, lineColor=labelColor, width=1, style=line.style_dashed):na
  267. ac = showXABCD?f_draw_pattern_line(y1=a, y2=c, x1=aBar, x2=cBar, lineColor=labelColor, width=1, style=line.style_dotted):na
  268. xd = showXABCD?f_draw_pattern_line(y1=x, y2=d, x1=xBar, x2=dBar, lineColor=labelColor, width=1, style=line.style_dotted):na
  269.  
  270. if(fillMajorTriangles and hasPatterns)
  271. xaab = linefill.new(xa, ab, color.new(labelColor, majorFillTransparency))
  272. xbab = linefill.new(xb, ab, color.new(labelColor, majorFillTransparency))
  273. bccd = linefill.new(bc, cd, color.new(labelColor, majorFillTransparency))
  274. bdcd = linefill.new(bd, cd, color.new(labelColor, majorFillTransparency))
  275. [xa,ab,bc,cd,xb,bd,ac,xd,xLabel,aLabel,bLabel,cLabel,dLabel,xabLabel,abcLabel,bcdLabel,xadLabel]
  276.  
  277.  
  278. patternLabels = hp.getSupportedPatterns()
  279.  
  280. find_pattern(zigzagpivots, zigzagpivotbars, startIndex, lastDir, x, a, b, c, d,
  281. xBar, aBar, bBar, cBar, dBar)=>
  282. existingPattern=false
  283. patterns = hp.isHarmonicPattern(x, a, b, c, d, flags, errorPercent = errorPercent)
  284. basicCondition = array.includes(patterns,true)
  285. for i=0 to matrix.rows(pivotBarMatrix) > 0? matrix.rows(pivotBarMatrix)-1 : na
  286. commonPivotsCount = (xBar == matrix.get(pivotBarMatrix, i, 0) ? 1 : 0) +
  287. (aBar == matrix.get(pivotBarMatrix, i, 1) ? 1 : 0) +
  288. (bBar == matrix.get(pivotBarMatrix, i, 2) ? 1 : 0) +
  289. (cBar == matrix.get(pivotBarMatrix, i, 3) ? 1 : 0) +
  290. (dBar == matrix.get(pivotBarMatrix, i, 4) ? 1 : 0)
  291.  
  292. if ( commonPivotsCount >=3 ) or (avoidOverlap and xBar >= matrix.get(pivotBarMatrix, i, 0) and xBar <= matrix.get(pivotBarMatrix, i, 4))
  293. existingPattern := true
  294. break
  295.  
  296. if(not existingPattern)
  297. zgColor = array.pop(themeColors)
  298. array.unshift(themeColors, zgColor)
  299. if(basicCondition)
  300. lbl = pa.getLabel(patterns, patternLabels)
  301. [xa,ab,bc,cd,xb,bd,ac,xd,xLabel,aLabel,bLabel,cLabel,dLabel,xabLabel,abcLabel,bcdLabel,xadLabel]=draw_xabcd(x, a, b, c, d, xBar, aBar, bBar, cBar, dBar, lastDir, zgColor, patterns)
  302. [dStart, dEnd] = get_prz_range(x, a, b, c, patterns, errorPercent)
  303. boxxx=showPRZ?f_draw_entry_box(dStart, dEnd, dBar+5, zgColor, zgColor, lbl):na
  304. dir=c-d>0?1:-1
  305. if(dir==1 and close<dEnd) or (dir==-1 and close>dStart)
  306. line.delete(xa)
  307. line.delete(ab)
  308. line.delete(bc)
  309. line.delete(cd)
  310. line.delete(xb)
  311. line.delete(bd)
  312. line.delete(ac)
  313. line.delete(xd)
  314. label.delete(xLabel)
  315. label.delete(aLabel)
  316. label.delete(bLabel)
  317. label.delete(cLabel)
  318. label.delete(dLabel)
  319. label.delete(xabLabel)
  320. label.delete(abcLabel)
  321. label.delete(bcdLabel)
  322. label.delete(xadLabel)
  323. box.delete(boxxx)
  324. if(showTAG)
  325. label.new(y=(c>d?d-ta.tr/5:d+ta.tr/5), x=dBar , color=c>d?color.new(color.green,50):color.new(color.red,50),style=c<d ? label.style_triangledown : label.style_triangleup, size=size.tiny)
  326. scan_patterns(startIndex, newPivot, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, lastdBar)=>
  327. length = array.size(zigzagpivots)
  328. numberOfPivots=5
  329. newLastdBar = lastdBar
  330. if(length >= startIndex+numberOfPivots and newPivot)
  331. d = array.get(zigzagpivots, startIndex)
  332. dBar = array.get(zigzagpivotbars, startIndex)
  333. lastDir = array.get(zigzagpivotdirs, startIndex)
  334. if(dBar!=lastdBar)
  335. newLastdBar := dBar
  336. c = array.get(zigzagpivots, startIndex+1)
  337. cBar = array.get(zigzagpivotbars, startIndex+1)
  338. b = array.get(zigzagpivots, startIndex+2)
  339. bBar = array.get(zigzagpivotbars, startIndex+2)
  340. a = array.get(zigzagpivots, startIndex+3)
  341. aBar = array.get(zigzagpivotbars, startIndex+3)
  342. x = array.get(zigzagpivots, startIndex+4)
  343. xBar = array.get(zigzagpivotbars, startIndex+4)
  344. find_pattern(zigzagpivots, zigzagpivotbars, startIndex, lastDir, x, a, b, c, d,
  345. xBar, aBar, bBar, cBar, dBar)
  346. newLastdBar
  347.  
  348. ohlc = array.from(high, low)
  349. indicatorHigh = array.new<float>()
  350. indicatorLow = array.new<float>()
  351. setup(showZigzag, zigzagLength, zigzagDepth)=>
  352. if showZigzag
  353. [valueMatrix, zigzagpivotdirs, zigzagpivotbars, newPivot, doublePivot] = zigzag.calculateplain(zigzagLength, ohlc, indicatorHigh, indicatorLow, numberOfPivots= zigzagDepth)
  354. var lastABar = 0
  355. if(newPivot)
  356. zigzagpivots = matrix.col(valueMatrix, 0)
  357. lastABar := scan_patterns(1, doublePivot, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, lastABar)
  358. lastABar := scan_patterns(0, newPivot, zigzagpivots, zigzagpivotbars, zigzagpivotdirs, lastABar)
  359.  
  360.  
  361. setup(showZigZag1, zigzag1Length, depthhh)
  362. setup(showZigZag2, zigzag2Length, depthhh)
  363. setup(showZigZag3, zigzag3Length, depthhh)
  364. setup(showZigZag4, zigzag4Length, depthhh)
  365.  
  366. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  367. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  368. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  369. //////////////////TD
  370. TDNumbers = input(true,group='TD')
  371. TD = 0.0
  372. TS = 0.0
  373. TD := close > close[4] ? nz(TD[1]) + 1 : 0
  374. TS := close < close[4] ? nz(TS[1]) + 1 : 0
  375. TDUp = 0.0
  376. TDDn = 0.0
  377. TDUp := TD - ta.valuewhen(TD < TD[1], TD, 1)
  378. TDDn := TS - ta.valuewhen(TS < TS[1], TS, 1)
  379. plotshape(TDNumbers ? TDUp == 9 ? true : na : na, style=shape.cross, text='9', color=color.white, location=location.abovebar, size =size.small,textcolor=color.white,title='TD Up9')
  380. plotshape(TDNumbers ? TDUp == 13 ? true : na : na, style=shape.cross, text='13', color=color.white, location=location.abovebar, size =size.small,textcolor=color.white,title='TD Up13')
  381. plotshape(TDNumbers ? TDDn == 9 ? true : na : na, style=shape.cross, text='9', color=color.white, location=location.belowbar, size =size.small,textcolor=color.white,title='TD Dn9')
  382. plotshape(TDNumbers ? TDDn == 13 ? true : na : na, style=shape.cross, text='13', color=color.white, location=location.belowbar, size =size.small,textcolor=color.white,title='TD Dn13')
  383. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  384. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  385. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  386. //vegas
  387. vegas=input.bool(true,group='vegas channel')
  388. EMA144=ta.ema(close,144)
  389. EMA169=ta.ema(close,169)
  390. EMA288=ta.ema(close,288)
  391. EMA338=ta.ema(close,338)
  392. plot(vegas?EMA144:na,color=#00bcd4,linewidth=3,title='EMA144')
  393. plot(vegas?EMA169:na,color=#426eea,linewidth=3,title='EMA169')
  394. plot(vegas?EMA288:na,color=#d250e9,linewidth=3,title='EMA288')
  395. plot(vegas?EMA338:na,color=#673ab7,linewidth=3,title='EMA338')
  396.  
  397. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  398. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  399. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  400. //atrStopLoss
  401. showATRStopLoss=input.bool(false,group='atrStopLoss')
  402. atrlength = input.int(title='atr length', defval=14, minval=1,group='atrStopLoss')
  403. lookbackForStopLoss = input.int(title='how far to look back for high/lows', defval=8, minval=1,group='atrStopLoss')
  404. atrstopmultiplier = input.float(title='atr x ?', defval=1.0, minval=0.1,group='atrStopLoss')
  405. //calculate data
  406. money=input(title='资金量', defval=10000,group='atrStopLoss')
  407. atr = ta.atr(atrlength)
  408. realatr = atr * atrstopmultiplier
  409. longstop = (ta.lowest(low, lookbackForStopLoss)) - realatr
  410. shortstop = (ta.highest(high, lookbackForStopLoss)) + realatr
  411. MK=high-low
  412. ll=MK<atr?longstop:MK>atr and MK<2*atr?longstop-realatr:MK>2*atr?longstop-2*realatr:na
  413. ss=MK<atr?shortstop:MK>atr and MK<2*atr?shortstop+realatr:MK>2*atr?shortstop+2*realatr:na
  414. plot(showATRStopLoss?ll:na,color=MK<atr?color.green:MK>atr and MK<2*atr?color.yellow:MK>2*atr?color.red:na,style=plot.style_stepline,title='atrStop')
  415. plot(showATRStopLoss?ss:na,color=MK<atr?color.green:MK>atr and MK<2*atr?color.yellow:MK>2*atr?color.red:na,style=plot.style_stepline,title='atrStop')
  416. var testTable = table.new(position = position.bottom_right, columns = 1, rows = 5, border_width = 1)
  417. lp=money*0.025/(close-ll)
  418. sp=money*0.025/(ss-close)
  419. Tl=0.0125*money/lp+close
  420. Ts=close-0.0125*money/sp
  421. if showATRStopLoss
  422. table.cell(table_id = testTable, column = 0, row = 0, text = "ATR " + str.tostring(math.round(atr, 1)),bgcolor = color.new(color.yellow,10))
  423. table.cell(table_id = testTable, column = 0, row = 1, text = str.tostring(math.round(Tl))+"mt" + str.tostring(math.round(lp, 3)),bgcolor = color.new(color.green,10),text_color=color.white)
  424. table.cell(table_id = testTable, column = 0, row = 2, text = str.tostring(math.round(ll))+"---"+str.tostring(math.round(close-ll)),bgcolor = color.new(color.green,10),text_color=color.white)
  425. table.cell(table_id = testTable, column = 0, row = 3, text = str.tostring(math.round(Ts))+"mt" + str.tostring(math.round(sp, 3)), bgcolor = color.new(color.red,10),text_color=color.white)
  426. table.cell(table_id = testTable, column = 0, row = 4, text = str.tostring(math.round(ss))+"---"+str.tostring(math.round(ss-close)), bgcolor = color.new(color.red,10),text_color=color.white)
  427.  
  428. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  429. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  430. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  431. //HTF LIQ
  432.  
  433. var START_OFFSET = 0
  434. var END_OFFSET = 25
  435. var PURGED_COLOR = color.gray
  436. var PURGED_STYLE = line.style_dotted
  437. var g_indicator = "Liquidity"
  438. i_isDailyEnabled = input (true, "Daily", inline="Daily", group=g_indicator)
  439. i_dailyAboveLiquidityColor = input (color.new(#4caf50, 30), "", inline="Daily", group=g_indicator)
  440. i_dailyBelowLiquidityColor = input (color.new(#f23645, 30), "", inline="Daily", group=g_indicator)
  441. i_dailyWidth = input (3, "Width", inline="Daily", group=g_indicator)
  442. i_isWeeklyEnabled = input (true, "Weekly", inline="Weekly", group=g_indicator)
  443. i_weelyAboveLiquidityColor = input (color.new(#ffeb3b, 50), "", inline="Weekly", group=g_indicator)
  444. i_weelyBelowLiquidityColor = input (color.new(#ffeb3b, 50), "", inline="Weekly", group=g_indicator)
  445. i_weeklyWidth = input (10, "Width", inline="Weekly", group=g_indicator)
  446. i_isMonthlyEnabled = input (true, "Monthly", inline="Monthly", group=g_indicator)
  447. i_monthlyAboveLiquidityColor = input (color.new(#00bcd4, 50), "", inline="Monthly", group=g_indicator)
  448. i_monthlyBelowLiquidityColor = input (color.new(#00bcd4, 50), "", inline="Monthly", group=g_indicator)
  449. i_monthlyWidth = input (20, "Width", inline="Monthly", group=g_indicator)
  450. var highsArray = array.new_float()
  451. var lowsArray = array.new_float()
  452. var highLinesArray = array.new_line()
  453. var lowLinesArray = array.new_line()
  454. var float dayHigh = na
  455. var float dayLow = na
  456. [prevDayHigh, prevDayLow] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead=barmerge.lookahead_on)
  457. [prevWeekHigh, prevWeekLow] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead=barmerge.lookahead_on)
  458. [prevMonthHigh, prevMonthLow] = request.security(syminfo.tickerid, "M", [high[1], low[1]], lookahead=barmerge.lookahead_on)
  459.  
  460. f_drawLine(float _y, color _c, int _w=1) => line.new(bar_index, _y, bar_index, _y, color=_c, width=_w)
  461. f_create(float _high, float _low, color _upperColor, color _lowerColor, int _linewidth) =>
  462. array.push(highsArray, _high)
  463. array.push(lowsArray, _low)
  464. array.push(highLinesArray, f_drawLine(_high, _upperColor, _linewidth))
  465. array.push(lowLinesArray, f_drawLine(_low, _lowerColor, _linewidth))
  466. f_update(array<line> _levels) =>
  467. for _line in _levels
  468. line.set_x1(_line, bar_index + START_OFFSET)
  469. line.set_x2(_line, bar_index + END_OFFSET)
  470. f_cleanUpperLevels(float _high, array<float> _highs, array<line> _levels) =>
  471. while array.min(_highs) < _high
  472. for [_index, _value] in _highs
  473. if _high > _value
  474. line.delete(array.remove(_levels, _index))
  475. array.remove(_highs, _index)
  476. f_cleanLowerLevels(float _low, array<float> _lows, array<line> _levels) =>
  477. while array.max(_lows) > _low
  478. for [_index, _value] in _lows
  479. if _low < _value
  480. line.delete(array.remove(_levels, _index))
  481. array.remove(_lows, _index)
  482. f_highlightUpperLevels(float _high, array<float> _highs, array<line> _levels) =>
  483. for [_index, _value] in _highs
  484. if _high > _value
  485. _line = array.get(_levels, _index)
  486. line.set_color(_line, PURGED_COLOR)
  487. line.set_style(_line, PURGED_STYLE)
  488. f_highlightLowerLevels(float _low, array<float> _lows, array<line> _levels) =>
  489. for [_index, _value] in _lows
  490. if _low < _value
  491. _line = array.get(_levels, _index)
  492. line.set_color(_line, PURGED_COLOR)
  493. line.set_style(_line, PURGED_STYLE)
  494.  
  495. if i_isDailyEnabled and ta.change(time("D"))
  496. f_create(prevDayHigh, prevDayLow, i_dailyAboveLiquidityColor, i_dailyBelowLiquidityColor, i_dailyWidth)
  497.  
  498. if i_isWeeklyEnabled and ta.change(time("W"))
  499. f_create(prevWeekHigh, prevWeekLow, i_weelyAboveLiquidityColor, i_weelyBelowLiquidityColor, i_weeklyWidth)
  500.  
  501. if i_isMonthlyEnabled and ta.change(time("M"))
  502. f_create(prevMonthHigh, prevMonthLow, i_monthlyAboveLiquidityColor, i_monthlyBelowLiquidityColor, i_monthlyWidth)
  503. if barstate.islast
  504. f_update(highLinesArray)
  505. f_update(lowLinesArray)
  506. if ta.change(time("D"))
  507. dayHigh := high
  508. dayLow := low
  509.  
  510. if high > dayHigh
  511. dayHigh := high
  512.  
  513. if low < dayLow
  514. dayLow := low
  515.  
  516. if barstate.islast
  517. f_highlightUpperLevels(dayHigh, highsArray, highLinesArray)
  518. f_highlightLowerLevels(dayLow, lowsArray, lowLinesArray)
  519. if ta.change(time("D"))
  520. f_cleanUpperLevels(prevDayHigh, highsArray, highLinesArray)
  521. f_cleanLowerLevels(prevDayLow, lowsArray, lowLinesArray)
  522.  
  523. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  524. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  525. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  526.  
  527. plotOB = input.bool(defval=true, title='Plot OB', group='Order Blocks')
  528. obBullColor = input.color(defval=color.new(#4caf50, 30), title='Bullish OB Color', inline='Set Custom Color', group='Order Blocks')
  529. obBearColor = input.color(defval=color.new(#ec407a, 30), title='Bearish OB Color', inline='Set Custom Color', group='Order Blocks')
  530. obBoxBorder = input.string(defval=line.style_solid, title='OB Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Order Blocks', tooltip='To disable border, set Border Width below to 0')
  531. obBorderTransparency = input.int(defval=80, title='OB Border Box Transparency', minval=0, maxval=100, group='Order Blocks')
  532. obMaxBoxSet = input.int(defval=10, title='Maximum OB Box Displayed', minval=1, maxval=100, group='Order Blocks', tooltip='Minimum = 1, Maximum = 100')
  533. filterMitOB = input.bool(defval=true, title='Custom Color Mitigated OB', group='Order Blocks')
  534. mitOBColor = input.color(defval=color.new(#9598a1, 50), title='Mitigated OB Color', group='Order Blocks', inline='Set Custom Color Mit OB', tooltip='Set Transparency to 0 to make mitigated OB disappear')
  535.  
  536. plotFVG = input.bool(defval=true, title='Plot FVG', group='Fair Value Gaps', inline='FVG sets')
  537. plotStructureBreakingFVG = input.bool(defval=false, title='Plot Structure Breaking FVG', group='Fair Value Gaps', inline='FVG sets')
  538. fvgBullColor = input.color(defval=color.new(#ffeb3b, 85), title='Bullish FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
  539. fvgBearColor = input.color(defval=color.new(#ffeb3b, 85), title='Bearish FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
  540. fvgStructBreakingColor = input.color(defval=color.new(#ffeb3b, 50), title='Structure Breaking FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
  541. fvgBoxBorder = input.string(defval=line.style_solid, title='FVG Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Fair Value Gaps', tooltip='To disable border, set Border Width below to 0')
  542. fvgBorderTransparency = input.int(defval=80, title='FVG Border Box Transparency', minval=0, maxval=100, group='Fair Value Gaps')
  543. fvgMaxBoxSet = input.int(defval=10, title='Maximum FVG Box Displayed', minval=1, maxval=100, group='Fair Value Gaps', tooltip='Minimum = 1, Maximum = 100')
  544. filterMitFVG = input.bool(defval=true, title='Custom Color Mitigated FVG', group='Fair Value Gaps')
  545. mitFVGColor = input.color(defval=color.new(color.gray, 100), title='Mitigated FVG Color', group='Fair Value Gaps', inline='Set Custom Color Mit FVG', tooltip='Set Transparency to 0 to make mitigated FVG disappear')
  546.  
  547. plotRJB = input.bool(defval=true, title='Plot RJB', group='Rejection Blocks', inline='RJB sets')
  548. rjbBullColor = input.color(defval=color.new(#00bcd4, 30), title='Bullish RJB Color', inline='Set Custom Color', group='Rejection Blocks')
  549. rjbBearColor = input.color(defval=color.new(#f23645, 30), title='Bearish RJB Color', inline='Set Custom Color', group='Rejection Blocks')
  550. rjbBoxBorder = input.string(defval=line.style_solid, title='RJB Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Rejection Blocks', tooltip='To disable border, set Border Width below to 0')
  551. rjbBorderTransparency = input.int(defval=80, title='RJB Border Box Transparency', minval=0, maxval=100, group='Rejection Blocks')
  552. rjbMaxBoxSet = input.int(defval=10, title='Maximum RJB Box Displayed', minval=1, maxval=100, group='Rejection Blocks', tooltip='Minimum = 1, Maximum = 100')
  553. filterMitRJB = input.bool(defval=true, title='Custom Color Mitigated RJB', group='Rejection Blocks')
  554. mitRJBColor = input.color(defval=color.new(#512da8, 10), title='Mitigated RJB Color', group='Rejection Blocks', inline='Set Custom Color Mit RJB', tooltip='Set to 100 to make mitigated RJB disappear')
  555.  
  556. plotPVT = input.bool(defval=false, title='Plot Pivots', group='Pivots')
  557. pivotLookup = input.int(defval=1, minval=1, maxval=5,title='Pivot Lookup', group='Pivots', tooltip='Minimum = 1, Maximum = 5')
  558. pvtTopColor = input.color(defval=color.new(color.silver, 0), title='Pivot Top Color', group='Pivots', inline='PVT Color')
  559. pvtBottomColor = input.color(defval=color.new(color.silver, 0), title='Pivot Bottom Color', group='Pivots', inline='PVT Color')
  560.  
  561. plotBOS = input.bool(defval=false, title='Plot BoS', group='Crossovers', inline='BOS sets')
  562. useHighLowForBullishBoS = input.bool(defval=true, title='Use High/Low for Bullish BoS (for Bearish setup)', group='Crossovers')
  563. useHighLowForBearishBoS = input.bool(defval=true, title='Use High/Low for Bearish BoS (for Bullish setup)', group='Crossovers')
  564. bosBoxFlag = input.bool(title='BoS Box Length Manually', defval=false, group='Crossovers', tooltip='If activated the BoS Boxes will not extend unitl crossed by price. Instead will extend by the amount of bars choosen in the "Set BoS Box Length Manually" option')
  565. bosBoxLength = input.int(title='BoS Box Length Manually', defval=3, minval=1, maxval=5, group='Crossovers', inline='BoS Boxes', tooltip='If "Set BoS Box Length Manually" is marked, choose by how many bars. Minimum = 1, Maximum = 5')
  566. bosBullColor = input.color(defval=color.new(color.green, 90), title='Bullish BoS Color', inline='Set Custom Color', group='Crossovers')
  567. bosBearColor = input.color(defval=color.new(color.red, 90), title='Bearish BoS Color', inline='Set Custom Color', group='Crossovers')
  568. bosBoxBorder = input.string(defval=line.style_solid, title='BoS Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Crossovers', tooltip='To disable border, set Border Width below to 0')
  569. bosBorderTransparency = input.int(defval=80, title='BoS Border Box Transparency', minval=0, maxval=100, group='Crossovers')
  570. bosMaxBoxSet = input.int(defval=10, title='Maximum BoS Box Displayed', minval=1, maxval=100, group='Crossovers', tooltip='Minimum = 1, Maximum = 100')
  571.  
  572. plotHVB = input.bool(defval=false, title='Plot HVB', group='High Volume Bar', tooltip='A candle where the average volume is higher than last few bars.')
  573. hvbBullColor = input.color(defval=color.green, title='Bullish HVB Color', inline='Set Custom Color', group='High Volume Bar')
  574. hvbBearColor = input.color(defval=color.red, title='Bearish HVB Color', inline='Set Custom Color', group='High Volume Bar')
  575. hvbEMAPeriod = input.int(defval=12, minval=1, title='Volume EMA Period', group='High Volume Bar')
  576. hvbMultiplier = input.float(defval=1.5, title='Volume Multiplier', minval=1, maxval=100, group='High Volume Bar')
  577.  
  578. plotPPDD = input.bool(defval=false, title="Plot PPDD OB's", group='Qualitative indicators', tooltip='Premium Premium Discount Discount (PPDD) is an OB formed after liquidity sweep. It will show up by default as a triangle (Bull ▲ / Bear ▼). Also PPDD1 (by deafult maked with a x-cross ⨯) which is a weak OB formed after liquidity sweep, that fails to completely engulf the high/low, but closes beyond the trapped candles open price.')
  579. ppddBullColor = input.color(defval=color.new(color.green, 0), title="Bullish PPDD OB's Color", group='Qualitative indicators', inline='PPDD Color')
  580. ppddBearColor = input.color(defval=color.new(color.red, 0), title="Bearish PPDD OB's Color", group='Qualitative indicators', inline='PPDD Color')
  581.  
  582. plotOBFVG = input.bool(defval=false, title='Plot Stacked OB+FVG', group='Qualitative indicators', tooltip='Marks the candle (default with a diamond ◆) when an OB & FVG are stacked, showing momentum')
  583. obfvgBullColor = input.color(defval=color.new(color.green, 0), title='Bullish Stacked OB+FVG Color', group='Qualitative indicators', inline='OBFVG Color')
  584. obfvgBearColor = input.color(defval=color.new(color.red, 0), title='Bearish Stacked OB+FVG Color', group='Qualitative indicators', inline='OBFVG Color')
  585.  
  586. plotLabelOB = input.bool(defval=true, title='Plot OB Label', inline='OB label', group='Label Options')
  587. obLabelColor = input.color(defval=color.new(#4dd0e1,0), title='Color', inline='OB label', group='Label Options')
  588. obLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='OB label', group='Label Options')
  589. plotLabelFVG = input.bool(defval=true, title='Plot FVG Label', inline='FVG label', group='Label Options')
  590. fvgLabelColor = input.color(defval=color.new(#e1bee7,0), title='Color', inline='FVG label', group='Label Options')
  591. fvgLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='FVG label', group='Label Options')
  592. plotLabelRJB = input.bool(defval=true, title='Plot RJB Label', inline='RJB label', group='Label Options')
  593. rjbLabelColor = input.color(defval=color.new(#ffffff,0), title='Color', inline='RJB label', group='Label Options')
  594. rjbLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='RJB label', group='Label Options')
  595. plotLabelBOS = input.bool(defval=true, title='Plot BoS Label', inline='BOS label', group='Label Options')
  596. bosLabelColor = input.color(defval=color.new(#ffeb3b,0), title='Color', inline='BOS label', group='Label Options')
  597. bosLabelSize = input.string(defval=size.auto, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='BOS label', group='Label Options')
  598.  
  599. //Box Types
  600. var int _ob = 1
  601. var int _fvg = 2
  602. var int _rjb = 3
  603. var int _bos = 4
  604.  
  605. //Box Labels
  606. var string _obLabel = "OB"
  607. var string _fvgLabel = "FVG"
  608. var string _rjbLabel = "RJB"
  609. var string _bosLabel = "BoS"
  610. var string _plus = "+"
  611. var string _minus = "-"
  612. var string _empty = ""
  613.  
  614. //Box Arrays
  615. var box[] _bearBoxesOB = array.new_box()
  616. var box[] _bullBoxesOB = array.new_box()
  617. var box[] _bearBoxesFVG = array.new_box()
  618. var box[] _bullBoxesFVG = array.new_box()
  619. var box[] _bearBoxesRJB = array.new_box()
  620. var box[] _bullBoxesRJB = array.new_box()
  621. var box[] _bearBoxesBOS = array.new_box()
  622. var box[] _bullBoxesBOS = array.new_box()
  623.  
  624. //Functions
  625. isUp(index) =>
  626. close[index] > open[index]
  627.  
  628. isDown(index) =>
  629. close[index] < open[index]
  630.  
  631. isObUp(index) =>
  632. isDown(index + 1) and isUp(index) and close[index] > high[index + 1]
  633.  
  634. isObDown(index) =>
  635. isUp(index + 1) and isDown(index) and close[index] < low[index + 1]
  636.  
  637. isFvgUp(index) =>
  638. (low[index] > high[index + 2])
  639.  
  640. isFvgDown(index) =>
  641. (high[index] < low[index + 2])
  642.  
  643. //Function to Calculte Box Length
  644. _controlBox(_boxes, _high, _low, _type) =>
  645. if array.size(_boxes) > 0
  646. for i = array.size(_boxes) - 1 to 0 by 1
  647. _box = array.get(_boxes, i)
  648. _boxLow = box.get_bottom(_box)
  649. _boxHigh = box.get_top(_box)
  650. _boxRight = box.get_right(_box)
  651. if bosBoxFlag and _type == _bos
  652. if na or (bar_index + bosBoxLength - 1 == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
  653. box.set_right(_box, bar_index + bosBoxLength - 1)
  654. else if (filterMitOB and _type == _ob) or (filterMitFVG and _type == _fvg) or (filterMitRJB and _type == _rjb)
  655. if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
  656. box.set_right(_box, bar_index + 1)
  657. else
  658. if _type == _ob
  659. box.set_bgcolor(_box, mitOBColor)
  660. box.set_border_color(_box, mitOBColor)
  661. else if _type == _fvg
  662. // box.set_bgcolor(_box, mitFVGColor)
  663. // box.set_border_color(_box, mitFVGColor)
  664. box.delete(_box)
  665. else if _type == _rjb
  666. box.set_bgcolor(_box, mitRJBColor)
  667. box.set_border_color(_box, mitRJBColor)
  668. else
  669. if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
  670. box.set_right(_box, bar_index + 1)
  671.  
  672. //////////////////// Pivots ////////////////////
  673. hih = ta.pivothigh(high, pivotLookup, pivotLookup)
  674. lol = ta.pivotlow(low , pivotLookup, pivotLookup)
  675. top = ta.valuewhen(hih, high[pivotLookup], 0)
  676. bottom = ta.valuewhen(lol, low [pivotLookup], 0)
  677. plot(top, offset=-pivotLookup, linewidth=1, color=(top != top[1] ? na : (plotPVT ? pvtTopColor : na)), title="Pivot Top")
  678. plot(bottom, offset=-pivotLookup, linewidth=1, color=(bottom != bottom[1] ? na : (plotPVT ? pvtBottomColor : na)), title="Pivot Bottom")
  679.  
  680. //////////////////// Order Block //////////////////
  681. //Bullish OB Box Plotting
  682. if isObUp(1) and plotOB
  683. _bullboxOB = box.new(left=bar_index - 2, top=high[2], right=bar_index, bottom=math.min(low[2], low[1]), border_color=color.new(obBullColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBullColor,
  684. text=plotLabelOB ? _obLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
  685. if array.size(_bullBoxesOB) > obMaxBoxSet
  686. box.delete(array.shift(_bullBoxesOB))
  687. array.push(_bullBoxesOB, _bullboxOB)
  688.  
  689. //Bearish OB Box Plotting
  690. if isObDown(1) and plotOB
  691. _bearboxOB = box.new(left=bar_index - 2, top=math.max(high[2], high[1]), right=bar_index, bottom=low[2], border_color=color.new(obBearColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBearColor,
  692. text=plotLabelOB ? _obLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
  693. if array.size(_bearBoxesOB) > obMaxBoxSet
  694. box.delete(array.shift(_bearBoxesOB))
  695. array.push(_bearBoxesOB, _bearboxOB)
  696.  
  697. if plotOB
  698. _controlBox(_bearBoxesOB, high, low, _ob)
  699. _controlBox(_bullBoxesOB, high, low, _ob)
  700.  
  701. //////////////////// Fair Value Gap //////////////////
  702. //Bullish FVG Box Plotting
  703. if isFvgUp(0)
  704. box _bullboxFVG = na
  705. if plotStructureBreakingFVG and (close[1] > top) and (low[1] < top) and (high[2] < top) and (low > top)
  706. _bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index, bottom=high[2], bgcolor=fvgStructBreakingColor, border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
  707. text=plotLabelFVG ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
  708. else if plotFVG
  709. _bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index, bottom=high[2], bgcolor=fvgBullColor, border_color=color.new(fvgBullColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
  710. text=plotLabelFVG ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
  711. if array.size(_bullBoxesFVG) > fvgMaxBoxSet
  712. box.delete(array.shift(_bullBoxesFVG))
  713. array.push(_bullBoxesFVG, _bullboxFVG)
  714.  
  715. //Bearish FVG Box Plotting
  716. if isFvgDown(0)
  717. box _bearboxFVG = na
  718. if plotStructureBreakingFVG and (close[1] < bottom) and (high[1] > bottom) and (low[2] > bottom) and (high < bottom)
  719. _bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index, bottom=high[0], bgcolor=fvgStructBreakingColor, border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
  720. text=plotLabelFVG ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
  721. else if plotFVG
  722. _bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index, bottom=high[0], bgcolor=fvgBearColor, border_color=color.new(fvgBearColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
  723. text=plotLabelFVG ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
  724. if array.size(_bearBoxesFVG) > fvgMaxBoxSet
  725. box.delete(array.shift(_bearBoxesFVG))
  726. array.push(_bearBoxesFVG, _bearboxFVG)
  727.  
  728. if plotFVG or plotStructureBreakingFVG
  729. _controlBox(_bearBoxesFVG, high, low, _fvg)
  730. _controlBox(_bullBoxesFVG, high, low, _fvg)
  731.  
  732. //////////////////// Rejection Block //////////////////
  733. if plotRJB
  734. isDownRjbObCondition = isObDown(1)
  735. isDownRjb1 = isDownRjbObCondition and (high[1] < (close[2] + 0.2*(high[2]-close[2]))) // RJB is on trapped's wick and <50% of the wick was covered by signal
  736. isDownRjb2 = isDownRjbObCondition and (high[1] > high[2]) // RJB is on signal's wick
  737. if isDownRjb1 and plotRJB
  738. _bearboxRJB = box.new(left=bar_index-2, top=high[2], right=bar_index, bottom=close[2], bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
  739. text=plotLabelRJB ? _rjbLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
  740. if array.size(_bearBoxesRJB) > rjbMaxBoxSet
  741. box.delete(array.shift(_bearBoxesRJB))
  742. array.push(_bearBoxesRJB, _bearboxRJB)
  743.  
  744. if isDownRjb2 and plotRJB
  745. _bearboxRJB = box.new(left=bar_index-1, top=high[1], right=bar_index, bottom=open[1], bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
  746. text=plotLabelRJB ? _rjbLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
  747. if array.size(_bearBoxesRJB) > rjbMaxBoxSet
  748. box.delete(array.shift(_bearBoxesRJB))
  749. array.push(_bearBoxesRJB, _bearboxRJB)
  750.  
  751. //Bullish RJB Box Plotting
  752. if plotRJB
  753. isUpRjbObCondition = isObUp(1)
  754. isUpRjb1 = isUpRjbObCondition and (low[1] > (close[2] - 0.2*(close[2]-low[2]))) // RJB is on trapped's wick and <50% of the wick was covered by signal
  755. isUpRjb2 = isUpRjbObCondition and (low[1] < low[2]) // RJB is on signal's wick
  756. if isUpRjb1 and plotRJB
  757. _bullboxRJB = box.new(left=bar_index-2, top=close[2], right=bar_index, bottom=low[2], bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
  758. text=plotLabelRJB ? _rjbLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
  759. if array.size(_bullBoxesRJB) > rjbMaxBoxSet
  760. box.delete(array.shift(_bullBoxesRJB))
  761. array.push(_bullBoxesRJB, _bullboxRJB)
  762.  
  763. if isUpRjb2 and plotRJB
  764. _bullboxRJB = box.new(left=bar_index-1, top=open[1], right=bar_index, bottom=low[1], bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
  765. text=plotLabelRJB ? _rjbLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
  766. if array.size(_bullBoxesRJB) > rjbMaxBoxSet
  767. box.delete(array.shift(_bullBoxesRJB))
  768. array.push(_bullBoxesRJB, _bullboxRJB)
  769.  
  770. if plotRJB
  771. _controlBox(_bearBoxesRJB, high, low, _rjb)
  772. _controlBox(_bullBoxesRJB, high, low, _rjb)
  773.  
  774. //////////////////// Crossovers a.k.a. Break of Structure ////////////////////
  775. //Bullish BOS Box Plotting
  776. if plotBOS
  777. if ta.crossover(useHighLowForBullishBoS ? high : close, top)
  778. _bullboxBOS = box.new(left=bar_index, top=top, right=bosBoxFlag ? bar_index+bosBoxLength : bar_index+1, bottom=bottom, bgcolor=bosBullColor, border_color=color.new(bosBullColor, bosBorderTransparency), border_style=bosBoxBorder, border_width=1,
  779. text=plotLabelBOS ? _bosLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=bosLabelSize, text_color=bosLabelColor)
  780. if array.size(_bullBoxesBOS) > bosMaxBoxSet
  781. box.delete(array.shift(_bullBoxesBOS))
  782. array.push(_bullBoxesBOS, _bullboxBOS)
  783.  
  784. //Bearish BOS Box Plotting
  785. if plotBOS
  786. if ta.crossunder(useHighLowForBearishBoS ? low : close, bottom)
  787. _bearboxBOS = box.new(left=bar_index, top=top, right=bosBoxFlag ? bar_index+bosBoxLength : bar_index+1, bottom=bottom, bgcolor=bosBearColor, border_color=color.new(bosBearColor, bosBorderTransparency), border_style=bosBoxBorder, border_width=1,
  788. text=plotLabelBOS ? _bosLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=bosLabelSize, text_color=bosLabelColor)
  789. if array.size(_bearBoxesBOS) > bosMaxBoxSet
  790. box.delete(array.shift(_bearBoxesBOS))
  791. array.push(_bearBoxesBOS, _bearboxBOS)
  792.  
  793. if plotBOS
  794. _controlBox(_bearBoxesBOS, high, low, _bos)
  795. _controlBox(_bullBoxesBOS, high, low, _bos)
  796.  
  797. //////////////////// Premium Premium & Discount Discount //////////////////
  798. premiumPremium = plotPPDD and isObDown(0) and ((math.max(high, high[1]) > top and close < top) or (math.max(high, high[1]) > top[1] and close < top[1]))
  799. discountDiscount = plotPPDD and isObUp(0) and ((math.min(low, low[1]) < bottom and close > bottom) or (math.min(low, low[1]) < bottom[1] and close > bottom[1]))
  800. plotshape(premiumPremium, "Bearish PPDD OB", style=shape.triangledown , location=location.abovebar, color=ppddBearColor, size=size.tiny)
  801. plotshape(discountDiscount, "Bullish PPDD OB", style=shape.triangleup , location=location.belowbar, color=ppddBullColor, size=size.tiny)
  802.  
  803. premiumPremium1 = plotPPDD and (isUp(1) and isDown(0) and close[0] < open[1]) and ((math.max(high, high[1]) > top and close < top) or (math.max(high, high[1]) > top[1] and close < top[1])) and not premiumPremium
  804. discountDiscount1 = plotPPDD and (isDown(1) and isUp(0) and close[0] > open[1]) and ((math.min(low, low[1]) < bottom and close > bottom) or (math.min(low, low[1]) < bottom[1] and close > bottom[1])) and not discountDiscount
  805. plotshape(premiumPremium1, "Bearish PPDD Weak OB", style=shape.xcross, location=location.abovebar, color=ppddBearColor, size=size.tiny)
  806. plotshape(discountDiscount1, "Bullish PPDD Weak OB", style=shape.xcross, location=location.belowbar, color=ppddBullColor, size=size.tiny)
  807.  
  808. ////////////////// High Volume Bars //////////////////
  809. volEma = ta.ema(volume, hvbEMAPeriod)
  810. isHighVolume = volume > (hvbMultiplier * volEma)
  811. barcolor(plotHVB and isUp(0) and isHighVolume ? hvbBullColor : na, title="Bullish HVB")
  812. barcolor(plotHVB and isDown(0) and isHighVolume ? hvbBearColor : na, title="Bearish HVB")
  813.  
  814. ///////////////// Stacked OB + FVG //////////////////
  815. plotshape(plotOBFVG and isFvgDown(0) and isObDown(1), "Bearish OB+FVG Stack", style=shape.diamond, location=location.abovebar, color=obfvgBearColor, size=size.tiny)
  816. plotshape(plotOBFVG and isFvgUp(0) and isObUp(1), "Bullish OB+FVG Stack", style=shape.diamond, location=location.belowbar, color=obfvgBullColor, size=size.tiny)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement