title: How to get last value that equals the current value in TradingView Pine Script?
body: <p>I am using Pine Script which is used in tradingview.com.</p>
  <p>My question is: how I can get the last value that equals the current value? I thought about using a <code>for</code> loop or something else.</p>
  <p>I tried this code but it returns an error:</p>
  <pre><code>getval(x,y) =&gt;
      for i = 1 to 100
          val = valuewhen(i, y, 1)
          val2 = valuewhen(x=i, val, 1)
      val2
  </code></pre>