I have found this with credit to this user "Jonathan K 2806".
try this instead, simpler and probably enough:
/**
* Calculates the EMA of the range.
*
* @param {range} range The range of cells to calculate.
* @param {number} n The number of trailing samples to give higer weight to, e.g. 30.
* @return The EMA of the range.
* @customfunction
*/
function EMA(range, n) {
if (!range.reduce) {
return range;
}
n = Math.min(n, range.length);
var a = 2 / (n + 1);
return range.reduce(function(accumulator, currentValue, index, array) {
return currentValue != "" ? (currentValue * a + accumulator * (1-a)) : accumulator;
}, 0);
}
go to tools -> script editor, paste this there and hit save than go back to your spreadsheet and type into a cell =EMA($A2:$A100, 10) or however you want to use it.