title: How TradingView Pine Script RMA works?
body: <p>I faced the problem that I wanted to implement the same indicators as in the trading view, but I can't correctly implement the RMA indicator.</p>
  <p>If I refer to the documentation, I get the following code:</p>
  <pre><code>pine_rma(src, length) =&gt;
      alpha = length
      sum = 0.0
      sum := na(sum[1]) ? sma(src, length) : (src + (alpha - 1) * nz(sum[1])) / alpha
  </code></pre>
  <p>Everything in it is clear to me, except for the when <strong>na(sum[1])</strong> condition may occur. And do I understand correctly that <strong>nz(sum[1])</strong> is the previous value of <strong>sum</strong>.</p>
  <p>When I try to implement it in golang, they write the following code:</p>
  <pre><code>func RMA(value []float64, period int) float64 {
      var sum float64 
  
      for i := period - 1; i &gt;= 0; i-- {
          sum = (sum * (float64(period) - 1) + value[i]) / float64(period)
      }
  
      return sum
  }
  </code></pre>
  <p>And I am having strong discrepancies in the returned data.</p>
  <p>I tried to understand what values ​​are obtained in order from the RMA with a period of 3, when the input parameters for it are</p>
  <p><strong>src[0] = 0, src[1] = 0</strong> and <strong>src[2] = 0.12</strong></p>
  <p>and we get that</p>
  <p><strong>rma[0] = 0.06, rma [1] = 0.04</strong> and <strong>rma [2] = 0.03</strong></p>
  <p>and I don't understand where such numbers are taken, because I substitute src in the original formula, we get the most different numbers.</p>
  <p>I took the benchmark data from the down array created for RSI from the <em>FORD MTR CO DEL, 1D, Cboe BZX</em> chart for September 2, 2020.</p>