Create a new moving average. this.periods = periods; this.data = new double[periods]; reset();
this.periods = periods; this.data = new double[periods]; reset();
double sum = 0.0; for (int i=0; i < periods; i++) { sum += data[i]; } return sum / periods;
Return average-so-far. return calculateAve();
return calculateAve();
pos = 0; for (int i=0; i < periods; i++) { data[i] = 0.0; }
Update average and return average-so-far. data[pos] = newValue; pos++; if (pos == periods) pos = 0; return calculateAve();
data[pos] = newValue; pos++; if (pos == periods) pos = 0; return calculateAve();