title: Selected time periods of IB data for data analysis
body: <p>Afternoon all,</p>
  <p>The below script captures Initial Balance (first highest and lowest price within the first 60 mins) for market opening times (London, New York and Asia).</p>
  <p>The building of IB happens within the first 60 mins and is displayed thereafter, so for example London 0800 to 0900 IB builds and displays 0900 onwards.</p>
  <p>The script then looks at the three IB highs and works out the highest and plots this (displayed as a white line in the below script).</p>
  <p>What I am trying to work out is how do I exclude the building phase of the new IB coming into play. The below pictures should help explain this:</p>
  <p><a href="https://i.stack.imgur.com/TKoQR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TKoQR.png" alt="enter image description here" /></a>
  How would I exclude the IB building phase for the blue plot, during that 1 hour the purple and yellow would only be included in the calculation and the white line would continue at the height on the highest excluding the IB build.</p>
  <p>I can explain further if required. Any assistance would be gratefully received.</p>
  <p>Please see script so far:</p>
  <pre><code>//@version=4
  study(&quot;Highest Test Script&quot;, overlay=true)
  
  
  offset_val = input(title=&quot;Daily Label Offset&quot;, type=input.integer, defval=10)
  offset_valW = input(title=&quot;Weekly Label Offset&quot;, type=input.integer, defval=30)
  
  
  
  // Asia Start
  time_int_01 = input(&quot;0000-0100:1234567&quot;, &quot;Asia&quot;, input.session)
  
  in_time_int_01 = time(timeframe.period, time_int_01)
  
  var highe_01 = 0.0
  var lowe_01  = 10e10
  if in_time_int_01
      if not in_time_int_01[1]
          highe_01 := high
          lowe_01  := low
      else
          highe_01 := max(high, highe_01)
          lowe_01  := min(low, lowe_01)
  
  plot(not in_time_int_01 ? highe_01 : na, title=&quot;Asia High&quot;, color=color.purple, linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_01 ? highe_01 : na, style=shape.labelup, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text=&quot;Asia/UTC High&quot;,  offset = offset_val, transp=20, title=&quot;Asia/UTC High&quot;)
  
  plot(not in_time_int_01 ? lowe_01  : na, title=&quot;Asia Low&quot;,  color=color.purple,  linewidth=2, style=plot.style_linebr)
  plotshape(not in_time_int_01 ? lowe_01 : na, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text=&quot;Asia/UTC Low&quot;,  offset = offset_val, transp=20, title=&quot;Asia/UTC Low&quot;)
  // Asia Finish
  
  
  // London Start
  time_int_02 = input(&quot;0800-0900:1234567&quot;, &quot;London&quot;, input.session)
  time_int_002 = input(&quot;0900-0800:1234567&quot;, &quot;London&quot;, input.session)
  
  in_time_int_02 = time(timeframe.period, time_int_02)
  
  var highe_02 = 0.0
  var lowe_02  = 10e10
  if in_time_int_02
      if not in_time_int_02[1]
          highe_02 := high
          lowe_02  := low
      else
          highe_02 := max(high, highe_02)
          lowe_02  := min(low, lowe_02)
  
  plot(not in_time_int_02 ? highe_02 : na, title=&quot;London High&quot;, color=color.yellow, linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_02 ? highe_02 : na, style=shape.labelup, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text=&quot;London High&quot;,  offset = offset_val, transp=20, title=&quot;London High&quot;)
  
  plot(not in_time_int_02 ? lowe_02  : na, title=&quot;London Low&quot;,  color=color.yellow,  linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_02 ? lowe_02  : na, style=shape.labeldown, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text=&quot;London Low&quot;,  offset = offset_val, transp=20, title=&quot;London Low&quot;)
  // London Finsh
  
  
  // New York Start
  time_int_03 = input(&quot;1430-1530:1234567&quot;, &quot;New York&quot;, input.session)
  
  in_time_int_03 = time(timeframe.period, time_int_03)
  
  var highe_03 = 0.0
  var lowe_03  = 10e10
  if in_time_int_03
      if not in_time_int_03[1]
          highe_03 := high
          lowe_03  := low
      else
          highe_03 := max(high, highe_03)
          lowe_03  := min(low, lowe_03)
  
  plot(not in_time_int_03 ? highe_03 : na, title=&quot;New York High&quot;, color=color.blue, linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_03 ? highe_03 : na, style=shape.labelup, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text=&quot;New York High&quot;,  offset = offset_val, transp=20, title=&quot;New York High&quot;)
  
  plot(not in_time_int_03 ? lowe_03  : na, title=&quot;New York Low&quot;,  color=color.blue,  linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_03 ? lowe_03  : na, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text=&quot;New York Low&quot;,  offset = offset_val, transp=20, title=&quot;New York Low&quot;)
  // New York Finish
  
  
  //Londontest = (not time_int_002 ? highe_02 : na)
  
  //DailyIBHighest = max(highe_01, Londontest, highe_03)
  
  DailyIBHighest = max(highe_01, highe_02, highe_03)
  
  plot(DailyIBHighest, color=color.white, linewidth=1, style=plot.style_linebr)
  </code></pre>
  <p>#####Update 18/02/2021 @ 1600 #####</p>
  <p>After thinking about this question further, what I am trying to achieve is to work out the max IB high as detailed below:</p>
  <p><strong>0000 - 0100</strong></p>
  <p>Yellow - highe_02</p>
  <p>Blue - highe_03</p>
  <p><strong>0100 - 0800</strong></p>
  <p>Yellow - highe_02</p>
  <p>Blue - highe_03</p>
  <p>Purple - highe_01</p>
  <p><strong>0800 - 0900</strong></p>
  <p>Blue - highe_03</p>
  <p>Purple - highe_01</p>
  <p><strong>0900 - 1430</strong></p>
  <p>Yellow - highe_02</p>
  <p>Blue - highe_03</p>
  <p>Purple - highe_01</p>
  <p><strong>1430 - 1530</strong></p>
  <p>Yellow - highe_02</p>
  <p>Purple - highe_01</p>
  <p><strong>1530 - 0000</strong></p>
  <p>Yellow - highe_02</p>
  <p>Blue - highe_03</p>
  <p>Purple - highe_01</p>
  <p><strong>##### Update 19/02/2021 @ 0845 ####</strong></p>
  <p>I have made the original IBs high/low as false within setting can be switched on to confirm the redlines are aligned correctly. This is how I would like it displayed but I feel I haven't gone the right way about it as I would like to consolidate the output red line into one output so that I can use it for alerts.</p>
  <pre><code>//@version=4
  study(&quot;Highest Test Script&quot;, overlay=true)
  
  
  offset_val = input(title=&quot;Daily Label Offset&quot;, type=input.integer, defval=10)
  offset_valW = input(title=&quot;Weekly Label Offset&quot;, type=input.integer, defval=30)
  ShowIB = input(false, title=&quot;show IBs&quot;)
  
  
  // Asia Start
  time_int_01 = input(&quot;0000-0100:1234567&quot;, &quot;Asia&quot;, input.session)
  time_int_001 = input(&quot;0100-0000:1234567&quot;, &quot;London&quot;, input.session)
  
  in_time_int_01 = time(timeframe.period, time_int_01)
  in_time_int_001 = time(timeframe.period, time_int_001)
  
  var highe_01 = 0.0
  var lowe_01  = 10e10
  if in_time_int_01
      if not in_time_int_01[1]
          highe_01 := high
          lowe_01  := low
      else
          highe_01 := max(high, highe_01)
          lowe_01  := min(low, lowe_01)
  
  plot(not in_time_int_01  and ShowIB ? highe_01 : na, title=&quot;Asia High&quot;, color=color.purple, linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_01  and ShowIB ? highe_01 : na, style=shape.labelup, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text=&quot;Asia/UTC High&quot;,  offset = offset_val, transp=20, title=&quot;Asia/UTC High&quot;)
  
  plot(not in_time_int_01  and ShowIB ? lowe_01  : na, title=&quot;Asia Low&quot;,  color=color.purple,  linewidth=2, style=plot.style_linebr)
  plotshape(not in_time_int_01  and ShowIB ? lowe_01 : na, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text=&quot;Asia/UTC Low&quot;,  offset = offset_val, transp=20, title=&quot;Asia/UTC Low&quot;)
  // Asia Finish
  
  
  // London Start
  time_int_02 = input(&quot;0800-0900:1234567&quot;, &quot;London&quot;, input.session)
  time_int_002 = input(&quot;0900-0800:1234567&quot;, &quot;London&quot;, input.session)
  
  in_time_int_02 = time(timeframe.period, time_int_02)
  in_time_int_002 = time(timeframe.period, time_int_002)
  
  
  var highe_02 = 0.0
  var lowe_02  = 10e10
  if in_time_int_02
      if not in_time_int_02[1]
          highe_02 := high
          lowe_02  := low
      else
          highe_02 := max(high, highe_02)
          lowe_02  := min(low, lowe_02)
  
  plot(not in_time_int_02  and ShowIB ? highe_02 : na, title=&quot;London High&quot;, color=color.yellow, linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_02  and ShowIB ? highe_02 : na, style=shape.labelup, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text=&quot;London High&quot;,  offset = offset_val, transp=20, title=&quot;London High&quot;)
  
  plot(not in_time_int_02  and ShowIB ? lowe_02  : na, title=&quot;London Low&quot;,  color=color.yellow,  linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_02  and ShowIB ? lowe_02  : na, style=shape.labeldown, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text=&quot;London Low&quot;,  offset = offset_val, transp=20, title=&quot;London Low&quot;)
  // London Finsh
  
  
  // New York Start
  time_int_03 = input(&quot;1430-1530:1234567&quot;, &quot;New York&quot;, input.session)
  time_int_003 = input(&quot;1530-1430:1234567&quot;, &quot;New York&quot;, input.session)
  
  in_time_int_03 = time(timeframe.period, time_int_03)
  in_time_int_003 = time(timeframe.period, time_int_003)
  
  var highe_03 = 0.0
  var lowe_03  = 10e10
  if in_time_int_03
      if not in_time_int_03[1]
          highe_03 := high
          lowe_03  := low
      else
          highe_03 := max(high, highe_03)
          lowe_03  := min(low, lowe_03)
  
  plot(not in_time_int_03  and ShowIB ? highe_03 : na, title=&quot;New York High&quot;, color=color.blue, linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_03 and ShowIB ? highe_03 : na, style=shape.labelup, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text=&quot;New York High&quot;,  offset = offset_val, transp=20, title=&quot;New York High&quot;)
  
  plot(not in_time_int_03 and ShowIB ? lowe_03  : na, title=&quot;New York Low&quot;,  color=color.blue,  linewidth=3, style=plot.style_linebr)
  plotshape(not in_time_int_03 and ShowIB ? lowe_03  : na, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text=&quot;New York Low&quot;,  offset = offset_val, transp=20, title=&quot;New York Low&quot;)
  // New York Finish
  
  
  
  Session01 = input(&quot;0000-0100:1234567&quot;, &quot;0000 - 0100&quot;, input.session)
  S1 = time(timeframe.period, Session01)
  
  Session02 = input(&quot;0100-0800:1234567&quot;, &quot;0100 - 0800&quot;, input.session)
  S2 = time(timeframe.period, Session02)
  
  Session03 = input(&quot;0800-0900:1234567&quot;, &quot;0800 - 0900&quot;, input.session)
  S3 = time(timeframe.period, Session03)
  
  Session04 = input(&quot;0900-1430:1234567&quot;, &quot;0900 - 1430&quot;, input.session)
  S4 = time(timeframe.period, Session04)
  
  Session05 = input(&quot;1430-1530:1234567&quot;, &quot;1430 - 1530&quot;, input.session)
  S5 = time(timeframe.period, Session05)
  
  Session06 = input(&quot;1530-0000:1234567&quot;, &quot;1530 - 0000&quot;, input.session)
  S6 = time(timeframe.period, Session06)
  
  Test1 = S2 or S4 or S6 ? max(highe_01, highe_02, highe_03) : na
  Test2 = S5 ? max(highe_02, highe_01) : na
  Test3 = S1 ? max(highe_02, highe_03) : na
  Test4 = S3 ? max(highe_03, highe_01) : na
  
  Test1a = S2 or S4 or S6 ? min(lowe_01, lowe_02, lowe_03) : na
  Test2a = S5 ? min(lowe_02, lowe_01) : na
  Test3a = S1 ? min(lowe_02, lowe_03) : na
  Test4a = S3 ? min(lowe_03, lowe_01) : na
  
  
  plot(Test1, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test2, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test3, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test4, color=color.red, linewidth=1, style=plot.style_linebr)
  
  plot(Test1a, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test2a, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test3a, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test4a, color=color.red, linewidth=1, style=plot.style_linebr)
  </code></pre>
  <p>Is there a way to put the below extract into a var or function? Just seems to much code, I feel I have not completed it correctly.</p>
  <pre><code>Session01 = input(&quot;0000-0100:1234567&quot;, &quot;0000 - 0100&quot;, input.session)
  S1 = time(timeframe.period, Session01)
  
  Session02 = input(&quot;0100-0800:1234567&quot;, &quot;0100 - 0800&quot;, input.session)
  S2 = time(timeframe.period, Session02)
  
  Session03 = input(&quot;0800-0900:1234567&quot;, &quot;0800 - 0900&quot;, input.session)
  S3 = time(timeframe.period, Session03)
  
  Session04 = input(&quot;0900-1430:1234567&quot;, &quot;0900 - 1430&quot;, input.session)
  S4 = time(timeframe.period, Session04)
  
  Session05 = input(&quot;1430-1530:1234567&quot;, &quot;1430 - 1530&quot;, input.session)
  S5 = time(timeframe.period, Session05)
  
  Session06 = input(&quot;1530-0000:1234567&quot;, &quot;1530 - 0000&quot;, input.session)
  S6 = time(timeframe.period, Session06)
  
  Test1 = S2 or S4 or S6 ? max(highe_01, highe_02, highe_03) : na
  Test2 = S5 ? max(highe_02, highe_01) : na
  Test3 = S1 ? max(highe_02, highe_03) : na
  Test4 = S3 ? max(highe_03, highe_01) : na
  
  Test1a = S2 or S4 or S6 ? min(lowe_01, lowe_02, lowe_03) : na
  Test2a = S5 ? min(lowe_02, lowe_01) : na
  Test3a = S1 ? min(lowe_02, lowe_03) : na
  Test4a = S3 ? min(lowe_03, lowe_01) : na
  
  
  plot(Test1, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test2, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test3, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test4, color=color.red, linewidth=1, style=plot.style_linebr)
  
  plot(Test1a, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test2a, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test3a, color=color.red, linewidth=1, style=plot.style_linebr)
  plot(Test4a, color=color.red, linewidth=1, style=plot.style_linebr)
  </code></pre>