Shabeer6555

Rudy indicator

Jul 4th, 2025 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 90.88 KB | Cryptocurrency | 0 0
  1. /// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  2. // © RUDYBANK INDICATOR - formerly know as RUDY INDICATOR
  3.  
  4. //@version=5
  5. indicator("Price Action Concepts [RUDYINDICATOR]", shorttitle = "RUDYINDICATOR-V1
  6.  
  7. - Price Action RUDYINDICATOR [1.2.2]", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 500, max_polylines_count = 100)
  8.  
  9.  
  10. //-----------------------------------------------------------------------------{
  11. //Boolean set
  12. //-----------------------------------------------------------------------------{
  13. s_BOS = 0
  14. s_CHoCH = 1
  15. i_BOS = 2
  16. i_CHoCH = 3
  17. i_pp_CHoCH = 4
  18. green_candle = 5
  19. red_candle = 6
  20. s_CHoCHP = 7
  21. i_CHoCHP = 8
  22.  
  23. boolean =
  24. array.from(
  25. false
  26. , false
  27. , false
  28. , false
  29. , false
  30. , false
  31. , false
  32. , false
  33. , false
  34. )
  35.  
  36.  
  37. //-----------------------------------------------------------------------------{
  38. // User inputs
  39. //-----------------------------------------------------------------------------{
  40.  
  41. show_swing_ms = input.string ("All" , "Swing        " , inline = "1", group = "MARKET STRUCTURE" , options = ["All", "CHoCH", "CHoCH+", "BOS", "None"])
  42. show_internal_ms = input.string ("All" , "Internal     " , inline = "2", group = "MARKET STRUCTURE" , options = ["All", "CHoCH", "CHoCH+", "BOS", "None"])
  43. internal_r_lookback = input.int (5 , "" , inline = "2", group = "MARKET STRUCTURE" , minval = 2)
  44. swing_r_lookback = input.int (50 , "" , inline = "1", group = "MARKET STRUCTURE" , minval = 2)
  45. ms_mode = input.string ("Manual" , "Market Structure Mode" , inline = "a", group = "MARKET STRUCTURE" , tooltip = "[Manual] Use selected lenght\n[Dynamic] Use automatic lenght" ,options = ["Manual", "Dynamic"])
  46. show_mtf_str = input.bool (true , "MTF Scanner" , inline = "9", group = "MARKET STRUCTURE" , tooltip = "Display Multi-Timeframe Market Structure Trend Directions. Green = Bullish. Red = Bearish")
  47. show_eql = input.bool (false , "Show EQH/EQL" , inline = "6", group = "MARKET STRUCTURE")
  48. plotcandle_bool = input.bool (false , "Plotcandle" , inline = "3", group = "MARKET STRUCTURE" , tooltip = "Displays a cleaner colored candlestick chart in place of the default candles. (requires hiding the current ticker candles)")
  49. barcolor_bool = input.bool (false , "Bar Color" , inline = "4", group = "MARKET STRUCTURE" , tooltip = "Color the candle bodies according to market strucutre trend")
  50.  
  51. i_ms_up_BOS = input.color (#089981 , "" , inline = "2", group = "MARKET STRUCTURE")
  52. i_ms_dn_BOS = input.color (#f23645 , "" , inline = "2", group = "MARKET STRUCTURE")
  53. s_ms_up_BOS = input.color (#089981 , "" , inline = "1", group = "MARKET STRUCTURE")
  54. s_ms_dn_BOS = input.color (#f23645 , "" , inline = "1", group = "MARKET STRUCTURE")
  55.  
  56. lvl_daily = input.bool (false , "Day   " , inline = "1", group = "HIGHS & LOWS MTF")
  57. lvl_weekly = input.bool (false , "Week " , inline = "2", group = "HIGHS & LOWS MTF")
  58. lvl_monthly = input.bool (false , "Month" , inline = "3", group = "HIGHS & LOWS MTF")
  59. lvl_yearly = input.bool (false , "Year  " , inline = "4", group = "HIGHS & LOWS MTF")
  60. css_d = input.color (color.blue , "" , inline = "1", group = "HIGHS & LOWS MTF")
  61. css_w = input.color (color.blue , "" , inline = "2", group = "HIGHS & LOWS MTF")
  62. css_m = input.color (color.blue , "" , inline = "3", group = "HIGHS & LOWS MTF")
  63. css_y = input.color (color.blue , "" , inline = "4", group = "HIGHS & LOWS MTF")
  64. s_d = input.string ('⎯⎯⎯' , '' , inline = '1', group = 'HIGHS & LOWS MTF' , options = ['⎯⎯⎯', '----', '····'])
  65. s_w = input.string ('⎯⎯⎯' , '' , inline = '2', group = 'HIGHS & LOWS MTF' , options = ['⎯⎯⎯', '----', '····'])
  66. s_m = input.string ('⎯⎯⎯' , '' , inline = '3', group = 'HIGHS & LOWS MTF' , options = ['⎯⎯⎯', '----', '····'])
  67. s_y = input.string ('⎯⎯⎯' , '' , inline = '4', group = 'HIGHS & LOWS MTF' , options = ['⎯⎯⎯', '----', '····'])
  68.  
  69. ob_show = input.bool (true , "Show Last    " , inline = "1", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Display volumetric order blocks on the chart \n\n[Input] Ammount of volumetric order blocks to show")
  70. ob_num = input.int (5 , "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Orderblocks number", minval = 1, maxval = 10)
  71. ob_metrics_show = input.bool (true , "Internal Buy/Sell Activity" , inline = "2", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Display volume metrics that have formed the orderblock")
  72. css_metric_up = input.color (color.new(#089981, 50) , "         " , inline = "2", group = "VOLUMETRIC ORDER BLOCKS")
  73. css_metric_dn = input.color (color.new(#f23645 , 50) , "" , inline = "2", group = "VOLUMETRIC ORDER BLOCKS")
  74. ob_swings = input.bool (false , "Swing Order Blocks" , inline = "a", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Display swing volumetric order blocks")
  75. css_swing_up = input.color (color.new(color.gray , 90) , "                 " , inline = "a", group = "VOLUMETRIC ORDER BLOCKS")
  76. css_swing_dn = input.color (color.new(color.silver, 90) , "" , inline = "a", group = "VOLUMETRIC ORDER BLOCKS")
  77. ob_filter = input.string ("None" , "Filtering             " , inline = "d", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Filter out volumetric order blocks by BOS/CHoCH/CHoCH+", options = ["None", "BOS", "CHoCH", "CHoCH+"])
  78. ob_mitigation = input.string ("Absolute" , "Mitigation           " , inline = "4", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Trigger to remove volumetric order blocks", options = ["Absolute", "Middle"])
  79. ob_pos = input.string ("Precise" , "Positioning          " , inline = "k", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Position of the Order Block\n[Full] Cover the whole candle\n[Middle] Cover half candle\n[Accurate] Adjust to volatility\n[Precise] Same as Accurate but more precise", options = ["Full", "Middle", "Accurate", "Precise"])
  80. use_grayscale = input.bool (false , "Grayscale" , inline = "6", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Use gray as basic order blocks color")
  81. use_show_metric = input.bool (true , "Show Metrics" , inline = "7", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Show volume associated with the orderblock and his relevance")
  82. use_middle_line = input.bool (true , "Show Middle-Line" , inline = "8", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Show mid-line order blocks")
  83. use_overlap = input.bool (true , "Hide Overlap" , inline = "9", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "Hide overlapping order blocks")
  84. use_overlap_method = input.string ("Previous" , "Overlap Method    " , inline = "Z", group = "VOLUMETRIC ORDER BLOCKS" , tooltip = "[Recent] Preserve the most recent volumetric order blocks\n\n[Previous] Preserve the previous volumetric order blocks", options = ["Recent", "Previous"])
  85. ob_bull_css = input.color (color.new(#089981 , 90) , "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS")
  86. ob_bear_css = input.color (color.new(#f23645 , 90) , "" , inline = "1", group = "VOLUMETRIC ORDER BLOCKS")
  87.  
  88. show_acc_dist_zone = input.bool (false , "" , inline = "1", group = "Accumulation And Distribution")
  89. zone_mode = input.string ("Fast" , "" , inline = "1", group = "Accumulation And Distribution" , tooltip = "[Fast] Find small zone pattern formation\n[Slow] Find bigger zone pattern formation" ,options = ["Slow", "Fast"])
  90. acc_css = input.color (color.new(#089981 , 60) , "" , inline = "1", group = "Accumulation And Distribution")
  91. dist_css = input.color (color.new(#f23645 , 60) , "" , inline = "1", group = "Accumulation And Distribution")
  92.  
  93. show_lbl = input.bool (false , "Show swing point" , inline = "1", group = "High and Low" , tooltip = "Display swing point")
  94. show_mtb = input.bool (false , "Show High/Low/Equilibrium" , inline = "2", group = "High and Low" , tooltip = "Display Strong/Weak High And Low and Equilibrium")
  95. toplvl = input.color (color.red , "Premium Zone   " , inline = "3", group = "High and Low")
  96. midlvl = input.color (color.gray , "Equilibrium Zone" , inline = "4", group = "High and Low")
  97. btmlvl = input.color (#089981 , "Discount Zone    " , inline = "5", group = "High and Low")
  98.  
  99. fvg_enable = input.bool (false , "        " , inline = "1", group = "FAIR VALUE GAP" , tooltip = "Display fair value gap")
  100. what_fvg = input.string ("FVG" , "" , inline = "1", group = "FAIR VALUE GAP" , tooltip = "Display fair value gap", options = ["FVG", "VI", "OG"])
  101. fvg_num = input.int (5 , "Show Last  " , inline = "1a", group = "FAIR VALUE GAP" , tooltip = "Number of fvg to show")
  102. fvg_upcss = input.color (color.new(#089981, 80) , "" , inline = "1", group = "FAIR VALUE GAP")
  103. fvg_dncss = input.color (color.new(color.red , 80) , "" , inline = "1", group = "FAIR VALUE GAP")
  104. fvg_extend = input.int (10 , "Extend FVG" , inline = "2", group = "FAIR VALUE GAP" , tooltip = "Extend the display of the FVG.")
  105. fvg_src = input.string ("Close" , "Mitigation  " , inline = "3", group = "FAIR VALUE GAP" , tooltip = "[Close] Use the close of the body as trigger\n\n[Wick] Use the extreme point of the body as trigger", options = ["Close", "Wick"])
  106. fvg_tf = input.timeframe ("" , "Timeframe " , inline = "4", group = "FAIR VALUE GAP" , tooltip = "Timeframe of the fair value gap")
  107.  
  108. t = color.t (ob_bull_css)
  109. invcol = color.new (color.white , 100)
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  144. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  145. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  146. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  147. //{ - UDT }
  148. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  149. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  150. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  151. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  152.  
  153. type bar
  154. float o = open
  155. float c = close
  156. float h = high
  157. float l = low
  158. float v = volume
  159. int n = bar_index
  160. int t = time
  161.  
  162. type Zphl
  163. line top
  164. line bottom
  165. label top_label
  166. label bottom_label
  167. bool stopcross
  168. bool sbottomcross
  169. bool itopcross
  170. bool ibottomcross
  171. string txtup
  172. string txtdn
  173. float topy
  174. float bottomy
  175. float topx
  176. float bottomx
  177. float tup
  178. float tdn
  179. int tupx
  180. int tdnx
  181. float itopy
  182. float itopx
  183. float ibottomy
  184. float ibottomx
  185. float uV
  186. float dV
  187.  
  188. type FVG
  189. box [] box
  190. line[] ln
  191. bool bull
  192. float top
  193. float btm
  194. int left
  195. int right
  196.  
  197. type ms
  198. float[] p
  199. int [] n
  200. float[] l
  201.  
  202. type msDraw
  203. int n
  204. float p
  205. color css
  206. string txt
  207. bool bull
  208.  
  209. type obC
  210. float[] top
  211. float[] btm
  212. int [] left
  213. float[] avg
  214. float[] dV
  215. float[] cV
  216. int [] wM
  217. int [] blVP
  218. int [] brVP
  219. int [] dir
  220. float[] h
  221. float[] l
  222. int [] n
  223.  
  224. type obD
  225. box [] ob
  226. box [] eOB
  227. box [] blB
  228. box [] brB
  229. line[] mL
  230.  
  231. type zone
  232. chart.point points
  233. float p
  234. int c
  235. int t
  236.  
  237. type hqlzone
  238. box pbx
  239. box ebx
  240. box lbx
  241. label plb
  242. label elb
  243. label lbl
  244.  
  245. type ehl
  246. float pt
  247. int t
  248. float pb
  249. int b
  250.  
  251. type pattern
  252. string found = "None"
  253. bool isfound = false
  254. int period = 0
  255. bool bull = false
  256.  
  257. type alerts
  258. bool chochswing = false
  259. bool chochplusswing = false
  260. bool swingbos = false
  261. bool chochplus = false
  262. bool choch = false
  263. bool bos = false
  264. bool equal = false
  265. bool ob = false
  266. bool swingob = false
  267. bool zone = false
  268. bool fvg = false
  269. bool obtouch = false
  270.  
  271. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  272. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  273. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  274. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  275. //{ - End }
  276. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  277. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  278. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  279. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  314. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  315. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  316. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  317. //{ - General Setup }
  318. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  319. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  320. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  321. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  322.  
  323. bar b = bar.new()
  324. var pattern p = pattern.new()
  325.  
  326. alerts blalert = alerts.new()
  327. alerts bralert = alerts.new()
  328.  
  329. if p.isfound
  330.  
  331. p.period += 1
  332.  
  333. if p.period == 50
  334.  
  335. p.period := 0
  336. p.found := "None"
  337. p.isfound := false
  338. p.bull := na
  339.  
  340. switch
  341.  
  342. b.c > b.o => boolean.set(green_candle, true)
  343. b.c < b.o => boolean.set(red_candle , true)
  344.  
  345. f_zscore(src, lookback) =>
  346.  
  347. (src - ta.sma(src, lookback)) / ta.stdev(src, lookback)
  348.  
  349. var int iLen = internal_r_lookback
  350. var int sLen = swing_r_lookback
  351.  
  352. vv = f_zscore(((close - close[iLen]) / close[iLen]) * 100,iLen)
  353.  
  354. if ms_mode == "Dynamic"
  355.  
  356. switch
  357.  
  358. vv >= 1.5 or vv <= -1.5 => iLen := 10
  359. vv >= 1.6 or vv <= -1.6 => iLen := 9
  360. vv >= 1.7 or vv <= -1.7 => iLen := 8
  361. vv >= 1.8 or vv <= -1.8 => iLen := 7
  362. vv >= 1.9 or vv <= -1.9 => iLen := 6
  363. vv >= 2.0 or vv <= -2.0 => iLen := 5
  364. => iLen
  365.  
  366. var msline = array.new<line>(0)
  367.  
  368. iH = ta.pivothigh(high, iLen, iLen)
  369. sH = ta.pivothigh(high, sLen, sLen)
  370. iL = ta.pivotlow (low , iLen, iLen)
  371. sL = ta.pivotlow (low , sLen, sLen)
  372.  
  373. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  374. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  375. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  376. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  377. //{ - End }
  378. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  379. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  380. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  381. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  416. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  417. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  418. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  419. //{ - ARRAYS }
  420. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  421. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  422. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  423. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  424.  
  425. hl () => [high, low]
  426.  
  427. [pdh, pdl] = request.security(syminfo.tickerid , 'D' , hl() , lookahead = barmerge.lookahead_on)
  428. [pwh, pwl] = request.security(syminfo.tickerid , 'W' , hl() , lookahead = barmerge.lookahead_on)
  429. [pmh, pml] = request.security(syminfo.tickerid , 'M' , hl() , lookahead = barmerge.lookahead_on)
  430. [pyh, pyl] = request.security(syminfo.tickerid , '12M', hl() , lookahead = barmerge.lookahead_on)
  431.  
  432. lstyle(style) =>
  433.  
  434. out = switch style
  435.  
  436. '⎯⎯⎯' => line.style_solid
  437. '----' => line.style_dashed
  438. '····' => line.style_dotted
  439.  
  440. mtfphl(h, l ,tf ,css, pdhl_style) =>
  441.  
  442. var line hl = line.new(
  443. na
  444. , na
  445. , na
  446. , na
  447. , xloc = xloc.bar_time
  448. , color = css
  449. , style = lstyle(pdhl_style)
  450. )
  451.  
  452. var line ll = line.new(
  453. na
  454. , na
  455. , na
  456. , na
  457. , xloc = xloc.bar_time
  458. , color = css
  459. , style = lstyle(pdhl_style)
  460. )
  461.  
  462. var label lbl = label.new(
  463. na
  464. , na
  465. , xloc = xloc.bar_time
  466. , text = str.format('P{0}L', tf)
  467. , color = invcol
  468. , textcolor = css
  469. , size = size.small
  470. , style = label.style_label_left
  471. )
  472.  
  473. var label hlb = label.new(
  474. na
  475. , na
  476. , xloc = xloc.bar_time
  477. , text = str.format('P{0}H', tf)
  478. , color = invcol
  479. , textcolor = css
  480. , size = size.small
  481. , style = label.style_label_left
  482. )
  483.  
  484. hy = ta.valuewhen(h != h[1] , h , 1)
  485. hx = ta.valuewhen(h == high , time , 1)
  486. ly = ta.valuewhen(l != l[1] , l , 1)
  487. lx = ta.valuewhen(l == low , time , 1)
  488.  
  489. if barstate.islast
  490.  
  491. extension = time + (time - time[1]) * 50
  492.  
  493. line.set_xy1(hl , hx , hy)
  494. line.set_xy2(hl , extension , hy)
  495. label.set_xy(hlb, extension , hy)
  496. line.set_xy1(ll , lx , ly)
  497. line.set_xy2(ll , extension , ly)
  498. label.set_xy(lbl, extension , ly)
  499.  
  500. if lvl_daily
  501.  
  502. mtfphl(pdh , pdl , 'D' , css_d, s_d)
  503.  
  504. if lvl_weekly
  505.  
  506. mtfphl(pwh , pwl , 'W' , css_w, s_w)
  507.  
  508. if lvl_monthly
  509.  
  510. mtfphl(pmh , pml, 'M' , css_m, s_m)
  511.  
  512. if lvl_yearly
  513.  
  514. mtfphl(pyh , pyl , '12M', css_y, s_y)
  515.  
  516.  
  517. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  518. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  519. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  520. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  521. //{ - End }
  522. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  523. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  524. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  525. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  560. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  561. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  562. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  563. //{ - Market Structure }
  564. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  565. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  566. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  567. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  568.  
  569. method darkcss(color css, float factor, bool bull) =>
  570.  
  571. blue = color.b(css) * (1 - factor)
  572. red = color.r(css) * (1 - factor)
  573. green = color.g(css) * (1 - factor)
  574.  
  575. color.rgb(red, green, blue, 0)
  576.  
  577. method f_line(msDraw d, size, style) =>
  578.  
  579. var line id = na
  580. var label lbl = na
  581.  
  582. id := line.new(
  583. d.n
  584. , d.p
  585. , b.n
  586. , d.p
  587. , color = d.css
  588. , width = 1
  589. , style = style
  590. )
  591.  
  592. if msline.size() >= 250
  593.  
  594. line.delete(msline.shift())
  595.  
  596. msline.push(id)
  597.  
  598. lbl := label.new(
  599. int(math.avg(d.n, b.n))
  600. , d.p
  601. , d.txt
  602. , color = invcol
  603. , textcolor = d.css
  604. , style = d.bull ? label.style_label_down : label.style_label_up
  605. , size = size
  606. , text_font_family = font.family_monospace
  607. )
  608.  
  609. structure(bool mtf) =>
  610.  
  611. msDraw drw = na
  612.  
  613. bool isdrw = false
  614. bool isdrwS = false
  615.  
  616. var color css = na
  617. var color icss = na
  618.  
  619. var int itrend = 0
  620. var int trend = 0
  621.  
  622. bool bull_ob = false
  623. bool bear_ob = false
  624.  
  625. bool s_bull_ob = false
  626. bool s_bear_ob = false
  627.  
  628. n = bar_index
  629.  
  630. var ms up = ms.new(
  631. array.new<float>()
  632. , array.new< int >()
  633. , array.new<float>()
  634. )
  635.  
  636. var ms dn = ms.new(
  637. array.new<float>()
  638. , array.new< int >()
  639. , array.new<float>()
  640. )
  641.  
  642. var ms sup = ms.new(
  643. array.new<float>()
  644. , array.new< int >()
  645. , array.new<float>()
  646. )
  647.  
  648. var ms sdn = ms.new(
  649. array.new<float>()
  650. , array.new< int >()
  651. , array.new<float>()
  652. )
  653.  
  654. switch show_swing_ms
  655.  
  656. "All" => boolean.set(s_BOS , true ), boolean.set(s_CHoCH, true ) , boolean.set(s_CHoCHP, true )
  657. "CHoCH" => boolean.set(s_BOS , false), boolean.set(s_CHoCH, true ) , boolean.set(s_CHoCHP, false )
  658. "CHoCH+" => boolean.set(s_BOS , false), boolean.set(s_CHoCH, false) , boolean.set(s_CHoCHP, true )
  659. "BOS" => boolean.set(s_BOS , true ), boolean.set(s_CHoCH, false) , boolean.set(s_CHoCHP, false )
  660. "None" => boolean.set(s_BOS , false), boolean.set(s_CHoCH, false) , boolean.set(s_CHoCHP, false )
  661. => na
  662.  
  663. switch show_internal_ms
  664.  
  665. "All" => boolean.set(i_BOS, true ), boolean.set(i_CHoCH, true ), boolean.set(i_CHoCHP, true )
  666. "CHoCH" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, true ), boolean.set(i_CHoCHP, false)
  667. "CHoCH+" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, false ), boolean.set(i_CHoCHP, true )
  668. "BOS" => boolean.set(i_BOS, true ), boolean.set(i_CHoCH, false ), boolean.set(i_CHoCHP, false)
  669. "None" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, false ), boolean.set(i_CHoCHP, false)
  670. => na
  671.  
  672. switch
  673. iH =>
  674.  
  675. up.p.unshift(b.h[iLen])
  676. up.l.unshift(b.h[iLen])
  677. up.n.unshift(n [iLen])
  678.  
  679. iL =>
  680.  
  681. dn.p.unshift(b.l[iLen])
  682. dn.l.unshift(b.l[iLen])
  683. dn.n.unshift(n [iLen])
  684.  
  685. sL =>
  686.  
  687. sdn.p.unshift(b.l[sLen])
  688. sdn.l.unshift(b.l[sLen])
  689. sdn.n.unshift(n [sLen])
  690.  
  691. sH =>
  692.  
  693. sup.p.unshift(b.h[sLen])
  694. sup.l.unshift(b.h[sLen])
  695. sup.n.unshift(n [sLen])
  696.  
  697. // INTERNAL BULLISH STRUCTURE
  698. if up.p.size() > 0 and dn.l.size() > 1
  699.  
  700. if ta.crossover(b.c, up.p.first())
  701.  
  702. bool CHoCH = na
  703. string txt = na
  704.  
  705. if itrend < 0
  706.  
  707. CHoCH := true
  708.  
  709. switch
  710.  
  711. not CHoCH =>
  712.  
  713. txt := "BOS"
  714. css := i_ms_up_BOS
  715.  
  716. blalert.bos := true
  717.  
  718. if boolean.get(i_BOS) and mtf == false and na(drw)
  719.  
  720. isdrw := true
  721. drw := msDraw.new(
  722. up.n.first()
  723. , up.p.first()
  724. , i_ms_up_BOS
  725. , txt
  726. , true
  727. )
  728.  
  729. CHoCH =>
  730.  
  731. dn.l.first() > dn.l.get(1) ? blalert.chochplus : blalert.choch
  732.  
  733. txt := dn.l.first() > dn.l.get(1) ? "CHoCH+" : "CHoCH"
  734. css := i_ms_up_BOS.darkcss(0.25, true)
  735.  
  736. if (dn.l.first() > dn.l.get(1) ? boolean.get(i_CHoCHP) : boolean.get(i_CHoCH)) and mtf == false and na(drw)
  737.  
  738. isdrw := true
  739. drw := msDraw.new(
  740. up.n.first()
  741. , up.p.first()
  742. , i_ms_up_BOS.darkcss(0.25, true)
  743. , txt
  744. , true
  745. )
  746.  
  747. if mtf == false
  748.  
  749. switch
  750.  
  751. ob_filter == "None" => bull_ob := true
  752. ob_filter == "BOS" and txt == "BOS" => bull_ob := true
  753. ob_filter == "CHoCH" and txt == "CHoCH" => bull_ob := true
  754. ob_filter == "CHoCH+" and txt == "CHoCH+" => bull_ob := true
  755.  
  756. itrend := 1
  757. up.n.clear()
  758. up.p.clear()
  759.  
  760. // INTERNAL BEARISH STRUCTURE
  761. if dn.p.size() > 0 and up.l.size() > 1
  762.  
  763. if ta.crossunder(b.c, dn.p.first())
  764.  
  765. bool CHoCH = na
  766. string txt = na
  767.  
  768. if itrend > 0
  769.  
  770. CHoCH := true
  771.  
  772. switch
  773.  
  774. not CHoCH =>
  775.  
  776. bralert.bos := true
  777.  
  778. txt := "BOS"
  779. css := i_ms_dn_BOS
  780.  
  781. if boolean.get(i_BOS) and mtf == false and na(drw)
  782.  
  783. isdrw := true
  784. drw := msDraw.new(
  785. dn.n.first()
  786. , dn.p.first()
  787. , i_ms_dn_BOS
  788. , txt
  789. , false
  790. )
  791.  
  792. CHoCH =>
  793.  
  794. if up.l.first() < up.l.get(1)
  795. bralert.chochplus := true
  796. else
  797. bralert.choch := true
  798.  
  799. txt := up.l.first() < up.l.get(1) ? "CHoCH+" : "CHoCH"
  800. css := i_ms_dn_BOS.darkcss(0.25, false)
  801.  
  802. if (up.l.first() < up.l.get(1) ? boolean.get(i_CHoCHP) : boolean.get(i_CHoCH)) and mtf == false and na(drw)
  803.  
  804. isdrw := true
  805. drw := msDraw.new(
  806. dn.n.first()
  807. , dn.p.first()
  808. , i_ms_dn_BOS.darkcss(0.25, false)
  809. , txt
  810. , false
  811. )
  812.  
  813. if mtf == false
  814.  
  815. switch
  816.  
  817. ob_filter == "None" => bear_ob := true
  818. ob_filter == "BOS" and txt == "BOS" => bear_ob := true
  819. ob_filter == "CHoCH" and txt == "CHoCH" => bear_ob := true
  820. ob_filter == "CHoCH+" and txt == "CHoCH+" => bear_ob := true
  821.  
  822. itrend := -1
  823. dn.n.clear()
  824. dn.p.clear()
  825.  
  826. // SWING BULLISH STRUCTURE
  827. if sup.p.size() > 0 and sdn.l.size() > 1
  828.  
  829. if ta.crossover(b.c, sup.p.first())
  830.  
  831. bool CHoCH = na
  832. string txt = na
  833.  
  834. if trend < 0
  835.  
  836. CHoCH := true
  837.  
  838. switch
  839.  
  840. not CHoCH =>
  841.  
  842. blalert.swingbos := true
  843.  
  844. txt := "BOS"
  845. icss := s_ms_up_BOS
  846.  
  847. if boolean.get(s_BOS) and mtf == false and na(drw)
  848.  
  849. isdrwS := true
  850. drw := msDraw.new(
  851. sup.n.first()
  852. , sup.p.first()
  853. , s_ms_up_BOS
  854. , txt
  855. , true
  856. )
  857.  
  858. CHoCH =>
  859.  
  860. if sdn.l.first() > sdn.l.get(1)
  861. blalert.chochplusswing := true
  862. else
  863. blalert.chochswing := true
  864.  
  865. txt := sdn.l.first() > sdn.l.get(1) ? "CHoCH+" : "CHoCH"
  866. icss := s_ms_up_BOS.darkcss(0.25, true)
  867.  
  868. if (sdn.l.first() > sdn.l.get(1) ? boolean.get(s_CHoCHP) : boolean.get(s_CHoCH)) and mtf == false and na(drw)
  869.  
  870. isdrwS := true
  871. drw := msDraw.new(
  872. sup.n.first()
  873. , sup.p.first()
  874. , s_ms_up_BOS.darkcss(0.25, true)
  875. , txt
  876. , true
  877. )
  878.  
  879. if mtf == false
  880.  
  881. switch
  882.  
  883. ob_filter == "None" => s_bull_ob := true
  884. ob_filter == "BOS" and txt == "BOS" => s_bull_ob := true
  885. ob_filter == "CHoCH" and txt == "CHoCH" => s_bull_ob := true
  886. ob_filter == "CHoCH+" and txt == "CHoCH+" => s_bull_ob := true
  887.  
  888. trend := 1
  889. sup.n.clear()
  890. sup.p.clear()
  891.  
  892. // SWING BEARISH STRUCTURE
  893. if sdn.p.size() > 0 and sup.l.size() > 1
  894.  
  895. if ta.crossunder(b.c, sdn.p.first())
  896.  
  897. bool CHoCH = na
  898. string txt = na
  899.  
  900. if trend > 0
  901.  
  902. CHoCH := true
  903.  
  904. switch
  905.  
  906. not CHoCH =>
  907.  
  908. bralert.swingbos := true
  909.  
  910. txt := "BOS"
  911. icss := s_ms_dn_BOS
  912.  
  913. if boolean.get(s_BOS) and mtf == false and na(drw)
  914.  
  915. isdrwS := true
  916. drw := msDraw.new(
  917. sdn.n.first()
  918. , sdn.p.first()
  919. , s_ms_dn_BOS
  920. , txt
  921. , false
  922. )
  923.  
  924. CHoCH =>
  925.  
  926. if sup.l.first() < sup.l.get(1)
  927. bralert.chochplusswing := true
  928. else
  929. bralert.chochswing := true
  930.  
  931. txt := sup.l.first() < sup.l.get(1) ? "CHoCH+" : "CHoCH"
  932. icss := s_ms_dn_BOS.darkcss(0.25, false)
  933.  
  934. if (sup.l.first() < sup.l.get(1) ? boolean.get(s_CHoCHP) : boolean.get(s_CHoCH)) and mtf == false and na(drw)
  935.  
  936. isdrwS := true
  937. drw := msDraw.new(
  938. sdn.n.first()
  939. , sdn.p.first()
  940. , s_ms_dn_BOS.darkcss(0.25, false)
  941. , txt
  942. , false
  943. )
  944.  
  945. if mtf == false
  946.  
  947. switch
  948.  
  949. ob_filter == "None" => s_bear_ob := true
  950. ob_filter == "BOS" and txt == "BOS" => s_bear_ob := true
  951. ob_filter == "CHoCH" and txt == "CHoCH" => s_bear_ob := true
  952. ob_filter == "CHoCH+" and txt == "CHoCH+" => s_bear_ob := true
  953.  
  954. trend := -1
  955. sdn.n.clear()
  956. sdn.p.clear()
  957.  
  958. [css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss, isdrwS]
  959.  
  960.  
  961. [css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss, isdrwS] = structure(false)
  962.  
  963. if isdrw
  964. f_line(drw, size.small, line.style_dashed)
  965.  
  966. if isdrwS
  967. f_line(drw, size.small, line.style_solid)
  968.  
  969. [_, _, _, itrend15, _, _, _, _, _, _, _] = request.security("", "15" , structure(true))
  970. [_, _, _, itrend1H, _, _, _, _, _, _, _] = request.security("", "60" , structure(true))
  971. [_, _, _, itrend4H, _, _, _, _, _, _, _] = request.security("", "240" , structure(true))
  972. [_, _, _, itrend1D, _, _, _, _, _, _, _] = request.security("", "1440" , structure(true))
  973.  
  974. if show_mtf_str
  975.  
  976. var tab = table.new(position = position.top_right, columns = 10, rows = 10, bgcolor = na, frame_color = color.rgb(54, 58, 69, 0), frame_width = 1, border_color = color.rgb(54, 58, 69, 100), border_width = 1)
  977. table.cell(tab, 0, 1, text = "15" , text_color = color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor = chart.bg_color, text_font_family = font.family_monospace, width = 2)
  978. table.cell(tab, 0, 2, text = "1H" , text_color = color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor = chart.bg_color, text_font_family = font.family_monospace, width = 2)
  979. table.cell(tab, 0, 3, text = "4H" , text_color = color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor = chart.bg_color, text_font_family = font.family_monospace, width = 2)
  980. table.cell(tab, 0, 4, text = "1D" , text_color = color.silver, text_halign = text.align_center, text_size = size.normal, bgcolor = chart.bg_color, text_font_family = font.family_monospace, width = 2)
  981.  
  982. table.cell(tab, 1, 1, text = itrend15 == 1 ? "BULLISH" : itrend15 == -1 ? "BEARISH" : na , text_halign = text.align_center, text_size = size.normal, text_color = itrend15 == 1 ? i_ms_up_BOS.darkcss(-0.25, true) : itrend15 == -1 ? i_ms_dn_BOS.darkcss(0.25, false) : color.gray, bgcolor = chart.bg_color, text_font_family = font.family_monospace)
  983. table.cell(tab, 1, 2, text = itrend1H == 1 ? "BULLISH" : itrend1H == -1 ? "BEARISH" : na , text_halign = text.align_center, text_size = size.normal, text_color = itrend1H == 1 ? i_ms_up_BOS.darkcss(-0.25, true) : itrend1H == -1 ? i_ms_dn_BOS.darkcss(0.25, false) : color.gray, bgcolor = chart.bg_color, text_font_family = font.family_monospace)
  984. table.cell(tab, 1, 3, text = itrend4H == 1 ? "BULLISH" : itrend4H == -1 ? "BEARISH" : na , text_halign = text.align_center, text_size = size.normal, text_color = itrend4H == 1 ? i_ms_up_BOS.darkcss(-0.25, true) : itrend4H == -1 ? i_ms_dn_BOS.darkcss(0.25, false) : color.gray, bgcolor = chart.bg_color, text_font_family = font.family_monospace)
  985. table.cell(tab, 1, 4, text = itrend1D == 1 ? "BULLISH" : itrend1D == -1 ? "BEARISH" : na , text_halign = text.align_center, text_size = size.normal, text_color = itrend1D == 1 ? i_ms_up_BOS.darkcss(-0.25, true) : itrend1D == -1 ? i_ms_dn_BOS.darkcss(0.25, false) : color.gray, bgcolor = chart.bg_color, text_font_family = font.family_monospace)
  986.  
  987. table.cell(tab, 0, 5, text = "Detected Pattern", text_halign = text.align_center, text_size = size.normal, text_color = color.silver, bgcolor = chart.bg_color, text_font_family = font.family_monospace)
  988. table.cell(tab, 0, 6, text = p.found, text_halign = text.align_center, text_size = size.normal, text_color = na(p.bull) ? color.white : p.bull ? i_ms_up_BOS.darkcss(-0.25, true) : p.bull == false ? i_ms_dn_BOS.darkcss(0.25, false) : na, bgcolor = chart.bg_color, text_font_family = font.family_monospace)
  989.  
  990. table.merge_cells(tab, 0, 5, 1, 5)
  991. table.merge_cells(tab, 0, 6, 1, 6)
  992.  
  993. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  994. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  995. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  996. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  997. //{ - End }
  998. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  999. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1000. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1001. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1036. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1037. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1038. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1039. //{ - Strong/Weak High/Low And Equilibrium }
  1040. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1041. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1042. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1043. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1044.  
  1045. var phl = Zphl.new(
  1046. na
  1047. , na
  1048. , label.new(na , na , color = invcol , textcolor = i_ms_dn_BOS , style = label.style_label_down , size = size.tiny , text = "")
  1049. , label.new(na , na , color = invcol , textcolor = i_ms_up_BOS , style = label.style_label_up , size = size.tiny , text = "")
  1050. , true
  1051. , true
  1052. , true
  1053. , true
  1054. , ""
  1055. , ""
  1056. , 0
  1057. , 0
  1058. , 0
  1059. , 0
  1060. , high
  1061. , low
  1062. , 0
  1063. , 0
  1064. , 0
  1065. , 0
  1066. , 0
  1067. , 0
  1068. , na
  1069. , na
  1070. )
  1071.  
  1072. zhl(len)=>
  1073.  
  1074. upper = ta.highest(len)
  1075. lower = ta.lowest(len)
  1076.  
  1077. var float out = 0
  1078. out := b.h[len] > upper ? 0 : b.l[len] < lower ? 1 : out[1]
  1079.  
  1080. top = out == 0 and out[1] != 0 ? b.h[len] : 0
  1081. btm = out == 1 and out[1] != 1 ? b.l[len] : 0
  1082.  
  1083. [top, btm]
  1084.  
  1085. [top , btm ] = zhl(sLen)
  1086. [itop, ibtm] = zhl(iLen)
  1087.  
  1088. upphl(trend) =>
  1089.  
  1090. var label lbl = label.new(
  1091. na
  1092. , na
  1093. , color = invcol
  1094. , textcolor = toplvl
  1095. , style = label.style_label_down
  1096. , size = size.small
  1097. )
  1098.  
  1099. if top
  1100.  
  1101. phl.stopcross := true
  1102. phl.txtup := top > phl.topy ? "HH" : "HL"
  1103.  
  1104. if show_lbl
  1105.  
  1106. topl = label.new(
  1107. b.n - swing_r_lookback
  1108. , top
  1109. , phl.txtup
  1110. , color = invcol
  1111. , textcolor = toplvl
  1112. , style = label.style_label_down
  1113. , size = size.small
  1114. )
  1115.  
  1116. line.delete(phl.top[1])
  1117.  
  1118. phl.top := line.new(
  1119. b.n - sLen
  1120. , top
  1121. , b.n
  1122. , top
  1123. , color = toplvl)
  1124.  
  1125. phl.topy := top
  1126. phl.topx := b.n - sLen
  1127. phl.tup := top
  1128. phl.tupx := b.n - sLen
  1129.  
  1130. if itop
  1131.  
  1132. phl.itopcross := true
  1133. phl.itopy := itop
  1134. phl.itopx := b.n - iLen
  1135.  
  1136. phl.tup := math.max(high, phl.tup)
  1137. phl.tupx := phl.tup == high ? b.n : phl.tupx
  1138. phl.uV := phl.tup != phl.tup[1] ? b.v : phl.uV
  1139.  
  1140. if barstate.islast
  1141.  
  1142. line.set_xy1(
  1143. phl.top
  1144. , phl.tupx
  1145. , phl.tup
  1146. )
  1147.  
  1148. line.set_xy2(
  1149. phl.top
  1150. , b.n + 50
  1151. , phl.tup
  1152. )
  1153.  
  1154. label.set_x(
  1155. lbl
  1156. , b.n + 50
  1157. )
  1158.  
  1159. label.set_y(
  1160. lbl
  1161. , phl.tup
  1162. )
  1163.  
  1164. dist = math.abs(phl.uV / (phl.uV + phl.dV)) * 100
  1165. label.set_text (lbl, trend < 0
  1166. ? "Strong High | " + str.tostring(phl.uV, format.volume) + " (" + str.tostring(math.round(dist,0)) + "%)"
  1167. : "Weak High | " + str.tostring(phl.uV, format.volume) + " (" + str.tostring(math.round(dist,0)) + "%)")
  1168.  
  1169. dnphl(trend) =>
  1170.  
  1171. var label lbl = label.new(
  1172. na
  1173. , na
  1174. , color = invcol
  1175. , textcolor = btmlvl
  1176. , style = label.style_label_up
  1177. , size = size.small
  1178. )
  1179.  
  1180. if btm
  1181.  
  1182. phl.sbottomcross := true
  1183. phl.txtdn := btm > phl.bottomy ? "LH" : "LL"
  1184.  
  1185. if show_lbl
  1186.  
  1187. btml = label.new(
  1188. b.n - swing_r_lookback
  1189. , btm, phl.txtdn
  1190. , color = invcol
  1191. , textcolor = btmlvl
  1192. , style = label.style_label_up
  1193. , size = size.small
  1194. )
  1195.  
  1196. line.delete(phl.bottom[1])
  1197.  
  1198. phl.bottom := line.new(
  1199. b.n - sLen
  1200. , btm
  1201. , b.n
  1202. , btm
  1203. , color = btmlvl
  1204. )
  1205.  
  1206. phl.bottomy := btm
  1207. phl.bottomx := b.n - sLen
  1208. phl.tdn := btm
  1209. phl.tdnx := b.n - sLen
  1210.  
  1211. if ibtm
  1212.  
  1213. phl.ibottomcross := true
  1214. phl.ibottomy := ibtm
  1215. phl.ibottomx := b.n - iLen
  1216.  
  1217. phl.tdn := math.min(low, phl.tdn)
  1218. phl.tdnx := phl.tdn == low ? b.n : phl.tdnx
  1219. phl.dV := phl.tdn != phl.tdn[1] ? b.v : phl.dV
  1220.  
  1221. if barstate.islast
  1222.  
  1223. line.set_xy1(
  1224. phl.bottom
  1225. , phl.tdnx
  1226. , phl.tdn
  1227. )
  1228.  
  1229. line.set_xy2(
  1230. phl.bottom
  1231. , b.n + 50
  1232. , phl.tdn
  1233. )
  1234.  
  1235. label.set_x(
  1236. lbl
  1237. , b.n + 50
  1238. )
  1239.  
  1240. label.set_y(
  1241. lbl
  1242. , phl.tdn
  1243. )
  1244.  
  1245. dist = math.abs(phl.dV / (phl.uV + phl.dV)) * 100
  1246. label.set_text (lbl, trend > 0
  1247. ? "Strong Low | " + str.tostring(phl.dV, format.volume) + " (" + str.tostring(math.round(dist,0)) + "%)"
  1248. : "Weak Low | " + str.tostring(phl.uV, format.volume) + " (" + str.tostring(math.round(dist,0)) + "%)")
  1249.  
  1250. midphl() =>
  1251.  
  1252. avg = math.avg(phl.bottom.get_y2(), phl.top.get_y2())
  1253.  
  1254. var line l = line.new(
  1255. y1 = avg
  1256. , y2 = avg
  1257. , x1 = b.n - sLen
  1258. , x2 = b.n + 50
  1259. , color = midlvl
  1260. , style = line.style_solid
  1261. )
  1262.  
  1263. var label lbl = label.new(
  1264. x = b.n + 50
  1265. , y = avg
  1266. , text = "Equilibrium"
  1267. , style = label.style_label_left
  1268. , color = invcol
  1269. , textcolor = midlvl
  1270. , size = size.small
  1271. )
  1272.  
  1273. if barstate.islast
  1274.  
  1275. more = (phl.bottom.get_x1() + phl.bottom.get_x2()) > (phl.top.get_x1() + phl.top.get_x2()) ? phl.top.get_x1() : phl.bottom.get_x1()
  1276. line.set_xy1(l , more , avg)
  1277. line.set_xy2(l , b.n + 50, avg)
  1278. label.set_x (lbl , b.n + 50 )
  1279. label.set_y (lbl , avg )
  1280. dist = math.abs((l.get_y2() - close) / close) * 100
  1281. label.set_text (lbl, "Equilibrium (" + str.tostring(math.round(dist,0)) + "%)")
  1282.  
  1283. hqlzone() =>
  1284.  
  1285. if barstate.islast
  1286.  
  1287. var hqlzone dZone = hqlzone.new(
  1288. box.new(
  1289. na
  1290. , na
  1291. , na
  1292. , na
  1293. , bgcolor = color.new(toplvl, 70)
  1294. , border_color = na
  1295. )
  1296. , box.new(
  1297. na
  1298. , na
  1299. , na
  1300. , na
  1301. , bgcolor = color.new(midlvl, 70)
  1302. , border_color = na
  1303. )
  1304. , box.new(
  1305. na
  1306. , na
  1307. , na
  1308. , na
  1309. , bgcolor = color.new(btmlvl, 70)
  1310. , border_color = na
  1311. )
  1312.  
  1313. , label.new(na, na, text = "Premium" , color = invcol, textcolor = toplvl, style = label.style_label_down, size = size.small)
  1314. , label.new(na, na, text = "Equilibrium", color = invcol, textcolor = midlvl, style = label.style_label_left, size = size.small)
  1315. , label.new(na, na, text = "Discount" , color = invcol, textcolor = btmlvl, style = label.style_label_up , size = size.small)
  1316. )
  1317.  
  1318. dZone.pbx.set_lefttop(int(math.max(phl.topx, phl.bottomx)) , phl.tup)
  1319. dZone.pbx.set_rightbottom(b.n + 50 , 0.95 * phl.tup + 0.05 * phl.tdn)
  1320.  
  1321. dZone.ebx.set_lefttop(int(math.max(phl.topx, phl.bottomx)), 0.525 * phl.tup + 0.475 * phl.tdn)
  1322. dZone.ebx.set_rightbottom(b.n + 50 , 0.525 * phl.tdn + 0.475 * phl.tup)
  1323.  
  1324. dZone.lbx.set_lefttop(int(math.max(phl.topx, phl.bottomx)), 0.95 * phl.tdn + 0.05 * phl.tup)
  1325. dZone.lbx.set_rightbottom(b.n + 50 , phl.tdn)
  1326.  
  1327. dZone.plb.set_xy( int(math.avg(math.max(phl.topx, phl.bottomx), int(b.n + 50))) , phl.tup)
  1328. dZone.elb.set_xy( int(b.n + 50) , math.avg(phl.tup, phl.tdn))
  1329. dZone.lbl.set_xy( int(math.avg(math.max(phl.topx, phl.bottomx), int(b.n + 50))) , phl.tdn)
  1330.  
  1331.  
  1332.  
  1333. if show_mtb
  1334.  
  1335. upphl (trend)
  1336. dnphl (trend)
  1337. hqlzone()
  1338.  
  1339. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1340. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1341. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1342. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1343. //{ - End }
  1344. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1345. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1346. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1347. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1381. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1382. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1383. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1384. //{ - Volumetric Order Block }
  1385. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1386. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1387. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1388. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1389.  
  1390.  
  1391. method eB(box[] b, bool ext, color css, bool swing) =>
  1392. b.unshift(
  1393. box.new(
  1394. na
  1395. , na
  1396. , na
  1397. , na
  1398. , xloc = xloc.bar_time
  1399. , text_font_family = font.family_monospace
  1400. , extend = ext ? extend.right : extend.none
  1401. , border_color = swing ? color.new(css, 0) : color.new(color.white,100)
  1402. , bgcolor = css
  1403. , border_width = 1
  1404. )
  1405. )
  1406.  
  1407. method eL(line[] l, bool ext, bool solid, color css) =>
  1408. l.unshift(
  1409. line.new(
  1410. na
  1411. , na
  1412. , na
  1413. , na
  1414. , width = 1
  1415. , color = css
  1416. , xloc = xloc.bar_time
  1417. , extend = ext ? extend.right : extend.none
  1418. , style = solid ? line.style_solid : line.style_dashed
  1419. )
  1420. )
  1421.  
  1422. method drawVOB(bool cdn, bool bull, color css, int loc, bool swing) =>
  1423.  
  1424. [cC, oO, hH, lL, vV] = request.security(
  1425. syminfo.tickerid
  1426. , ""
  1427.  
  1428. , [
  1429.  
  1430. close
  1431. , open
  1432. , high
  1433. , low
  1434. , volume
  1435.  
  1436. ]
  1437.  
  1438. , lookahead = barmerge.lookahead_off
  1439. )
  1440. var obC obj = obC.new(
  1441. array.new<float>()
  1442. , array.new<float>()
  1443. , array.new< int >()
  1444. , array.new<float>()
  1445. , array.new<float>()
  1446. , array.new<float>()
  1447. , array.new< int >()
  1448. , array.new< int >()
  1449. , array.new< int >()
  1450. , array.new< int >()
  1451. , array.new<float>()
  1452. , array.new<float>()
  1453. , array.new< int >()
  1454. )
  1455.  
  1456. var obD draw = obD.new(
  1457. array.new<box >()
  1458. , array.new<box >()
  1459. , array.new<box >()
  1460. , array.new<box >()
  1461. , array.new<line>()
  1462. )
  1463.  
  1464. if barstate.isfirst
  1465.  
  1466. for i = 0 to ob_num - 1
  1467.  
  1468. draw.mL .eL(false, false, use_grayscale ? color.new(color.gray, 0) : color.new(css,0))
  1469. draw.ob .eB(false, use_grayscale ? color.new(color.gray, 90) : css, swing)
  1470. draw.blB.eB(false, css_metric_up , swing)
  1471. draw.brB.eB(false, css_metric_dn , swing)
  1472. draw.eOB.eB(true , use_grayscale ? color.new(color.gray, 90) : css, swing)
  1473.  
  1474. float pos = ob_pos == "Full"
  1475. ? (bull ? high : low)
  1476. : ob_pos == "Middle"
  1477. ? ohlc4
  1478. : ob_pos == "Accurate"
  1479. ? hl2
  1480. : hl2
  1481.  
  1482. if cdn
  1483.  
  1484. obj.h.clear()
  1485. obj.l.clear()
  1486. obj.n.clear()
  1487.  
  1488. for i = 0 to math.abs((loc - b.n)) - 1
  1489.  
  1490. obj.h.push(hH[i])
  1491. obj.l.push(lL[i])
  1492. obj.n.push(b.t[i])
  1493.  
  1494. // obj.h.reverse()
  1495. // obj.l.reverse()
  1496.  
  1497. int iU = obj.l.indexof(obj.l.min()) + 1
  1498. int iD = obj.h.indexof(obj.h.max()) + 1
  1499.  
  1500. obj.dir.unshift(
  1501. bull
  1502. ? (b.c[iU] > b.o[iU] ? 1 : -1)
  1503. : (b.c[iD] > b.o[iD] ? 1 : -1)
  1504. )
  1505.  
  1506. obj.top.unshift(
  1507. bull
  1508. ? pos[iU]
  1509. : obj.h.max()
  1510. )
  1511.  
  1512. obj.btm.unshift(
  1513. bull
  1514. ? obj.l.min()
  1515. : pos[iD]
  1516. )
  1517.  
  1518. obj.left.unshift(
  1519. bull
  1520. ? obj.n.get(obj.l.indexof(obj.l.min()))
  1521. : obj.n.get(obj.h.indexof(obj.h.max()))
  1522. )
  1523.  
  1524. obj.avg.unshift(
  1525. math.avg(obj.top.first(), obj.btm.first())
  1526. )
  1527.  
  1528. obj.cV.unshift(
  1529. bull
  1530. ? b.v[iU]
  1531. : b.v[iD]
  1532. )
  1533.  
  1534. if ob_pos == "Precise"
  1535.  
  1536. switch bull
  1537. true =>
  1538. if obj.avg.get(0) < (b.c[iU] < b.o[iU] ? b.c[iU] : b.o[iU]) and obj.top.get(0) > hlcc4[iU]
  1539. obj.top.set(0, obj.avg.get(0))
  1540. obj.avg.set(0, math.avg(obj.top.first(), obj.btm.first()))
  1541. false =>
  1542. if obj.avg.get(0) > (b.c[iU] < b.o[iU] ? b.o[iD] : b.c[iD]) and obj.btm.get(0) < hlcc4[iD]
  1543. obj.btm.set(0, obj.avg.get(0))
  1544. obj.avg.set(0, math.avg(obj.top.first(), obj.btm.first()))
  1545.  
  1546. obj.blVP.unshift ( 0 )
  1547. obj.brVP.unshift ( 0 )
  1548. obj.wM .unshift ( 1 )
  1549.  
  1550. if use_overlap
  1551.  
  1552. int rmP = use_overlap_method == "Recent" ? 1 : 0
  1553.  
  1554. if obj.avg.size() > 1
  1555.  
  1556. if bull
  1557.  
  1558. ? obj.btm.first() < obj.top.get(1)
  1559. : obj.top.first() > obj.btm.get(1)
  1560. obj.wM .remove(rmP)
  1561. obj.cV .remove(rmP)
  1562. obj.dir .remove(rmP)
  1563. obj.top .remove(rmP)
  1564. obj.avg .remove(rmP)
  1565. obj.btm .remove(rmP)
  1566. obj.left .remove(rmP)
  1567. obj.blVP .remove(rmP)
  1568. obj.brVP .remove(rmP)
  1569.  
  1570. if barstate.isconfirmed
  1571.  
  1572. for x = 0 to ob_num - 1
  1573.  
  1574. tg = switch ob_mitigation
  1575. "Middle" => obj.avg
  1576. "Absolute" => bull ? obj.btm : obj.top
  1577.  
  1578. for [idx, pt] in tg
  1579.  
  1580. if (bull ? cC < pt : cC > pt)
  1581. obj.wM .remove(idx)
  1582. obj.cV .remove(idx)
  1583. obj.dir .remove(idx)
  1584. obj.top .remove(idx)
  1585. obj.avg .remove(idx)
  1586. obj.btm .remove(idx)
  1587. obj.left .remove(idx)
  1588. obj.blVP .remove(idx)
  1589. obj.brVP .remove(idx)
  1590.  
  1591. if barstate.islast
  1592.  
  1593. if obj.avg.size() > 0
  1594.  
  1595. // Alert
  1596.  
  1597. if bull
  1598. ? ta.crossunder(low , obj.top.get(0))
  1599. : ta.crossover (high, obj.btm.get(0))
  1600. switch bull
  1601. true => blalert.obtouch := true
  1602. false => bralert.obtouch := true
  1603.  
  1604.  
  1605. float tV = 0
  1606. obj.dV.clear()
  1607. seq = math.min(ob_num - 1, obj.avg.size() - 1)
  1608.  
  1609. for j = 0 to seq
  1610.  
  1611. tV += obj.cV.get(j)
  1612.  
  1613. if j == seq
  1614.  
  1615. for y = 0 to seq
  1616.  
  1617. obj.dV.unshift(
  1618. math.floor(
  1619. (obj.cV.get(y) / tV) * 100)
  1620. )
  1621.  
  1622. obj.dV.reverse()
  1623.  
  1624. for i = 0 to math.min(ob_num - 1, obj.avg.size() - 1)
  1625.  
  1626. dmL = draw.mL .get(i)
  1627. dOB = draw.ob .get(i)
  1628. dblB = draw.blB.get(i)
  1629. dbrB = draw.brB.get(i)
  1630. deOB = draw.eOB.get(i)
  1631.  
  1632. dOB.set_lefttop (obj.left .get(i) , obj.top.get(i))
  1633. deOB.set_lefttop (b.t , obj.top.get(i))
  1634. dOB.set_rightbottom (b.t , obj.btm.get(i))
  1635. deOB.set_rightbottom(b.t + (b.t - b.t[1]) * 100 , obj.btm.get(i))
  1636.  
  1637. if use_middle_line
  1638.  
  1639. dmL.set_xy1(obj.left.get(i), obj.avg.get(i))
  1640. dmL.set_xy2(b.t , obj.avg.get(i))
  1641.  
  1642. if ob_metrics_show
  1643.  
  1644. dblB.set_lefttop (obj.left.get(i), obj.top.get(i))
  1645. dbrB.set_lefttop (obj.left.get(i), obj.avg.get(i))
  1646. dblB.set_rightbottom(obj.left.get(i), obj.avg.get(i))
  1647. dbrB.set_rightbottom(obj.left.get(i), obj.btm.get(i))
  1648.  
  1649. rpBL = dblB.get_right()
  1650. rpBR = dbrB.get_right()
  1651. dbrB.set_right(rpBR + (b.t - b.t[1]) * obj.brVP.get(i))
  1652. dblB.set_right(rpBL + (b.t - b.t[1]) * obj.blVP.get(i))
  1653.  
  1654. if use_show_metric
  1655.  
  1656. txt = switch
  1657.  
  1658. obj.cV.get(i) >= 1000000000 => str.tostring(math.round(obj.cV.get(i) / 1000000000,3)) + "B"
  1659. obj.cV.get(i) >= 1000000 => str.tostring(math.round(obj.cV.get(i) / 1000000,3)) + "M"
  1660. obj.cV.get(i) >= 1000 => str.tostring(math.round(obj.cV.get(i) / 1000,3)) + "K"
  1661. obj.cV.get(i) < 1000 => str.tostring(math.round(obj.cV.get(i)))
  1662.  
  1663. deOB.set_text(
  1664. str.tostring(
  1665. txt + " (" + str.tostring(obj.dV.get(i)) + "%)")
  1666. )
  1667.  
  1668. deOB.set_text_size (size.auto)
  1669. deOB.set_text_halign(text.align_left)
  1670. deOB.set_text_color (use_grayscale ? color.silver : color.new(css, 0))
  1671.  
  1672. if ob_metrics_show and barstate.isconfirmed
  1673.  
  1674. if obj.wM.size() > 0
  1675.  
  1676. for i = 0 to obj.avg.size() - 1
  1677.  
  1678. switch obj.dir.get(i)
  1679.  
  1680. 1 =>
  1681.  
  1682. switch obj.wM.get(i)
  1683.  
  1684. 1 => obj.blVP.set(i, obj.blVP.get(i) + 1), obj.wM.set(i, 2)
  1685. 2 => obj.blVP.set(i, obj.blVP.get(i) + 1), obj.wM.set(i, 3)
  1686. 3 => obj.brVP.set(i, obj.brVP.get(i) + 1), obj.wM.set(i, 1)
  1687. -1 =>
  1688.  
  1689. switch obj.wM.get(i)
  1690.  
  1691. 1 => obj.brVP.set(i, obj.brVP.get(i) + 1), obj.wM.set(i, 2)
  1692. 2 => obj.brVP.set(i, obj.brVP.get(i) + 1), obj.wM.set(i, 3)
  1693. 3 => obj.blVP.set(i, obj.blVP.get(i) + 1), obj.wM.set(i, 1)
  1694.  
  1695. var hN = array.new<int>(1, b.n)
  1696. var lN = array.new<int>(1, b.n)
  1697. var hS = array.new<int>(1, b.n)
  1698. var lS = array.new<int>(1, b.n)
  1699.  
  1700. if iH
  1701.  
  1702. hN.pop()
  1703. hN.unshift(int(b.n[iLen]))
  1704.  
  1705. if iL
  1706.  
  1707. lN.pop()
  1708. lN.unshift(int(b.n[iLen]))
  1709.  
  1710. if sH
  1711.  
  1712. hS.pop()
  1713. hS.unshift(int(b.n[sLen]))
  1714.  
  1715. if sL
  1716.  
  1717. lS.pop()
  1718. lS.unshift(int(b.n[sLen]))
  1719.  
  1720. if ob_show
  1721.  
  1722. bull_ob.drawVOB(true , ob_bull_css, hN.first(), false)
  1723. bear_ob.drawVOB(false, ob_bear_css, lN.first(), false)
  1724.  
  1725.  
  1726. if ob_swings
  1727.  
  1728. s_bull_ob.drawVOB(true , css_swing_up, hS.first(), true)
  1729. s_bear_ob.drawVOB(false, css_swing_dn, lS.first(), true)
  1730.  
  1731. if bull_ob
  1732. blalert.ob := true
  1733.  
  1734. if bear_ob
  1735. bralert.ob := true
  1736.  
  1737. if s_bull_ob
  1738. blalert.swingob := true
  1739.  
  1740. if s_bear_ob
  1741. blalert.swingob := true
  1742.  
  1743. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1744. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1745. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1746. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1747. //{ - End }
  1748. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1749. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1750. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1751. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1787. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1788. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1789. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1790. //{ - FVG | VI | OG }
  1791. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1792. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1793. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1794. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1795.  
  1796. ghl() => request.security(syminfo.tickerid, fvg_tf, [high[2], low[2], close[1], open[1]])
  1797. tfG() => request.security(syminfo.tickerid, fvg_tf, [open, high, low, close])
  1798.  
  1799. cG(bool bull) =>
  1800.  
  1801. [h, l, c, o] = ghl()
  1802. [go, gh, gl, gc] = tfG()
  1803.  
  1804. var FVG draw = FVG.new(
  1805. array.new<box>()
  1806. , array.new<line>()
  1807. )
  1808.  
  1809. var FVG[] cords = array.new<FVG>()
  1810.  
  1811. float pup = na
  1812. float pdn = na
  1813. bool cdn = na
  1814. int pos = 2
  1815. cc = timeframe.change(fvg_tf)
  1816.  
  1817. if barstate.isfirst
  1818.  
  1819. for i = 0 to fvg_num - 1
  1820.  
  1821. draw.box.unshift(box.new (na, na, na, na, border_color = color.new(color.white, 100), xloc = xloc.bar_time))
  1822. draw.ln.unshift (line.new(na, na, na, na, xloc = xloc.bar_time, width = 1, style = line.style_solid))
  1823.  
  1824. switch what_fvg
  1825.  
  1826. "FVG" =>
  1827.  
  1828. pup := bull ? gl : l
  1829. pdn := bull ? h : gh
  1830. cdn := bull ? gl > h and cc : gh < l and cc
  1831. pos := 2
  1832.  
  1833. "VI" =>
  1834.  
  1835. pup := bull
  1836. ? (gc > go
  1837. ? go
  1838. : gc)
  1839. : (gc[1] > go[1]
  1840. ? go[1]
  1841. : gc[1])
  1842. pdn := bull
  1843. ? (gc[1] > go[1]
  1844. ? gc[1]
  1845. : go[1])
  1846. : (gc > go
  1847. ? gc
  1848. : go)
  1849. cdn := bull
  1850. ? go > gc[1] and gh[1] > gl and gc > gc[1] and go > go[1] and gh[1] < math.min(gc, go) and cc
  1851. : go < gc[1] and gl[1] < gh and gc < gc[1] and go < go[1] and gl[1] > math.max(gc, go) and cc
  1852. pos := 1
  1853.  
  1854. "OG" =>
  1855.  
  1856. pup := bull ? b.l : gl[1]
  1857. pdn := bull ? gh[1] : gh
  1858. cdn := bull ? gl > gh[1] and cc : gh < gl[1] and cc
  1859. pos := 1
  1860.  
  1861. if not na(cdn[1]) and cdn[1]
  1862.  
  1863. cords.unshift(
  1864. FVG.new(
  1865. na
  1866. , na
  1867. , bull
  1868. ? true
  1869. : false
  1870. , pup[1]
  1871. , pdn[1]
  1872. , b.t - (b.t - b.t[1]) * pos + 1
  1873. , b.t + (b.t - b.t[1]) * fvg_extend + 1)
  1874. )
  1875.  
  1876. if bull
  1877. blalert.fvg := true
  1878. else
  1879. bralert.fvg := true
  1880.  
  1881. if barstate.isconfirmed
  1882.  
  1883. for [idx, obj] in cords
  1884.  
  1885. if obj.bull ? b.c < obj.btm : b.c > obj.top
  1886.  
  1887. cords.remove(idx)
  1888.  
  1889. if barstate.islast
  1890.  
  1891. if cords.size() > 0
  1892.  
  1893. for i = math.min(fvg_num - 1, cords.size() - 1) to 0
  1894.  
  1895. gbx = draw.box.get(i)
  1896. gln = draw.ln.get(i)
  1897. gcd = cords.get(i)
  1898.  
  1899. gtop = gcd.top
  1900. gbtm = gcd.btm
  1901. left = gcd.left
  1902. right = gcd.right
  1903.  
  1904. gbx.set_lefttop(left, gtop)
  1905. gbx.set_rightbottom(right, gbtm)
  1906. gbx.set_bgcolor(gcd.bull ? fvg_upcss : fvg_dncss)
  1907.  
  1908. gln.set_xy1(left, math.avg(gbx.get_top(), gbx.get_bottom()))
  1909. gln.set_xy2(right, math.avg(gbx.get_top(), gbx.get_bottom()))
  1910. gln.set_color(gcd.bull ? fvg_upcss : fvg_dncss)
  1911.  
  1912. if fvg_enable
  1913.  
  1914. cG(true )
  1915. cG(false)
  1916.  
  1917. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1918. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1919. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1920. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1921. //{ - END }
  1922. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1923. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1924. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1925. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1961. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1962. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1963. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1964. //{ - Accumulation And Distribution }
  1965. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1966. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1967. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1968. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  1969.  
  1970. drawZone(int len) =>
  1971. var zone[] z = array.new<zone>()
  1972.  
  1973. if iH
  1974.  
  1975. z.unshift(
  1976. zone.new(
  1977. chart.point.from_time(
  1978. time[len]
  1979. , high [len]
  1980. )
  1981. , high [len]
  1982. , 1
  1983. , time[len]
  1984. )
  1985. )
  1986. if iL
  1987. z.unshift(
  1988. zone.new(
  1989. chart.point.from_time(
  1990. time[len]
  1991. , low [len]
  1992. )
  1993. , low [len]
  1994. , -1
  1995. , time[len]
  1996. )
  1997. )
  1998. if z.size() > 1
  1999. if z.get(0).c == z.get(1).c
  2000. z.clear()
  2001.  
  2002. switch
  2003.  
  2004. zone_mode == "Slow" =>
  2005.  
  2006. if z.size() > 5
  2007.  
  2008. if z.get(0).c == -1 and z.get(1).c == 1 and z.get(2).c == -1 and z.get(3).c == 1 and z.get(4).c == -1 and z.get(5).c == 1
  2009.  
  2010. if z.get(0).p > z.get(2).p and z.get(2).p > z.get(4).p
  2011.  
  2012. if z.get(1).p < z.get(3).p and z.get(3).p < z.get(5).p
  2013.  
  2014. blalert.zone := true
  2015.  
  2016. box.new(top = z.get(5).p, bottom = z.get(4).p, left = z.get(5).t, right = z.get(0).t, bgcolor = acc_css, border_color = color.new(color.white, 100), xloc = xloc.bar_time)
  2017. slice = array.new<chart.point>()
  2018.  
  2019. for i = 0 to 5
  2020.  
  2021. slice.unshift(z.get(i).points)
  2022.  
  2023. polyline.new(slice, xloc = xloc.bar_time, line_color = color.new(acc_css, 0), line_width = 2)
  2024. p.found := "Accumulation Zone"
  2025. p.bull := true
  2026. p.isfound := true
  2027. p.period := 0
  2028. z.clear()
  2029.  
  2030. if z.size() > 5
  2031.  
  2032. if z.get(0).c == 1 and z.get(1).c == -1 and z.get(2).c == 1 and z.get(3).c == -1 and z.get(4).c == 1 and z.get(5).c == -1
  2033.  
  2034. if z.get(0).p < z.get(2).p and z.get(2).p < z.get(4).p
  2035.  
  2036. if z.get(1).p > z.get(3).p and z.get(3).p > z.get(5).p
  2037.  
  2038. bralert.zone := true
  2039.  
  2040. box.new(top = z.get(5).p, bottom = z.get(4).p, left = z.get(5).t, right = z.get(0).t, bgcolor = dist_css, border_color = color.new(color.white, 100), xloc = xloc.bar_time)
  2041. slice = array.new<chart.point>()
  2042.  
  2043. for i = 0 to 5
  2044.  
  2045. slice.unshift(z.get(i).points)
  2046.  
  2047. polyline.new(slice, xloc = xloc.bar_time, line_color = color.new(dist_css, 0), line_width = 2)
  2048. p.found := "Distribution Zone"
  2049. p.bull := false
  2050. p.isfound := true
  2051. p.period := 0
  2052. z.clear()
  2053.  
  2054. zone_mode == "Fast" =>
  2055.  
  2056. if z.size() > 3
  2057.  
  2058. if z.get(0).c == -1 and z.get(1).c == 1 and z.get(2).c == -1 and z.get(3).c == 1
  2059.  
  2060. if z.get(0).p > z.get(2).p
  2061.  
  2062. if z.get(1).p < z.get(3).p
  2063.  
  2064. blalert.zone := true
  2065.  
  2066. box.new(top = z.get(3).p, bottom = z.get(2).p, left = z.get(3).t, right = z.get(0).t, bgcolor = acc_css, border_color = color.new(color.white, 100), xloc = xloc.bar_time)
  2067. slice = array.new<chart.point>()
  2068.  
  2069. for i = 0 to 3
  2070.  
  2071. slice.unshift(z.get(i).points)
  2072.  
  2073. polyline.new(slice, xloc = xloc.bar_time, line_color = color.new(acc_css, 0), line_width = 2)
  2074. p.found := "Accumulation Zone"
  2075. p.bull := true
  2076. p.isfound := true
  2077. p.period := 0
  2078. z.clear()
  2079.  
  2080. if z.size() > 3
  2081.  
  2082. if z.get(0).c == 1 and z.get(1).c == -1 and z.get(2).c == 1 and z.get(3).c == -1
  2083.  
  2084. if z.get(0).p < z.get(2).p
  2085.  
  2086. if z.get(1).p > z.get(3).p
  2087.  
  2088. bralert.zone := true
  2089.  
  2090. box.new(top = z.get(2).p, bottom = z.get(3).p, left = z.get(3).t, right = z.get(0).t, bgcolor = dist_css, border_color = color.new(color.white, 100), xloc = xloc.bar_time)
  2091. slice = array.new<chart.point>()
  2092.  
  2093. for i = 0 to 3
  2094.  
  2095. slice.unshift(z.get(i).points)
  2096.  
  2097. polyline.new(slice, xloc = xloc.bar_time, line_color = color.new(dist_css, 0), line_width = 2)
  2098. p.found := "Distribution Zone"
  2099. p.bull := false
  2100. p.isfound := true
  2101. p.period := 0
  2102. z.clear()
  2103.  
  2104. if show_acc_dist_zone
  2105.  
  2106. drawZone(iLen)
  2107.  
  2108. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2109. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2110. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2111. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2112. //{ - END }
  2113. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2114. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2115. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2116. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2117.  
  2118.  
  2119.  
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2152. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2153. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2154. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2155. //{ - EQH / EQL }
  2156. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2157. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2158. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2159. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2160.  
  2161. dEHL() =>
  2162.  
  2163. var ehl w = ehl.new(0, 0, 0, 0)
  2164. top = ta.pivothigh(high, 1, 1)
  2165. btm = ta.pivotlow(low , 1, 1)
  2166. atr = ta.atr(200)
  2167.  
  2168. switch
  2169.  
  2170. top =>
  2171.  
  2172. mx = math.max(top, w.pt)
  2173. mn = math.min(top, w.pt)
  2174.  
  2175. switch
  2176.  
  2177. mx < mn + atr * 0.1 =>
  2178.  
  2179. var aZ = array.new<line>()
  2180. var aL = array.new<label>()
  2181.  
  2182. if aZ.size() > 50
  2183.  
  2184. aZ.pop().delete()
  2185. aL.pop().delete()
  2186.  
  2187. aZ.unshift(line.new(w.t, w.pt, b.n - 1, top, color = i_ms_dn_BOS, style = line.style_dotted))
  2188. aL.unshift(label.new(int(math.avg(b.n - 1, w.t)), top, "EQH", color = invcol, textcolor = i_ms_dn_BOS, style = label.style_label_down, size = size.tiny))
  2189.  
  2190. bralert.equal := true
  2191.  
  2192. w.pt := top
  2193. w.t := b.n - 1
  2194.  
  2195. btm =>
  2196.  
  2197. mx = math.max(btm, w.pb)
  2198. mn = math.min(btm, w.pb)
  2199.  
  2200. switch
  2201.  
  2202. mn > mx - atr * 0.1 =>
  2203.  
  2204. var aZ = array.new<line>()
  2205. var aL = array.new<label>()
  2206.  
  2207. if aZ.size() > 50
  2208.  
  2209. aZ.pop().delete()
  2210. aL.pop().delete()
  2211.  
  2212. aZ.unshift(line.new(w.b, w.pb, b.n - 1, btm, color = i_ms_up_BOS, style = line.style_dotted))
  2213. aL.unshift(label.new(int(math.avg(b.n - 1, w.b)), btm, "EQL", color = invcol, textcolor = i_ms_up_BOS, style = label.style_label_up, size = size.tiny))
  2214.  
  2215. blalert.equal := true
  2216.  
  2217. w.pb := btm
  2218. w.b := b.n - 1
  2219.  
  2220.  
  2221. if show_eql
  2222. dEHL()
  2223.  
  2224. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2225. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2226. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2227. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2228. //{ - End }
  2229. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2230. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2231. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2232. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2268. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2269. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2270. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2271. //{ - Plotting And Coloring }
  2272. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2273. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2274. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2275. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2276.  
  2277. p_css = css
  2278. b_css = css
  2279. w_css = css
  2280.  
  2281. p_css := plotcandle_bool ? (css) : na
  2282. b_css := barcolor_bool ? (css) : na
  2283. w_css := plotcandle_bool ? color.rgb(120, 123, 134, 50) : na
  2284.  
  2285. plotcandle(open,high,low,close , color = p_css , wickcolor = w_css , bordercolor = p_css , editable = false)
  2286. barcolor(b_css, editable = false)
  2287.  
  2288. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2289. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2290. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2291. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2292. //{ - END }
  2293. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2294. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2295. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2296. //{----------------------------------------------------------------------------------------------------------------------------------------------}
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315. alertcondition(blalert.bos , "Bullish BOS", "Bullish BOS")
  2316. alertcondition(blalert.choch , "Bullish CHOCH", "Bullish CHOCH")
  2317. alertcondition(blalert.chochplus , "Bullish CHOCH+", "Bullish CHOCH+")
  2318. alertcondition(blalert.chochplusswing, "Bullish Swing CHOCH+", "Bullish Swing CHOCH+")
  2319. alertcondition(blalert.chochswing , "Bullish Swing CHOCH", "Bullish CHOCH")
  2320. alertcondition(blalert.swingbos , "Bullish Swing BOS", "Bullish Swing BOS")
  2321. alertcondition(blalert.equal , "EQL", "EQL")
  2322. alertcondition(blalert.fvg , "Bullish FVG", "Bullish FVG")
  2323. alertcondition(blalert.ob , "Bullish Order Block", "Bullish Order Block")
  2324. alertcondition(blalert.swingob , "Bullish Swing Order Block", "Bullish Swing Order Block")
  2325. alertcondition(blalert.zone , "Accumulation Zone", "Accumulation Zone")
  2326. alertcondition(blalert.obtouch , "Candle Entering in a Bullish Order Block", "Candle Entering in a Bullish Order Block")
  2327.  
  2328. alertcondition(bralert.bos , "Bearish BOS", "Bearish BOS")
  2329. alertcondition(bralert.choch , "Bearish CHOCH", "Bearish CHOCH")
  2330. alertcondition(bralert.chochplus , "Bearish CHOCH+", "Bearish CHOCH+")
  2331. alertcondition(bralert.chochplusswing, "Bearish Swing CHOCH+", "Bearish Swing CHOCH+")
  2332. alertcondition(bralert.chochswing , "Bearish Swing CHOCH", "Bearish CHOCH")
  2333. alertcondition(bralert.swingbos , "Bearish Swing BOS", "Bearish Swing BOS")
  2334. alertcondition(bralert.equal , "EQH", "EQH")
  2335. alertcondition(bralert.fvg , "Bearish FVG", "Bearish FVG")
  2336. alertcondition(bralert.ob , "Bearish Order Block", "Bearish Order Block")
  2337. alertcondition(bralert.swingob , "Bearish Swing Order Block", "Bearish Swing Order Block")
  2338. alertcondition(bralert.zone , "Distribution Zone", "Distribution Zone")
  2339. alertcondition(bralert.obtouch , "Candle Entering in a Bearish Order Block", "Candle Entering in a Bearish Order Block")
  2340.  
  2341. if barstate.isfirst
  2342. var table errorBox = table.new(position.bottom_right, 1, 1, bgcolor = color.new(#363a45, 100))
  2343. table.cell(errorBox, 0, 0, "© RUDYBANK INDICATOR", text_color = color.gray, text_halign = text.align_center, text_size = size.normal)
  2344.  
Advertisement
Add Comment
Please, Sign In to add comment