title: Read the historical values of a variable at the last bar
body: <p>How can I read the past values of a series variable at the last bar? For example, in my script below I would like the <code>last_bar_n</code> variable to contain all the historical values of the <code>n</code> variable, not just the last one.</p>
  <p>How can I do that, please? Maybe a function is more appropriate here?</p>
  <p>I need this in a script where at the last bar I have a variable (such as <code>last_bar_n</code>, in my example here) that will change its content in a <code>for</code> loop. With each loop, this variable should read the historical values of other global variables (such as <code>n</code> here).</p>
  <p>Thank you!</p>
  <p>Alex</p>
  <pre><code>//@version=5
  indicator(&quot;&quot;)
  
  var float last_bar_n = na
  
  n = close
  
  if (barstate.islast)
  
      last_bar_n := n
      
      // this does not show the previous bar value, so there are no historical values in this variable
      label.new(bar_index, close, str.tostring(last_bar_n[1]), textcolor=#ffffff)
  </code></pre>