Hi fellows,
Let me introduce you ALMA, the best moving average I've ever utilised. This is the website of Arnaud Legoux, where you can find related explanations:
http://www.arnaudlegoux.com.
And this is the simple PHP implementation of it:
function ALMA ($data) {
$sigma = 6;
$offset = 0.85;
$size = count ($data);
$m = $offset * ($size - 1);
$s = $size / $sigma;
$sum = 0;
$norm = 0;
for ($i = 0; $i < $size; $i++) {
$coeff = exp (- ($i - $m) * ($i - $m) / 2 * $s * $s);
$sum += $data[$size - $i - 1] * $coeff;
$norm += $coeff;
}
return $sum / $norm;
}
The array
$data will compromise the last closing values,
data[0] being the most recent one. It is argued that an odd value for the size of the array would yield better results.
Any opinion is welcome!