title: Draw box/rectangle over time range
body: <p>Im trying to draw a box over the range of price over a time period. I am successfuly at drawing the box however having difficulty tracking the price.</p>
  <p>Key things:</p>
  <ul>
  <li>I only want to draw the latest box and not all over history</li>
  <li>Using max_lines_count should not be an option as I'm using this as part of a larger indicator.</li>
  </ul>
  <p>Here's my code</p>
  <pre><code>//@version=4
  study(&quot;Box over range&quot;, overlay=true)
  
  showRange = input(title=&quot;Show Range&quot;, type=input.bool, defval=true)
  rangeTime = input(title=&quot;Session Time&quot;, type=input.session, defval=&quot;1800-0259&quot;)
  extendUntil = input(title=&quot;Session Time&quot;, type=input.session, defval=&quot;0300-1700&quot;)
  
  resolutionInMinutes() =&gt; 
      resInMinutes = timeframe.multiplier * (
        timeframe.isseconds ? 1. / 60             :
        timeframe.isminutes ? 1.                  :
        timeframe.isdaily   ? 60. * 24            :
        timeframe.isweekly  ? 60. * 24 * 7        :
        timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
  
  f_timeFrom(_from, length, _units) =&gt;
      int _timeFrom = na
      _unit = str.replace_all(_units, &quot;s&quot;, &quot;&quot;)
      _timeFrom := int(time + (resolutionInMinutes() * 60 * 1000 * length))
  
  linelength = 9 //(temporary length)
  
  inSession = not na(time(timeframe.period, rangeTime))
  
  startTime = inSession and not inSession[1] ? time : na
  endTime = f_timeFrom(&quot;bar&quot;, linelength, &quot;chart&quot;)
  
  line lowHLine = na
  line topHLine = na
  line leftVLine = na
  line rightHLine = na
  
  // Build the Box
  if not na(startTime)
      highestPoint = high
      lowestPoint = low
  
      //x1, y1, x2, y2
      lowHLine = line.new(startTime, lowestPoint, endTime, lowestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
      topHLine = line.new(startTime, highestPoint, endTime, highestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
      leftVLine = line.new(startTime, highestPoint, startTime, lowestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
      rightHLine = line.new(endTime, highestPoint, endTime, lowestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
  
      line.delete(lowHLine[1])
      line.delete(topHLine[1])
      line.delete(leftVLine[1])
      line.delete(rightHLine[1])
      
  //Track price
  if inSession
      lineHigh = line.get_y2(topHLine)
  
      if high &gt; lineHigh
          line.set_y1(topHLine, high)
          line.set_y2(topHLine, high)
  </code></pre>
  <p>The track price is just a rough code and obviously I do understand why it doesn't work, but I cannot find an elegant solution. Thank you</p>