ema function
The exponential mean, seeded with the first period values' mean.
Implementation
List<double?> ema(List<double?> v, int period) {
final out = List<double?>.filled(v.length, null);
final seed = sma(v, period);
final a = 2 / (period + 1);
double? last;
for (var i = 0; i < v.length; i++) {
final x = v[i];
if (x == null) {
last = null;
} else if (last == null) {
last = seed[i];
} else {
last = x * a + last * (1 - a);
}
out[i] = last;
}
return out;
}