title: Problem with Pine Scripts plotshapes offset
body: <p>This script will denote highs, with the left bar being lower and the right bar being lower.
  I also want this script to give me the HighofHighs, with the left high and right high being lower.
  I have it working but I can't get the label to display on the correct bar. </p>
  
  <p>If I use offset=-1, it will put it over the most recent high, if I use offset=-high_bars_back it doesn't offset it at all. </p>
  
  <p>(the default of the code is showing "HighofHighs" on the most current high (using offset=-1), but I need it to display on the second to most current high)</p>
  
  <p><a href="https://i.stack.imgur.com/0sFOa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0sFOa.png" alt="enter image description here"></a></p>
  
  <pre><code>//@version=3
  
  strategy(title = "Trend_v1", shorttitle = "Thrend_v1", overlay = true, 
    pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, 
    calc_on_every_tick=true, initial_capital=100000)//, calc_on_order_fills=true)
  
  
  //Window of time
  start     = timestamp(1000, 01, 01, 00, 00)  // backtest start window
  finish    = timestamp(3000, 10, 01, 00, 00)        // backtest finish window
  window()  =&gt; time &gt;= start and time &lt;= finish ? true : false // create function "within window of time"    
  
  //Input
  showLocalTrendHighLables = input(title="Show Local Trend High Labels", type=bool, defval=true)
  showRealTrendHighLables = input(title="Show Real Trend High Labels", type=bool, defval=true)
  
  //Initialize Variables
  first_high = na
  second_high = na
  third_high = na
  local_trend_highs = na
  real_trend_highs = na
  
  //Local Trend Highs
  if(nz(high[2]) &lt; nz(high[1]) and nz(high[1]) &gt; high)
      local_trend_highs := nz(high[1])
      third_high := second_high[1]
      second_high := first_high[1]
      first_high := nz(high[1])
  else
      local_trend_highs := nz(local_trend_highs[1])
      third_high := third_high[1]
      second_high := second_high[1]
      first_high := first_high[1]
  
  //Real Trend Highs
  if (third_high &lt; second_high and second_high &gt; first_high)
      real_trend_highs := nz(local_trend_highs)
  else
      real_trend_highs := nz(real_trend_highs[1])
  
  
  //Calculate how many high bars back to display HighofHighs
  high_bars_back = 0
  for i = 0 to 999
      high_bars_back = i
      if(high[i] == second_high)
          break
      else
          continue
  
  
  //Plots
  plotshape((not (local_trend_highs == local_trend_highs[1])) and showLocalTrendHighLables, style=shape.arrowdown, location=location.abovebar, color=green, text='high', offset=-1)
  
  //For some reason, offset=-high_bars_back doesn't shift at all
  plotshape((not (real_trend_highs == real_trend_highs[1])) and showRealTrendHighLables, style=shape.arrowdown, location=location.top, color=green, text='HIGHofHIGHs', offset=-1)//offset=-high_bars_back)
  
  plot(high_bars_back, color=blue, style=columns)
  </code></pre>