xmd79

CHoCHs+Nested Pivots+FVGs+Grade Sweeps

Apr 9th, 2023
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.36 KB | None | 0 0
  1. // combining CHoCHs with nested Pivot highs and grade sweeps and FVGs
  2. // 27th March 2023
  3. // © twingall
  4.  
  5. //@version=5
  6. indicator("CHoCHs+Nested Pivots+FVGs+Grade Sweeps", overlay = true, max_labels_count = 500, max_bars_back = 5000, max_lines_count = 500, max_boxes_count = 500)
  7.  
  8. // •••• User Inputs: CHoCHs ••••
  9. showChochs = input.bool(true, "• SHOW CHOCHS •", inline ='-2',group ="~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~")
  10. lb_ch = input.int(1, "CHoCH pivots: look-back", inline ='-1', group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~",tooltip = "This is for the very short 3 bar fractal pivots for finding CHoCHs.\n\nDefault/recommended lookback is 1.\n\nYou can experiment with 2, 3, 4 if you like.\n\nNote that Lookforward for these CHoCH pivots is necessarily fixed at 1")
  11. lf_ch =1 //input.int(1, 'CHoCH pivots: look-forward', inline ='0', group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", tooltip = "recommend leaving this set to 1")
  12. showUPchoch = input.bool(true, "UP CHoCH", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='1')
  13. upChochCol = input.color(color.blue, "", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='1')
  14. upIcon = input.string("🢁", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='1', options = ["🢁","▲","🡅","⟰","🡁","⮭"])
  15. upIconSize = input.string(size.normal,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge],group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='1')
  16. showDNchoch = input.bool(true, "DOWN CHoCH", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='2')
  17. dnChochCol = input.color(color.red, "", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='2')
  18. dnIcon = input.string("🢃", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='2', options = ["🢃","▼","🡇","⟱","🡃","⮯"])
  19. dnIconSize = input.string(size.normal,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge],group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='2')
  20. MultiTFcolorOveride = input.bool(false, "Multi-TF Color Override:",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='3', tooltip = "Overrides the above color choices when on the following chart timeframes:\n\n1m | 5m | 15m | H | 4H | D | W | M")
  21. _1minCol = input.color(color.lime, "1",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  22. _5minCol = input.color(color.fuchsia, "5",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  23. _15minCol = input.color(color.gray, "15",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  24. _HCol = input.color(color.teal, "H",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  25. _4hrCol = input.color(color.blue, "4H",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  26. _DCol = input.color(color.yellow, "D",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  27. _WCol = input.color(color.red, "W",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  28. _MCol = input.color(color.green, "M",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='4')
  29. _lineStyleCh = input.string("Dashed", "line", options =["Dashed", "Dotted", "Solid"], group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='5')
  30. lineWidthCh = input.int (1, "width", minval =1, maxval =5,group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='5')
  31. barsBackCh = input.int(70, "bars lookback" , minval = 5, step =1,group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='6')
  32. numActiveChoch = input.int(2, "live CHoCHs", minval = 1,group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='6', tooltip = "this number controls the number of active/open CHoCH lines (either Up or Down); i.e. CHoCH lines that have not yet been met by price\n\nHistorical CHoCH levels that have been hit by price will still print and remain within your lookback period setting")
  33. shrinkChochOnfill = input.bool(false, "shrink CHoCHs once hit",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='7', tooltip = "When price crosses through a CHoCH; the CHoCH will shrink to it's origin bar\n\nFor real-time reading of price action & to declutter chart, toggle this ON\n\nFor backtesting purposes, better to have this toggled OFF")
  34. useHTFchochs = input.bool(true, "HTF CHoCHs",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='8', tooltip = "prints the last up ChoCH and last down CHoCH from user selected HTF, on the LTF chart\n\nTable cell in green or red showing if we are above last HTF UP CHoCH or below last HTF DOWN CHoCH")
  35. HTF = input.timeframe ("D", "input HTF",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='8')
  36. showChochTable = input.bool(true, "show table(above/below)", group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='8')
  37. htfUPcol =input.color(color.green, "// UP",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='9')
  38. htfDNcol =input.color(color.red, "DOWN",group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='9')
  39. _lineStyleChHTF = input.string("Solid", "line", options =["Solid", "Dashed", "Dotted"], group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='9')
  40. lineWidthChHTF = input.int (1, "width", minval =1, maxval =5,group = "~~~~~~~~~~~~~~~~~~~~ CHoCHs ~~~~~~~~~~~~~~~~~~~~", inline ='9')
  41.  
  42. // •••• User Inputs: Pivot Highs and Lows (ST/MT/LT) ••••
  43. showPivHighsLows= input.bool(true, "• SHOW PIVOT HIGHS & LOWS •", inline ='-2',group ='~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  44. barsBack = input.int(2000, "bars lookback" , minval = 5, step =1, group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~',inline ='-1')
  45. lb1 =input.int(15, 'pivots: lookback/forward', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~',inline ='-1', tooltip = "This is the 'root' pivot number; i.e. the STH/STL pivots, from which all the MTH/MTL & LTH/LTL are based on\n\nlarger number for more significant pivot highs / pivot lows")
  46. useSpikeyCond = input.bool(true, "Apply 'Spikeyness' filter", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='0')
  47. atrMult =input.float(1.3, '|| Spikeyness index', minval = 0, step =0.1, group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='0', tooltip = "For catching only the 'spiky' pivot highs/pivot lows\n\nIncreasing this number will filter out smooth/unimpressive pivot high&lows\n\nRepresents local ATR multiple for distance from local Moving average a high or low must be\n\nSetting of 1.5 seems optimal on 15m chart with pivot lookback/lookforward = 15")
  48.  
  49. lookbackCond = bar_index > last_bar_index - barsBack
  50.  
  51. showSTHs = input.bool(true, "STH", inline='1', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  52. txtColSTH = input.color(color.teal, "", inline ='1', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  53. inputTextStyleSTH = input.string("Ʌ (single)", "Style:", inline='1', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', options = ["Ʌ (single)", "text horizontal", "text vertical" ])
  54. sizeSTH = input.string(size.normal,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='1')
  55. showSTHlines = input.bool(false, "line", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='1')
  56. showMTHs = input.bool(true, "MTH", inline='3', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  57. txtColMTH = input.color(color.blue, "", inline ='3', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  58. inputTextStyleMTH = input.string("text horizontal", "Style:", inline='3', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', options = ["Ʌ (double)" ,"text horizontal", "text vertical"])
  59. sizeMTH = input.string(size.normal,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='3')
  60. showMTHlines = input.bool(false, "line", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='3')
  61. showLTHs = input.bool(true, "LTH", inline='5', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  62. txtColLTH = input.color(color.green, "", inline ='5', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  63. inputTextStyleLTH = input.string("text horizontal", "Style:", inline='5', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', options = ["Ʌ (triple)","text horizontal", "text vertical" ])
  64. sizeLTH = input.string(size.large,"Size:", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='5')
  65. showLTHlines = input.bool(false, "line", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='5')
  66.  
  67. showSTLs = input.bool(true, "STL", inline='2', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  68. txtColSTL = input.color(color.orange, "", inline ='2', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  69. inputTextStyleSTL = input.string("V (single)", "Style:", inline='2', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', options = ["V (single)", "text horizontal", "text vertical" ])
  70. sizeSTL = input.string(size.normal,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='2')
  71. showSTLlines = input.bool(false, "line", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='2')
  72. showMTLs = input.bool(true, "MTL", inline='4', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  73. txtColMTL = input.color(color.fuchsia, "", inline ='4', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  74. inputTextStyleMTL = input.string("text horizontal", "Style:", inline='4', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', options = ["V (double)" ,"text horizontal", "text vertical"])
  75. sizeMTL = input.string(size.normal,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='4')
  76. showMTLlines = input.bool(false, "line", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='4')
  77. showLTLs = input.bool(true, "LTL", inline='6', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  78. txtColLTL = input.color(color.red, "", inline ='6', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~')
  79. inputTextStyleLTL = input.string("text horizontal", "Style:", inline='6', group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', options = ["V (triple)","text horizontal", "text vertical" ])
  80. sizeLTL = input.string(size.large,"Size", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='6')
  81. showLTLlines = input.bool(false, "line", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline='6')
  82.  
  83. unit_1 = input.float(0.25, "Label spacer (ATR multiples)",minval = 0, step = 0.25, group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='7', tooltip = "spacer above/below for pivot labels, based on multiples of ATR (long-term average true range)")
  84. lineStyleInput = input.string("Dotted", "LINES: Style", options =["Dashed", "Dotted", "Solid"], group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='8')
  85. lineWidth = input.int (1, "line width", minval =1, maxval =5,group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='8')
  86. showTable = input.bool(true, "Table", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='9' )
  87. tabPos = input.string(position.top_right, "|| Position:", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='9', options = [ position.top_left, position.top_center, position.top_right, position.middle_left, position.middle_center, position.middle_right, position.bottom_left, position.bottom_center, position.bottom_right])
  88. tabCol = input.color(color.new(color.blue, 60), "|| Bg Color:", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='9')
  89. txtCol = input.color(color.purple, "|| txt Color:", group = '~~~~~~~~~~~ pivot highs & lows (ST,MT,LT) ~~~~~~~~~~', inline ='9')
  90.  
  91. // •••• User Inputs: Sweep Boxes ••••
  92. showSweepBoxes = input.bool(true, "• SHOW SWEEP BOXES •", inline ='0',group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  93. showSTHboxes =input.bool(true, "STH", inline='1', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  94. STHbxCol = input.color(color.new(color.blue, 80), "", inline='1', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  95. showSTLboxes =input.bool(true, "STL", inline='1', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  96. STLbxCol = input.color(color.new(color.red, 80), "", inline='1', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  97. unitsST = input.float(5, "|| Sweep grade ($/pips)", inline='1', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~', tooltip = "'Sweep grade' = box height in $ or pips\n\nHeight of box beyond pivot high/low\n\nAuto detects units: USD $ for Indices/Commodities/Crypto; pips for FX\n\nS&P recommended settings = 5$ or 10$\n\nFX recommended settings = 10, 20, 30\n\nBonds recommended settings = 0.125 (4 ticks), 0.25 ( 8 ticks), 0.5 (16 ticks), 1 (32 ticks); where $1 = 32 ticks\n\nBitcoin recommmended settings = 50, 100, 200, 500. 1000\n\nCrypto: choose any number from 0.000001$ (very low unit value crypto coin) to 1000$ (Bitcoin swing trading)\n\nAlerts will be based on this input. Choose =0 if you're just interested in touch/peep of the pivot high or low")
  98.  
  99. showMTHboxes =input.bool(true, "MTH", inline='2', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  100. MTHbxCol = input.color(color.new(color.fuchsia, 80), "", inline='2', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  101. showMTLboxes =input.bool(true, "MTL", inline='2', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  102. MTLbxCol = input.color(color.new(color.orange, 80), "", inline='2', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  103. unitsMT = input.float(10, "|| Sweep grade ($/pips)", inline='2', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  104.  
  105. showLTHboxes =input.bool(true, "LTH", inline='3', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  106. LTHbxCol = input.color(color.new(color.green, 80), "", inline='3', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  107. showLTLboxes =input.bool(true, "LTL", inline='3', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  108. LTLbxCol = input.color(color.new(color.maroon, 80), "", inline='3', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  109. unitsLT = input.float(10,"|| Sweep grade ($/pips)", inline='3', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  110. showTxt = input.bool(true, "txt", inline ='4', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  111. txtColbx = input.color(color.maroon, "", inline ='4', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  112. txtSize = input.string(size.small,"", options = [size.auto, size.tiny, size.small, size.normal, size.large, size.huge], inline ='4', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  113. valignChoice = input.string(text.align_center,"Vpos", options = [text.align_top, text.align_center, text.align_bottom], inline ='4', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  114. halignChoice = input.string(text.align_right,"Hpos", options = [text.align_left, text.align_center, text.align_right], inline ='4', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  115. //**edit this to simple float input?? no options??...
  116. //units = input.float(5, "Box Height, 'Sweep grade' ($ or pips)", options = [0, 0.125, 0.25, 0.5, 1,2,3,5,10, 20, 30, 40, 50,100,200,500,1000], group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~', tooltip = "Height of box beyond pivot high/low\n\nAuto detects units (handles($) for indices/commodities; pips for FX\n\nS&P recommended settings = 5 or 10\n\nFX recommended settings = 10, 20, 30\n\nBonds recommended settings = 0.125 (4 ticks), 0.25 ( 8 ticks), 0.5 (16 ticks), 1 (32 ticks); where $1 = 32 ticks\n\nBitcoin recommmended settings = 50, 100, 200, 500. 1000\n\nAlerts will be based on this input. Choose =0 if you're just interested in touch/peep of the pivot high or low")
  117. pUnits = syminfo.type== 'index' or syminfo.type == 'futures'? "$": syminfo.type=='forex'?'pips':"$"
  118. endAtPrice = input.bool(true, "end boxes/lines at price", inline ='5', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~', tooltip = "if set to 1 (default); in realtime, sweep boxes/lines will paint until met/Filled by price; then they will disappear")
  119. numBoxesLines = input.int(1, "|| Historical Boxes/lines:", minval = 1, inline ='5', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~') //** best leave this out, it's only confusing and not working ideally
  120. boxWidth = input.int(10, "// Box width (bars):", inline ='6', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~')
  121. extendChoice = input.bool(false, "extend boxes/lines right", inline ='6', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~', tooltip ="this line of options only applies if the above 'end boxes/lines at price' is toggled OFF")
  122. shrinkGradeSweepsOnFill =input.bool(true, "shrink grade sweeps on fill", inline ='7', group = '~~~~~~~~~~~~~~~ Sweep Boxes ~~~~~~~~~~~~~~~', tooltip ="When price fills a grade sweep box, box will disappear\n\nFor real-time reading of price action & to declutter chart, toggle this ON\n\nFor backtesting purposes, better to have this toggled OFF")
  123.  
  124. // •••• User Inputs: FVGs ••••
  125. showFVGs = input.bool(true, "• Show FVGs •", inline ='-1',group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  126. barsBackFVG = input.int(80, "Bars Lookback", inline ='0',group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  127. showUP = input.bool(true, "'UP' FVGs (BISI):", inline ='1', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  128. colUp = input.color(color.new(color.orange, 70), "", inline ='1', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  129. showDN = input.bool(true, "'DOWN' FVGs (SIBI):", inline ='1', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  130. colDn = input.color(color.new(color.blue, 70), "", inline ='1', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  131. showCE = input.bool(true, "show CE", inline ='3', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  132. ceCol = input.color(color.new(color.black, 1), "| color:", inline ='3', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  133. _ceStyle = input.string("Dotted", "| style:", options=["Dashed", "Dotted", "Solid"], inline ='3', group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~')
  134. CEcond = input.bool (true, "Use CE (as opposed to Full Fill)", group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~', tooltip = "If toggled OFF, FVGs and CEs will paint until FVG has been completely filled.\n\nThis threshold is used for Alert conditions too:\ni.e. this will determine if your 'ABOVE threshold' alert fires when price hits most recent FVG CE ABOVE or most recent FVG Full Fill ABOVE\n\nAlerts are set by clicking the three dots on the indicator display line.")
  135. shrinkFVGonFill = input.bool(true, "shrink FVG on fill (CE hit or Full fill)", group = '~~~~~~~~~~~~~~~~~~~~ FVGs ~~~~~~~~~~~~~~~~~~~~', tooltip ="To declutter chart; FVGs which have had their threshold hit (CE or Full fill, depending on the above checkbox), will shrink to the single bar on which they originated\n\nFor backtesting it would be more useful to have this toggled OFF; for realtime better have it toggled ON")
  136.  
  137. ///////////////////////////////////////////////////////////////////////////
  138. ///////// ##### PIVOT HIGHS, PIVOT LOWS, SWEEP BOXES #####////////////////
  139. ///////////////////////////////////////////////////////////////////////////
  140.  
  141. gradeSweepST = syminfo.type== 'index' or syminfo.type == 'futures'? 1*unitsST:syminfo.type=='forex'? 0.0001*unitsST:1*unitsST
  142. gradeSweepLabST = syminfo.type== 'index' or syminfo.type == 'futures'? str.tostring(gradeSweepST):syminfo.type=='forex'?str.tostring(10000*gradeSweepST): str.tostring(gradeSweepST)
  143. gradeSweepMT = syminfo.type== 'index' or syminfo.type == 'futures'? 1*unitsMT:syminfo.type=='forex'? 0.0001*unitsMT:1*unitsMT
  144. gradeSweepLabMT = syminfo.type== 'index' or syminfo.type == 'futures'? str.tostring(gradeSweepMT):syminfo.type=='forex'?str.tostring(10000*gradeSweepMT): str.tostring(gradeSweepMT)
  145. gradeSweepLT = syminfo.type== 'index' or syminfo.type == 'futures'? 1*unitsLT:syminfo.type=='forex'? 0.0001*unitsLT:1*unitsLT
  146. gradeSweepLabLT = syminfo.type== 'index' or syminfo.type == 'futures'? str.tostring(gradeSweepLT):syminfo.type=='forex'?str.tostring(10000*gradeSweepLT): str.tostring(gradeSweepLT)
  147. //##
  148. atrSpacer = ta.atr(300)
  149. colorNone=color.new(color.white, 100)
  150.  
  151. string lineStyle = switch lineStyleInput
  152. "Dotted" => line.style_dotted
  153. "Dashed" => line.style_dashed
  154. "Solid" => line.style_solid
  155.  
  156. string textStyleSTH = switch inputTextStyleSTH
  157. "Ʌ (single)" => "ʌ"
  158. "text horizontal" => "STH\nʌ"
  159. "text vertical" => "S\nT\nH\n."
  160. string textStyleMTH = switch inputTextStyleMTH
  161. "Ʌ (double)" => "ʌ\nʌ"
  162. "text horizontal" => "MTH\nʌ"
  163. "text vertical" => "M\nT\nH\n."
  164. string textStyleLTH = switch inputTextStyleLTH
  165. "Ʌ (triple)" => "ʌ\nʌ\nʌ"
  166. "text horizontal" => "LTH\nʌ"
  167. "text vertical" => "L\nT\nH\n."
  168. string textStyleSTL = switch inputTextStyleSTL
  169. "V (single)" => "v"
  170. "text horizontal" => "v\nSTL"
  171. "text vertical" => ".\nS\nT\nL"
  172. string textStyleMTL = switch inputTextStyleMTL
  173. "V (double)" => "v\nv"
  174. "text horizontal" => "v\nMTL"
  175. "text vertical" => ".\nM\nT\nL"
  176. string textStyleLTL = switch inputTextStyleLTL
  177. "V (triple)" => "v\nv\nv"
  178. "text horizontal" => "v\nLTL"
  179. "text vertical" => ".\nL\nT\nL"
  180.  
  181. pivHigh = ta.pivothigh(high, lb1, lb1)
  182. pivLow = ta.pivotlow(low, lb1, lb1)
  183. isPivHigh = na(pivHigh)? false:true
  184. isPivLow = na(pivLow)? false:true
  185.  
  186. var float PH = na
  187. var float PL = na
  188. var array<float> PHarr = array.new<float>(0)
  189. var array<float> PLarr = array.new<float>(0)
  190.  
  191. var label countLabH = na
  192. var label countLabL = na
  193. var array<label> countLabHArr = array.new<label>(0)
  194. var array<label> countLabLArr = array.new<label>(0)
  195. var int PHbarInd =0
  196. var int PLbarInd =0
  197. var array<int>PHbarIndArr=array.new<int>(0)
  198. var array<int>PLbarIndArr=array.new<int>(0)
  199. var int MTHbarInd =0
  200. var int MTLbarInd =0
  201. var array<int>MTHbarIndArr=array.new<int>(0)
  202. var array<int>MTLbarIndArr=array.new<int>(0)
  203. var float MTH = na
  204. var float MTL = na
  205. var array<float> MTHarr = array.new<float>(0)
  206. var array<float> MTLarr = array.new<float>(0)
  207. var label MTHlab = na
  208. var label MTLlab = na
  209. var array<label> MTHlabArr = array.new<label>(0)
  210. var array<label> MTLlabArr = array.new<label>(0)
  211. var array<float> LTHarr = array.new<float>(0)
  212. var array<float> LTLarr = array.new<float>(0)
  213.  
  214. ///~~~~~~ line arrays declared
  215. var line STHline = na, var array<line> STHlineArr = array.new<line>(0)
  216. var line STLline = na, var array<line> STLlineArr = array.new<line>(0)
  217. var line MTHline = na, var array<line> MTHlineArr = array.new<line>(0)
  218. var line MTLline = na, var array<line> MTLlineArr = array.new<line>(0)
  219. var line LTHline = na, var array<line> LTHlineArr = array.new<line>(0)
  220. var line LTLline = na, var array<line> LTLlineArr = array.new<line>(0)
  221.  
  222. ///~~~~~~ Box arrays declared
  223. var box STHbox = na, var array<box> STHboxArr = array.new<box>(0)
  224. var box STLbox = na, var array<box> STLboxArr = array.new<box>(0)
  225. var box MTHbox = na, var array<box> MTHboxArr = array.new<box>(0)
  226. var box MTLbox = na, var array<box> MTLboxArr = array.new<box>(0)
  227. var box LTHbox = na, var array<box> LTHboxArr = array.new<box>(0)
  228. var box LTLbox = na, var array<box> LTLboxArr = array.new<box>(0)
  229.  
  230. //////////////////////////////////////////////
  231. //// ##### PIVOT HIGHS & SWEEP BOXES #####
  232.  
  233.  
  234. //spikey condition
  235. atr = ta.atr(2*lb1)
  236. maH = ta.sma(high, 2*lb1)
  237. bool spikeyH = useSpikeyCond? pivHigh > maH+atrMult*atr:true
  238. //
  239. if isPivHigh and lookbackCond
  240. if spikeyH
  241. PH:= pivHigh
  242. array.push(PHarr,PH)
  243. array.push(PHbarIndArr,bar_index-lb1)
  244. countLabH:=label.new(bar_index-lb1, high[lb1]+unit_1*atrSpacer, textStyleSTH, style=label.style_label_down, textcolor =showSTHs and showPivHighsLows?txtColSTH:colorNone, size = sizeSTH, color = colorNone)
  245. array.push(countLabHArr,countLabH)
  246. if showSTHlines and showPivHighsLows
  247. STHline:= line.new(bar_index-lb1,high[lb1], bar_index, high[lb1], color =txtColSTH, style = lineStyle, width =lineWidth, extend = extendChoice?extend.right:extend.none)
  248. array.push(STHlineArr, STHline)
  249. if showSTHboxes and showSweepBoxes
  250. STHbox:= box.new(bar_index-lb1, high[lb1] + gradeSweepST, bar_index-lb1+boxWidth, high[lb1],text = showTxt?(gradeSweepLabST +pUnits+" "):"" , text_valign=valignChoice,text_halign=halignChoice, text_size = txtSize, xloc = xloc.bar_index,
  251. text_color = txtCol, border_color = colorNone, bgcolor = STHbxCol, extend = extendChoice?extend.right:extend.none)
  252. array.push(STHboxArr, STHbox)
  253. if array.size(STHboxArr)>numBoxesLines
  254. box.delete(array.shift(STHboxArr))
  255. if array.size(STHlineArr)>numBoxesLines
  256. line.delete(array.shift(STHlineArr))
  257.  
  258. PHbarIndArrSize = array.size(PHbarIndArr)
  259. PHarrSize = array.size(PHarr)
  260.  
  261. _lastSTH = array.size(PHarr)>1?array.get(PHarr, PHarrSize-1):na
  262. _lastBarIndSTH = array.size(PHbarIndArr)>1?array.get(PHbarIndArr, PHbarIndArrSize-1):na
  263. _2ndLastSTH = array.size(PHarr)>2?array.get(PHarr, PHarrSize-2):na
  264. _2ndLastBarIndSTH = array.size(PHbarIndArr)>2?array.get(PHbarIndArr, PHbarIndArrSize-2):na
  265. _3rdLastSTH= array.size(PHarr)>3?array.get(PHarr, PHarrSize-3):na
  266. _3rdLastBarIndSTH= array.size(PHbarIndArr)>3?array.get(PHbarIndArr, PHbarIndArrSize-3):na
  267.  
  268. MTH_index = array.indexof(PHbarIndArr, _2ndLastBarIndSTH)
  269. if (_lastSTH<_2ndLastSTH and _2ndLastSTH>_3rdLastSTH) and not (_lastSTH<_2ndLastSTH and _2ndLastSTH>_3rdLastSTH)[1]
  270. MTHlab:=label.new(_2ndLastBarIndSTH, _2ndLastSTH+unit_1*atrSpacer, textStyleMTH, style=label.style_label_down, textcolor =showMTHs and showPivHighsLows?txtColMTH:colorNone, size = sizeMTH, color = colorNone)
  271. array.push(MTHarr,_2ndLastSTH)
  272. array.push(MTHbarIndArr,_2ndLastBarIndSTH)
  273. array.push(MTHlabArr, MTHlab)
  274. label.set_text(array.get(countLabHArr, MTH_index),"")
  275. if showMTHlines and showPivHighsLows
  276. MTHline:= line.new(_2ndLastBarIndSTH,_2ndLastSTH, bar_index, _2ndLastSTH, color =txtColMTH, style = lineStyle, width =lineWidth, extend = extendChoice?extend.right:extend.none)
  277. array.push(MTHlineArr, MTHline)
  278. if showMTHboxes and showSweepBoxes
  279. MTHbox:= box.new(_2ndLastBarIndSTH,_2ndLastSTH + gradeSweepMT, _2ndLastBarIndSTH+boxWidth, _2ndLastSTH ,text = showTxt?(gradeSweepLabMT +pUnits+" "):"" , text_valign=valignChoice,text_halign=halignChoice, text_size = txtSize, xloc = xloc.bar_index,
  280. text_color = txtCol, border_color = colorNone, bgcolor = MTHbxCol, extend = extendChoice?extend.right:extend.none)
  281. array.push(MTHboxArr, MTHbox)
  282. if array.size(MTHboxArr)>numBoxesLines
  283. box.delete(array.shift(MTHboxArr))
  284. if array.size(MTHlineArr)>numBoxesLines
  285. line.delete(array.shift(MTHlineArr))
  286.  
  287. MTHbarIndArrSize = array.size(MTHbarIndArr)
  288. MTHsizeOfArr = array.size(MTHarr)
  289. MTHlabArrSize = array.size(MTHlabArr)
  290.  
  291. _lastMTH = array.size(MTHarr)>1?array.get(MTHarr, MTHsizeOfArr-1):na
  292. _lastBarIndMTH = array.size(MTHbarIndArr)>1?array.get(MTHbarIndArr, MTHbarIndArrSize-1):na
  293. _2ndLastMTH = array.size(MTHarr)>2?array.get(MTHarr, MTHsizeOfArr-2):na
  294. _2ndLastBarIndMTH = array.size(MTHbarIndArr)>2?array.get(MTHbarIndArr, MTHbarIndArrSize-2):na
  295. _3rdLastMTH= array.size(MTHarr)>3?array.get(MTHarr, MTHsizeOfArr-3):na
  296. _3rdLastBarIndMTH= array.size(MTHbarIndArr)>3?array.get(MTHbarIndArr, MTHbarIndArrSize-3):na
  297.  
  298. LTH_index1 = array.indexof(PHbarIndArr, _2ndLastBarIndMTH)
  299. LTH_index2 = array.indexof(MTHbarIndArr, _2ndLastBarIndMTH)
  300.  
  301. if (_lastMTH<_2ndLastMTH and _2ndLastMTH>_3rdLastMTH) and not (_lastMTH<_2ndLastMTH and _2ndLastMTH>_3rdLastMTH)[1]
  302. label.new(_2ndLastBarIndMTH, _2ndLastMTH+unit_1*atrSpacer, textStyleLTH, style=label.style_label_down, textcolor =showLTHs and showPivHighsLows?txtColLTH:colorNone, size = sizeLTH, color = colorNone)
  303. label.set_text(array.get(MTHlabArr, LTH_index2),"")
  304. label.set_text(array.get(countLabHArr, LTH_index1),"")
  305. array.push(LTHarr,_2ndLastMTH)
  306. if showLTHlines and showPivHighsLows
  307. LTHline:= line.new(_2ndLastBarIndMTH,_2ndLastMTH, bar_index, _2ndLastMTH, color = txtColLTH, style = lineStyle, width =lineWidth, extend = extendChoice?extend.right:extend.none)
  308. array.push(LTHlineArr, LTHline)
  309. if showLTHboxes and showSweepBoxes
  310. LTHbox:= box.new(_2ndLastBarIndMTH,_2ndLastMTH + gradeSweepLT, _2ndLastBarIndMTH+boxWidth, _2ndLastMTH ,text = showTxt?(gradeSweepLabLT +pUnits):"" , text_valign=valignChoice,text_halign=halignChoice, text_size = txtSize, xloc = xloc.bar_index,
  311. text_color = txtCol, border_color = colorNone, bgcolor = LTHbxCol, extend = extendChoice?extend.right:extend.none)
  312. array.push(LTHboxArr, LTHbox)
  313. if array.size(LTHboxArr)>numBoxesLines
  314. box.delete(array.shift(LTHboxArr))
  315. if array.size(LTHlineArr)>numBoxesLines
  316. line.delete(array.shift(LTHlineArr))
  317.  
  318. /////////////////////////////////////////////
  319. //// ##### PIVOT LOWS & SWEEP BOXES #####
  320.  
  321. //spikey condition
  322. maL = ta.sma(low, 2*lb1)
  323. bool spikeyL = useSpikeyCond? pivLow < maL-atrMult*atr:true
  324. //
  325. if isPivLow and lookbackCond
  326. if spikeyL
  327. PL:= pivLow
  328. array.push(PLarr,PL)
  329. array.push(PLbarIndArr,bar_index-lb1)
  330. countLabL:=label.new(bar_index-lb1, low[lb1]-unit_1*atrSpacer, textStyleSTL, style=label.style_label_up, textcolor =showSTLs and showPivHighsLows?txtColSTL:colorNone, size = sizeSTL, color = colorNone)
  331. array.push(countLabLArr,countLabL)
  332. if showSTLlines and showPivHighsLows
  333. STLline:= line.new(bar_index-lb1,low[lb1], bar_index, low[lb1], color =txtColSTL, style = lineStyle, width =lineWidth, extend = extendChoice?extend.right:extend.none)
  334. array.push(STLlineArr, STLline)
  335. if showSTLboxes and showSweepBoxes
  336. STLbox:= box.new(bar_index-lb1,low[lb1], bar_index-lb1+boxWidth, low[lb1]- gradeSweepST,text = showTxt?(gradeSweepLabST +pUnits)+" ":"" , text_valign=valignChoice,text_halign=halignChoice, text_size = txtSize, xloc = xloc.bar_index,
  337. text_color = txtCol, border_color = colorNone, bgcolor = STLbxCol, extend = extendChoice?extend.right:extend.none)
  338. array.push(STLboxArr, STLbox)
  339. if array.size(STLboxArr)>numBoxesLines
  340. box.delete(array.shift(STLboxArr))
  341. if array.size(STLlineArr)>numBoxesLines
  342. line.delete(array.shift(STLlineArr))
  343.  
  344. PLbarIndArrSize = array.size(PLbarIndArr)
  345. PLarrSize = array.size(PLarr)
  346.  
  347. _lastSTL = array.size(PLarr)>1?array.get(PLarr, PLarrSize-1):na
  348. _lastBarIndSTL = array.size(PLbarIndArr)>1?array.get(PLbarIndArr, PLbarIndArrSize-1):na
  349. _2ndLastSTL = array.size(PLarr)>2?array.get(PLarr, PLarrSize-2):na
  350. _2ndLastBarIndSTL = array.size(PLbarIndArr)>2?array.get(PLbarIndArr, PLbarIndArrSize-2):na
  351. _3rdLastSTL= array.size(PLarr)>3?array.get(PLarr, PLarrSize-3):na
  352. _3rdLastBarIndSTL= array.size(PLbarIndArr)>3?array.get(PLbarIndArr, PLbarIndArrSize-3):na
  353.  
  354. MTL_index = array.indexof(PLbarIndArr, _2ndLastBarIndSTL)
  355.  
  356. if (_lastSTL>_2ndLastSTL and _2ndLastSTL<_3rdLastSTL) and not (_lastSTL>_2ndLastSTL and _2ndLastSTL<_3rdLastSTL)[1]
  357. MTLlab:=label.new(_2ndLastBarIndSTL, _2ndLastSTL-unit_1*atrSpacer, textStyleMTL, style=label.style_label_up, textcolor =showMTLs and showPivHighsLows?txtColMTL:colorNone, size = sizeMTL, color = colorNone)
  358. array.push(MTLarr,_2ndLastSTL)
  359. array.push(MTLbarIndArr,_2ndLastBarIndSTL)
  360. array.push(MTLlabArr, MTLlab)
  361. label.set_text(array.get(countLabLArr, MTL_index),"")
  362. if showMTLlines and showPivHighsLows
  363. MTLline:= line.new(_2ndLastBarIndSTL,_2ndLastSTL, bar_index, _2ndLastSTL, color =txtColMTL, style = lineStyle, width =lineWidth, extend = extendChoice?extend.right:extend.none)
  364. array.push(MTLlineArr, MTLline)
  365. if showMTLboxes and showSweepBoxes
  366. MTLbox:= box.new(_2ndLastBarIndSTL, _2ndLastSTL, _2ndLastBarIndSTL+boxWidth, _2ndLastSTL- gradeSweepMT,text = showTxt?(gradeSweepLabMT +pUnits+" "):"" , text_valign=valignChoice,text_halign=halignChoice, text_size = txtSize, xloc = xloc.bar_index,
  367. text_color = txtCol, border_color = colorNone, bgcolor = MTLbxCol, extend = extendChoice?extend.right:extend.none)
  368. array.push(MTLboxArr, MTLbox)
  369. if array.size(MTLboxArr)>numBoxesLines
  370. box.delete(array.shift(MTLboxArr))
  371. if array.size(MTLlineArr)>numBoxesLines
  372. line.delete(array.shift(MTLlineArr))
  373.  
  374. MTLbarIndArrSize = array.size(MTLbarIndArr)
  375. MTLsizeOfArr = array.size(MTLarr)
  376. MTLlabArrSize = array.size(MTLlabArr)
  377.  
  378. _lastMTL = array.size(MTLarr)>1?array.get(MTLarr, MTLsizeOfArr-1):na
  379. _lastBarIndMTL = array.size(MTLbarIndArr)>1?array.get(MTLbarIndArr, MTLbarIndArrSize-1):na
  380. _2ndLastMTL = array.size(MTLarr)>2?array.get(MTLarr, MTLsizeOfArr-2):na
  381. _2ndLastBarIndMTL = array.size(MTLbarIndArr)>2?array.get(MTLbarIndArr, MTLbarIndArrSize-2):na
  382. _3rdLastMTL= array.size(MTLarr)>3?array.get(MTLarr, MTLsizeOfArr-3):na
  383. _3rdLastBarIndMTL= array.size(MTLbarIndArr)>3?array.get(MTLbarIndArr, MTLbarIndArrSize-3):na
  384.  
  385. LTL_index1 = array.indexof(PLbarIndArr, _2ndLastBarIndMTL)
  386. LTL_index2 = array.indexof(MTLbarIndArr, _2ndLastBarIndMTL)
  387.  
  388. if (_lastMTL>_2ndLastMTL and _2ndLastMTL<_3rdLastMTL) and not (_lastMTL>_2ndLastMTL and _2ndLastMTL<_3rdLastMTL)[1]
  389. label.new(_2ndLastBarIndMTL, _2ndLastMTL-unit_1*atrSpacer, textStyleLTL, style=label.style_label_up, textcolor =showLTLs and showPivHighsLows?txtColLTL:colorNone, size = sizeLTL, color = colorNone)
  390. label.set_text(array.get(MTLlabArr, LTL_index2),"")
  391. label.set_text(array.get(countLabLArr, LTL_index1),"")
  392. array.push(LTLarr,_2ndLastMTL)
  393. if showLTLlines and showPivHighsLows
  394. LTLline:= line.new(_2ndLastBarIndMTL,_2ndLastMTL, bar_index, _2ndLastMTL, color =txtColLTL, style = lineStyle, width =lineWidth, extend = extendChoice?extend.right:extend.none)
  395. array.push(LTLlineArr, LTLline)
  396. if showLTLboxes and showSweepBoxes
  397. LTLbox:= box.new(_2ndLastBarIndMTL, _2ndLastMTL, _2ndLastBarIndMTL+boxWidth, _2ndLastMTL- gradeSweepLT,text = showTxt?(gradeSweepLabLT +pUnits):"" , text_valign=valignChoice,text_halign=halignChoice, text_size = txtSize, xloc = xloc.bar_index,
  398. text_color = txtCol, border_color = colorNone, bgcolor = LTLbxCol, extend = extendChoice?extend.right:extend.none)
  399. array.push(LTLboxArr, LTLbox)
  400. if array.size(LTLboxArr)>numBoxesLines
  401. box.delete(array.shift(LTLboxArr))
  402. if array.size(LTLlineArr)>numBoxesLines
  403. line.delete(array.shift(LTLlineArr))
  404.  
  405. // ~~ Alerts ~~
  406. lastLTH = array.size(LTHarr)>0?array.last(LTHarr):na
  407. lastLTL = array.size(LTLarr)>0?array.last(LTLarr):na
  408. lastMTH = array.size(MTHarr)>0?array.last(MTHarr):na
  409. lastMTL = array.size(MTLarr)>0?array.last(MTLarr):na
  410. lastSTH = array.size(PHarr)>0? array.last(PHarr):na
  411. lastSTL = array.size(PLarr)>0? array.last(PLarr):na
  412. alertcondition(ta.crossover(close, lastLTH), "LTH, cross above", "price has crossed above last LTH")
  413. alertcondition(ta.crossunder(close, lastLTL), "LTL, cross below", "price has crossed below last LTL")
  414. alertcondition(ta.crossover(close, lastMTH), "MTH, cross above", "price has crossed above last MTH")
  415. alertcondition(ta.crossunder(close, lastMTL), "MTL, cross below", "price has crossed below last MTL")
  416. alertcondition(ta.crossover(close, lastSTH), "STH, cross above", "price has crossed above last STH")
  417. alertcondition(ta.crossunder(close, lastSTL), "STL, cross below", "price has crossed below last STL")
  418.  
  419.  
  420. ////////////////////////////////////////////////////////////
  421. //// ##### Extend Sweep boxes / Shrink Sweep Boxes #####
  422.  
  423. pivBxExtToPrice(array<box>boxArray, simple bool isBull, int maxSize) =>
  424. if boxArray.size() > 0
  425. for i = boxArray.size() -1 to 0
  426. box bx = boxArray.get(i)
  427. bx.set_right(bar_index)
  428. int bxStart = bx.get_left()
  429. float bxEdge = isBull? bx.get_top() : -bx.get_bottom()
  430. float price = isBull ? high : -low
  431. if price > bxEdge
  432. if shrinkGradeSweepsOnFill
  433. bx.set_left(bxStart)
  434. bx.set_right(bxStart+1)
  435. boxArray.remove(i)
  436. if boxArray.size() > maxSize
  437. box.delete(boxArray.shift())
  438.  
  439. pivLnExtToPrice(array<line>lineArray, simple bool isBull,int maxSize) =>
  440. if lineArray.size() > 0
  441. for i = lineArray.size() -1 to 0
  442. line ln = lineArray.get(i)
  443. int x1 = line.get_x1(ln)
  444. ln.set_x2(bar_index)
  445. float lnHeight = isBull? ln.get_price(bar_index):-ln.get_price(bar_index)
  446. float price = isBull ? high : -low
  447. if price > lnHeight
  448. if shrinkGradeSweepsOnFill
  449. ln.set_x1(x1)
  450. ln.set_x2(x1+1)
  451. ln.delete()
  452. lineArray.shift()
  453. if lineArray.size() > maxSize
  454. line.delete(lineArray.shift())
  455.  
  456. if endAtPrice
  457. pivBxExtToPrice(STHboxArr,true,2)
  458. pivBxExtToPrice(STLboxArr,false,2)
  459. pivBxExtToPrice(MTHboxArr,true,2)
  460. pivBxExtToPrice(MTLboxArr,false,2)
  461. pivBxExtToPrice(LTHboxArr,true,2)
  462. pivBxExtToPrice(LTLboxArr,false,2)
  463.  
  464. pivLnExtToPrice(STHlineArr,true,2)
  465. pivLnExtToPrice(STLlineArr,false,2)
  466. pivLnExtToPrice(MTHlineArr,true,2)
  467. pivLnExtToPrice(MTLlineArr,false,2)
  468. pivLnExtToPrice(LTHlineArr,true,2)
  469. pivLnExtToPrice(LTLlineArr,false,2)
  470.  
  471.  
  472. /////////////////////////////////////////////////////////
  473. ///////// ##### CHoCHs ##### ////////////////
  474. /////////////////////////////////////////////////////////
  475.  
  476. string lineStyleCh = switch _lineStyleCh
  477. "Dotted" => line.style_dotted
  478. "Dashed" => line.style_dashed
  479. "Solid" => line.style_solid
  480.  
  481.  
  482. color ColChoice = switch
  483. timeframe.period == "1" => _1minCol
  484. timeframe.period == "5" => _5minCol
  485. timeframe.period == "15" => _15minCol
  486. timeframe.period == "60" => _HCol
  487. timeframe.period == "240" => _4hrCol
  488. timeframe.period == "D" => _DCol
  489. timeframe.period == "W" => _WCol
  490. timeframe.period == "M" => _MCol
  491.  
  492. pivHighCh = ta.pivothigh(high, lb_ch, lf_ch)
  493. pivLowCh = ta.pivotlow(low, lb_ch, lf_ch)
  494. ispivHighCh = na(pivHighCh)? false:true
  495. ispivLowCh = na(pivLowCh)? false:true
  496.  
  497. lookbackCondCh = bar_index > last_bar_index - barsBackCh
  498.  
  499. var float PhCh = na
  500. var float PlCh = na
  501. var array<float> PhCharr = array.new<float>(0)
  502. var array<float> PlCharr = array.new<float>(0)
  503.  
  504. var label pivHighChLab = na
  505. var label pivLowChLab = na
  506. var array<label> pivHighChLabArr = array.new<label>(0)
  507. var array<label> pivLowChLabArr = array.new<label>(0)
  508.  
  509. //
  510. if ispivHighCh and lookbackCondCh
  511. PhCh:= pivHighCh
  512. array.push(PhCharr,PhCh)
  513.  
  514. PhCharrSize = array.size(PhCharr)
  515.  
  516.  
  517. if ispivLowCh and lookbackCondCh
  518. PlCh:= pivLowCh
  519. array.push(PlCharr,PlCh)
  520.  
  521. PlCharrSize = array.size(PlCharr)
  522.  
  523. lastPhChigh = PhCharrSize>0? array.last(PhCharr):na
  524. lastPlChow = PlCharrSize>0? array.last(PlCharr):na
  525.  
  526. getChochD()=>
  527. int num = 0
  528. for i = 0 to 20
  529. if high[i]>=high[i+1]
  530. num+=1
  531. if high[i]<high[i+1]
  532. break
  533. num
  534.  
  535. getChochU()=>
  536. int num = 0
  537. for i = 0 to 20
  538. if low[i]<=low[i+1]
  539. num+=1
  540. if low[i]>low[i+1]
  541. break
  542. num
  543.  
  544. var array<line> chochDArr = array.new<line>(0)
  545. label labBrUp = na
  546. line chochD = na
  547. var array<line> chochUArr = array.new<line>(0)
  548. label labBrDn = na
  549. line chochU = na
  550.  
  551. label chochDlab =na
  552. var array<label> chochDlabArr = array.new<label>(0)
  553. label chochUlab =na
  554. var array<label> chochUlabArr = array.new<label>(0)
  555.  
  556. //CHoCH DOWN
  557. float CHochDNprice =na
  558. var array<float> CHochDNpriceArr = array.new<float>(0)
  559.  
  560. if high>lastPhChigh and lookbackCondCh and showDNchoch and showChochs
  561. CHochDNprice:=low[getChochD()]
  562. array.push(CHochDNpriceArr,CHochDNprice)
  563. chochD:= line.new(bar_index-getChochD(), low[getChochD()], bar_index+getChochD(), low[getChochD()], style = lineStyleCh, width = lineWidthCh, color = MultiTFcolorOveride?ColChoice:dnChochCol)
  564. chochDlab:= label.new(bar_index+5,low[getChochD()], dnIcon, style = label.style_label_center, color = colorNone, textcolor = MultiTFcolorOveride?ColChoice:dnChochCol, size = dnIconSize) //bar_index+5 ??
  565. array.push(chochDArr, chochD)
  566. array.push(chochDlabArr, chochDlab)
  567. //condition to shift +1 bar for fakeout chochs
  568. if low[getChochD()] > low[getChochD()-1]
  569. line.set_xy1(array.last(chochDArr),bar_index-getChochD()+1, low[getChochD()-1])
  570. line.set_xy2(array.last(chochDArr),bar_index+6, low[getChochD()-1]) // bar_index+5 ??
  571. label.set_xy(array.last(chochDlabArr),bar_index+6,low[getChochD()-1]) // bar_index+6 ??
  572. label.delete(chochDlab[1])
  573. line.delete(chochD[1])
  574.  
  575. if array.size(chochDArr)>numActiveChoch
  576. line.delete(array.shift(chochDArr))
  577. if array.size(chochDlabArr)>numActiveChoch
  578. label.delete(array.shift(chochDlabArr))
  579. if array.size(CHochDNpriceArr)>numActiveChoch
  580. array.shift(CHochDNpriceArr)
  581.  
  582. //CHoCH UP
  583. float CHochUPprice =na
  584. var array<float> CHochUPpriceArr = array.new<float>(0)
  585.  
  586. if low<lastPlChow and lookbackCondCh and showUPchoch and showChochs
  587. CHochUPprice:=high[getChochU()]
  588. array.push(CHochUPpriceArr,CHochUPprice)
  589. chochU:= line.new(bar_index-getChochU(), high[getChochU()], last_bar_index, high[getChochU()], style = lineStyleCh, width = lineWidthCh, color = MultiTFcolorOveride?ColChoice:upChochCol)
  590. chochUlab:= label.new(bar_index-getChochU()+5,high[getChochU()], upIcon, style = label.style_label_center, color = colorNone, textcolor = MultiTFcolorOveride?ColChoice:upChochCol, size = upIconSize) //label.new(bar_index-getChochU()+5 ??
  591. array.push(chochUArr, chochU)
  592. array.push(chochUlabArr, chochUlab)
  593. //condition to shift +1 bar for fakeout chochs
  594. if high[getChochU()] < high[getChochU()-1]
  595. line.set_xy1(array.last(chochUArr),bar_index-getChochU()+1, high[getChochU()-1])
  596. line.set_xy2(array.last(chochUArr),bar_index+5, high[getChochU()-1]) // bar_index+5 ??
  597. label.set_xy(array.last(chochUlabArr),bar_index-getChochU()+6,high[getChochU()-1])
  598.  
  599. label.delete(chochUlab[1])
  600. line.delete(chochU[1])
  601. //following 4 lines are used with 'number of 'active' chochs to show'.. but perhaps best to keep it simple and just control via bars lookback condition
  602. if array.size(chochUArr)>numActiveChoch
  603. line.delete(array.shift(chochUArr))
  604. if array.size(chochUlabArr)>numActiveChoch
  605. label.delete(array.shift(chochUlabArr))
  606. if array.size(CHochUPpriceArr)>numActiveChoch
  607. array.shift(CHochUPpriceArr)
  608.  
  609. lastChochUP = array.size(CHochUPpriceArr)>0?array.last(CHochUPpriceArr):na
  610. lastChochDN = array.size(CHochDNpriceArr)>0?array.last(CHochDNpriceArr):na
  611.  
  612. alertcondition(ta.crossover(close, lastChochUP ), "last CHoCH UP, cross above", "price has crossed above last CHoCH up")
  613. alertcondition(ta.crossunder(close, lastChochDN), "last CHoCH DOWN, cross below", "price has crossed below last CHoCH down")
  614.  
  615.  
  616.  
  617. ///### Adding self-terminating lines
  618.  
  619. chochLnLabExtToPrice( array<line> lineArray, array<label>labArray, simple bool isBull, int maxSize) => ///testing reclocation of "▲" label ( array<label>labArray,)
  620. if lineArray.size() > 0 and labArray.size()>0
  621. for i = lineArray.size() -1 to 0
  622. line ln = lineArray.get(i)
  623. label lb = labArray.get(i)
  624. int x1 = line.get_x1(ln)
  625. ln.set_x2(bar_index)
  626. lb.set_x(bar_index -( math.round(bar_index-x1)/2) )
  627. float lnHeight = isBull? ln.get_price(bar_index): -ln.get_price(bar_index)
  628. float price = isBull ? high : -low
  629. if price > lnHeight
  630. if shrinkChochOnfill
  631. lb.set_x(x1+1)
  632. ln.set_x1(x1)
  633. ln.set_x2(x1+1)
  634. lineArray.remove(i)
  635. labArray.remove(i)
  636.  
  637. if lineArray.size() > maxSize
  638. line.delete(lineArray.shift())
  639. if labArray.size() > maxSize
  640. label.delete(labArray.shift())
  641.  
  642. chochLnLabExtToPrice(chochUArr,chochUlabArr,true,numActiveChoch)
  643. chochLnLabExtToPrice(chochDArr,chochDlabArr,false, numActiveChoch)
  644.  
  645. chochUArrSize = array.size(chochUArr)
  646. chochUlabArrSize = array.size(chochUlabArr)
  647. chochDArrSize = array.size(chochDArr)
  648. chochDlabArrSize = array.size(chochDlabArr)
  649.  
  650. lastChUpPrice = chochUArrSize>0?line.get_price(array.last(chochUArr), bar_index):na
  651. lastChUpX1 = chochUArrSize>0?line.get_x1(array.last(chochUArr)):na
  652.  
  653.  
  654. lastChDnPrice = chochDArrSize>0?line.get_price(array.last(chochDArr), bar_index):na
  655. lastChDnX1 = chochDArrSize>0?line.get_x1(array.last(chochDArr)):na
  656.  
  657. // Conditions to extend latest CHoCH line only by 10 bars
  658. if not ta.crossunder(low, lastChDnPrice) and chochDArrSize >0 and chochDlabArrSize>0
  659. line.set_x2(array.last(chochDArr), bar_index+10)
  660. label.set_x(array.last(chochDlabArr),lastChDnX1 + ((bar_index-lastChDnX1)/2) +5)
  661. if not ta.crossover(high, lastChUpPrice) and chochUArrSize >0 and chochUlabArrSize>0
  662. line.set_x2(array.last(chochUArr), bar_index+10)
  663. label.set_x(array.last(chochUlabArr),lastChUpX1 +((bar_index-lastChUpX1)/2)+5)
  664.  
  665. ///////////////////////////////
  666. //// ##### HTF CHoCHs #####
  667. ///////////////////////////////
  668.  
  669. string lineStyleChHTF = switch _lineStyleChHTF
  670. "Dotted" => line.style_dotted
  671. "Dashed" => line.style_dashed
  672. "Solid" => line.style_solid
  673.  
  674. getHtfPhPl()=>
  675. float ph = ta.pivothigh(1, 1)
  676. float pl = ta.pivotlow(1, 1)
  677. [ph, pl]
  678.  
  679. [ph, pl] = request.security(syminfo.tickerid, HTF, getHtfPhPl(), lookahead = barmerge.lookahead_on)
  680. var array<float> htfPHarr = array.new<float>(0)
  681. var array<float> htfPLarr = array.new<float>(0)
  682. if na(ph[1]) and ph
  683. array.push(htfPHarr, ph)
  684. if na(pl[1]) and pl
  685. array.push(htfPLarr, pl)
  686.  
  687. float lastPHhtf = array.size(htfPHarr)>0? array.last(htfPHarr):na
  688. float lastPLhtf = array.size(htfPLarr)>0? array.last(htfPLarr):na
  689.  
  690. backCountLHs()=>
  691. int num = 0
  692. for i = 0 to 20
  693. while i==num
  694. if high[i]>=high[i+1]
  695. num+=1
  696. break
  697. num
  698. backCountHLs()=>
  699. int num = 0
  700. for i = 0 to 20
  701. while i==num
  702. if low[i]<=low[i+1]
  703. num+=1
  704. break
  705. num
  706.  
  707. backCountLHs = request.security(syminfo.tickerid, HTF, backCountLHs())
  708. backCountHLs = request.security(syminfo.tickerid, HTF, backCountHLs())
  709. backCountLHsPrice = request.security(syminfo.tickerid, HTF, low[backCountLHs])
  710. backCountHLsPrice = request.security(syminfo.tickerid, HTF, high[backCountHLs])
  711. backCountLHsPricePlus1 = request.security(syminfo.tickerid, HTF, low[backCountLHs-1==-1?0:backCountLHs-1])
  712. backCountHLsPricePlus1 = request.security(syminfo.tickerid, HTF, high[backCountHLs-1==-1?0:backCountHLs-1])
  713.  
  714. whenLastTFchg = ta.valuewhen(timeframe.change(HTF),bar_index, 0)
  715. when2ndLastTFchg = ta.valuewhen(timeframe.change(HTF),bar_index, 1)
  716. barDiff = whenLastTFchg - when2ndLastTFchg
  717. //ideally returns barDiff; but if ltf is very small and htf is very large, 20k bar lookback doesn't cover the calculation =>> revert to less accurate method using pure time (just cosmetic anyway; the price level is uneffected)
  718. ltfBarsInHTFbar = not na(barDiff)?(barDiff): math.round(timeframe.in_seconds(HTF) / timeframe.in_seconds(timeframe.period))
  719.  
  720. line lineDownHtf =na
  721. var array<line> lineDownHtfarr = array.new<line>(0)
  722. label labDownHtf =na
  723. var array<label> labelDownHtfarr = array.new<label>(0)
  724. float CHochDNpriceHTF =na
  725. var array<float> CHochDNpriceHTFArr = array.new<float>(0)
  726.  
  727. //Choch Down HTF
  728. if ta.crossover(high, lastPHhtf) and showChochs//and Cond1
  729. CHochDNpriceHTF:=backCountLHsPrice
  730. array.push(CHochDNpriceHTFArr, CHochDNpriceHTF)
  731. lineDownHtf:= line.new(bar_index-ltfBarsInHTFbar-1, backCountLHsPrice, last_bar_index+10, backCountLHsPrice, color= useHTFchochs?htfDNcol:colorNone, style = lineStyleChHTF)
  732. array.push(lineDownHtfarr, lineDownHtf)
  733. labDownHtf:= label.new(last_bar_index+13,backCountLHsPrice, "🢃", style=label.style_label_center, color=colorNone, textcolor= useHTFchochs?htfDNcol:colorNone)
  734. array.push(labelDownHtfarr, labDownHtf)
  735. if backCountLHsPrice > backCountLHsPricePlus1
  736. line.set_xy1(array.last(lineDownHtfarr),bar_index-ltfBarsInHTFbar-1, backCountLHsPricePlus1)
  737. line.set_xy2(array.last(lineDownHtfarr),last_bar_index+10, backCountLHsPricePlus1)
  738. label.set_xy(array.last(labelDownHtfarr),last_bar_index+13,backCountLHsPricePlus1)
  739. if array.size(lineDownHtfarr)>1
  740. line.delete(array.shift(lineDownHtfarr))
  741. if array.size(labelDownHtfarr)>1
  742. label.delete(array.shift(labelDownHtfarr))
  743. if array.size(CHochDNpriceHTFArr)>1
  744. array.shift(CHochDNpriceHTFArr)
  745.  
  746. line lineUpHtf =na
  747. var array<line> lineUpHtfarr = array.new<line>(0)
  748. label labUpHtf =na
  749. var array<label> labelUpHtfarr = array.new<label>(0)
  750. float CHochUPpriceHTF =na
  751. var array<float> CHochUPpriceHTFArr = array.new<float>(0)
  752.  
  753. //Choch UP HTF
  754. if ta.crossunder(low, lastPLhtf) and showChochs//and Cond2
  755. CHochUPpriceHTF:=backCountHLsPrice
  756. array.push(CHochUPpriceHTFArr, CHochUPpriceHTF)
  757. lineUpHtf:= line.new(bar_index-ltfBarsInHTFbar-1, backCountHLsPrice, last_bar_index+10, backCountHLsPrice, color= useHTFchochs?htfUPcol:colorNone, style = lineStyleChHTF)
  758. array.push(lineUpHtfarr, lineUpHtf)
  759. labUpHtf:= label.new(last_bar_index+13,backCountHLsPrice, "🢁", style=label.style_label_center, color=colorNone, textcolor= useHTFchochs?htfUPcol:colorNone)
  760. array.push(labelUpHtfarr, labUpHtf)
  761. //condition to shift +1 for fakeouts
  762. if backCountHLsPrice < backCountHLsPricePlus1
  763. line.set_xy1(array.last(lineUpHtfarr),bar_index-ltfBarsInHTFbar-1, backCountHLsPricePlus1)
  764. line.set_xy2(array.last(lineUpHtfarr),last_bar_index+10, backCountHLsPricePlus1)
  765. label.set_xy(array.last(labelUpHtfarr),last_bar_index+13,backCountHLsPricePlus1)
  766. if array.size(lineUpHtfarr)>1
  767. line.delete(array.shift(lineUpHtfarr))
  768. if array.size(labelUpHtfarr)>1
  769. label.delete(array.shift(labelUpHtfarr))
  770. if array.size(CHochUPpriceHTFArr)>1
  771. array.shift(CHochUPpriceHTFArr)
  772.  
  773. lastChochUP_HTF = array.size(CHochUPpriceHTFArr)>0?array.last(CHochUPpriceHTFArr):na
  774. lastChochDN_HTF = array.size(CHochDNpriceHTFArr)>0?array.last(CHochDNpriceHTFArr):na
  775.  
  776. alertcondition(ta.crossover(close, lastChochUP_HTF ), "HTF last CHoCH UP, cross above", "price has crossed above last HTF CHoCH up")
  777. alertcondition(ta.crossunder(close, lastChochDN_HTF), "HTF last CHoCH DOWN, cross below", "price has crossed below last HTF CHoCH down")
  778.  
  779. aboveLstUPcond = close > lastChochUP_HTF
  780. belowLstDNcond = close < lastChochDN_HTF
  781.  
  782. /////////////////////////////////////////////////////////
  783. ///////// ##### FVGs ##### ////////////////
  784. /////////////////////////////////////////////////////////
  785.  
  786. string ceStyle = switch _ceStyle
  787. "Dotted" => line.style_dotted
  788. "Dashed" => line.style_dashed
  789. "Solid" => line.style_solid
  790.  
  791.  
  792. var box bxUp = na, var box bxDn = na, var line lnUp = na, var line lnDn = na
  793. var array<box> bxUpArr = array.new<box>(0), var array<line> lnUpArr = array.new<line>(0)
  794. var array<box> bxDnArr = array.new<box>(0), var array<line> lnDnArr = array.new<line>(0)
  795. lookbackCondFVG = bar_index > last_bar_index - barsBackFVG
  796. dnCE = high[1] + (low[3]-high[1])/2
  797. upCE = low[1] - (low[1]-high[3])/2
  798. if low[3] > high[1] and lookbackCondFVG and showDN and showFVGs
  799. bxDnArr.push(box.new(bar_index-2, low[3], bar_index, high[1], bgcolor = colDn, border_color = colorNone))
  800. lnDnArr.push(line.new(bar_index-2, dnCE, bar_index, dnCE, color = showCE?ceCol:colorNone, style =ceStyle))
  801. if high[3] < low[1] and lookbackCondFVG and showUP and showFVGs
  802. bxUpArr.push(box.new(bar_index-2, low[1], bar_index, high[3], bgcolor = colUp, border_color = colorNone))
  803. lnUpArr.push(line.new(bar_index-2, upCE, bar_index, upCE, color = showCE?ceCol:colorNone, style =ceStyle))
  804. var array<int> _countArr =array.new<int>(0)
  805.  
  806. fvgBxExtToPrice(array<box> boxArray, array<line> lineArray, array<int> countArr, simple bool isBull, int maxSize) =>
  807. if boxArray.size() > 0
  808. for i = boxArray.size() -1 to 0
  809. line ln = lineArray.get(i)
  810. box bx = boxArray.get(i)
  811. bx.set_right(bar_index)
  812. int bxStart = bx.get_left()
  813. int lnStart = ln.get_x1()
  814. ln.set_x2(bar_index)
  815. float threshold = isBull?(CEcond?ln.get_price(bar_index):(isBull?bx.get_top():bx.get_bottom())): -(CEcond?ln.get_price(bar_index):(isBull?bx.get_top():bx.get_bottom()))
  816. int m = isBull ? 1 : -1
  817. float price = isBull ? high : -low
  818. if price > threshold
  819. if shrinkFVGonFill
  820. bx.set_left(bxStart)
  821. bx.set_right(bxStart+1)
  822. ln.set_x1(lnStart)
  823. ln.set_x2(lnStart+1)
  824. boxArray.remove(i)
  825. lineArray.remove(i)
  826. countArr.push(isBull?1:-1) //for alerts; counter sum will decrement 1 on lower threshold hit, increment 1 on upper threshold hit
  827. if boxArray.size() > maxSize
  828. box.delete(boxArray.shift())
  829. line.delete(lineArray.shift())
  830.  
  831. fvgBxExtToPrice(bxDnArr,lnDnArr,_countArr, true, 12) //12 should be good for around 2200 bars of history
  832. fvgBxExtToPrice(bxUpArr, lnUpArr,_countArr, false, 12)
  833.  
  834. upThresholdLst = array.sum(_countArr)>array.sum(_countArr)[1]
  835. dnThresholdLst = array.sum(_countArr)<array.sum(_countArr)[1]
  836. alertcondition(upThresholdLst, "FVG (SIBI) ABOVE threshold (CE or fvg High)", "FVG SIBI above threshold")
  837. alertcondition(dnThresholdLst, "FVG (BISI) BELOW threshold (CE or fvg low)", "FVG BISI below threshold")
  838.  
  839. /// ~ Display Table ~
  840. test =array.size(STHboxArr)
  841. var Table = table.new(tabPos, columns = 4, rows =6, bgcolor = tabCol, border_width = 1)
  842. if barstate.islast and showTable and (showPivHighsLows or showSweepBoxes)
  843. table.cell(Table, 0, 0, "Long-Term", text_color = txtCol, bgcolor = tabCol)
  844. table.cell(Table, 0, 1, "last LTH = "+str.tostring(lastLTH, format.mintick),bgcolor = color.new(color.orange,70), text_color = txtCol)
  845. table.cell(Table, 0, 2, "last LTL = " +str.tostring(lastLTL, format.mintick),bgcolor = color.new(color.orange,70), text_color = txtCol)
  846. table.cell(Table, 1, 0, "Med-Term", text_color = txtCol, bgcolor = tabCol)
  847. table.cell(Table, 1, 1, "last MTH = " +str.tostring(lastMTH, format.mintick),bgcolor = color.new(color.yellow,60), text_color = txtCol)
  848. table.cell(Table, 1, 2, "last MTL = " +str.tostring(lastMTL, format.mintick),bgcolor = color.new(color.yellow,60), text_color = txtCol)
  849. table.cell(Table, 2, 0, "Short-Term", text_color = txtCol, bgcolor = tabCol)
  850. table.cell(Table, 2, 1, "last STH = "+str.tostring(lastSTH, format.mintick),bgcolor = color.new(color.gray,70), text_color = txtCol)
  851. table.cell(Table, 2, 2, "last STL = " +str.tostring(lastSTL, format.mintick),bgcolor = color.new(color.gray,70), text_color = txtCol)
  852.  
  853. if barstate.islast and showChochTable
  854. table.cell(Table, 1, 3, "Above HTF Up CHoCH:",bgcolor = tabCol, text_color = txtCol)//, text_halign = text.align_right)
  855. //table.merge_cells(Table, 0, 3, 1, 3)
  856. table.cell(Table, 1, 4, "Below HTF Down CHoCH:",bgcolor = tabCol, text_color = txtCol)//, text_halign = text.align_right)
  857. //table.merge_cells(Table, 0, 4, 1, 4)
  858. table.cell(Table, 2, 3, str.tostring(aboveLstUPcond),bgcolor =aboveLstUPcond? color.new(color.green,60): color.new(color.gray, 60), text_color = txtCol)
  859. table.cell(Table, 2, 4, str.tostring(belowLstDNcond),bgcolor =belowLstDNcond? color.new(color.red,60): color.new(color.gray, 60), text_color = txtCol)
  860.  
  861.  
Advertisement
Add Comment
Please, Sign In to add comment