Hi Is possible to calculate EMA in javascript?
The formula for EMA that I'm trying to apply is this
EMA = array[i] * K + EMA(previous) * (1 – K)
Where K is the smooth factor:
K = 2/(N + 1)
And N is the Range of value that I wanna consider
So if I've an array of value like this, and this value grow during the times:
var data = [15,18,12,14,16,11,6,18,15,16];
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.
function EMACalc(Array,Range) {
var k = 2/(Range + 1);
...
}
I can't figure out how to achieve this, any help would be apreciated
Array
andRange
as parameter names, as you are overwriting native JS objects – RefrigerantEMA = array[i] * K + EMA(previous) * (1 – K)
you meanEMA[i] = array[i] * K + EMA[i - 1] * (1 – K)
? – Refrigerant