title: Calculating Exponential Moving Average (EMA) using javascript
body: <p>Hi Is possible to calculate EMA in javascript?</p>
  
  <p>The formula for EMA that I'm trying to apply is this</p>
  
  <blockquote>
    <p>EMA = array[i] * K + EMA(previous) * (1 – K)</p>
  </blockquote>
  
  <p>Where K is the smooth factor:</p>
  
  <blockquote>
    <p>K = 2/(N + 1)</p>
  </blockquote>
  
  <p>And N is the Range of value that I wanna consider</p>
  
  <p>So if I've an array of value like this, and this value grow during the times:</p>
  
  <pre><code>var data = [15,18,12,14,16,11,6,18,15,16];
  </code></pre>
  
  <p>the goal is to have a function, that return the array of the EMA, because any of this value, expect the very fist "Range" value, have this EMA, for each item on data, I've the related EMA value. In that way I can use all or use only the last one to "predict" the next one.</p>
  
  <pre><code>function EMACalc(Array,Range) {
  var k = 2/(Range + 1);
  ...
  }
  </code></pre>
  
  <p>I can't figure out how to achieve this, any help would be apreciated</p>