int bars = 20;
double [] ma = new double [x.length - bars]; //
int k = 0;
for (int i = bars - 1; i < double.length; i++)
{
ma [k] = 0.0;
for (int j = 0; j < bars; j++)
{
ma [k] += x [i - j];
}
ma [k++] /= bars;
}
Quote from dcraig:
I think this is correct. There are other ways.
double [] x; // your input time series
Code:int bars = 20; double [] ma = new double [x.length - bars]; // int k = 0; for (int i = bars - 1; i < x.length; i++) // for each bar { ma [k] = 0.0; for (int j = 0; j < bars; j++) // sum over 'bars' previous input values { ma [k] += x [i - j]; } ma [k++] /= bars; // divide by number of bars }
