title: Divergence Funtion result issue
body: <p>I try to implement a function to find short term RSI divergences. I want it to work like this:</p>
  
  <ul>
  <li>Find last RSI pivot </li>
  <li>Compare it to previous Pivots  </li>
  <li>If there is a Divergence, set counter plus one</li>
  <li>And if my counter over 0 - show a divergence char at bar.</li>
  </ul>
  
  <p>But it doesn't work.</p>
  
  <pre><code>study("RSI short term divergence", overlay=true)
  
  //Inputs
  lookback = input(defval=34, title='Lookback for RSI divergence, bars', minval=1, type=input.integer)
  len = input(defval=3, title='Pivot confirmation, bars', minval=1, type=input.integer)
  
  //RSI
  rsi = rsi(close, 14)
  
  //Variables
  pivotLow = pivotlow(rsi, len, 1)
  
  //Function
  
  func_short(pivsback) =&gt;
      count_s = 0
      for i = 1 to pivsback
          rsiLast_s = valuewhen(pivotLow, rsi[1], 0)
          priceLast_s = valuewhen(pivotLow, close[1], 0)
          barLast_s = valuewhen(pivotLow, bar_index[1], 0)
          rsiWas_s = valuewhen(pivotLow, rsi[1], i)
          priceWas_s = valuewhen(pivotLow, close[1], i)
          barWas_s = valuewhen(pivotLow, bar_index[1], i)
          count_s = if (rsiLast_s &gt; rsiWas_s) and (priceWas_s &gt; priceLast_s) and (barLast_s-barWas_s)&lt;lookback
              count_s := count_s + 1
      count_s
  
  divShort = func_short(3)&gt;0
  
  plotchar(divShort, location=location.abovebar, color=color.white, size=size.small)
  </code></pre>