I'm having trouble with the Java below. data_array
is an ArrayList of arrays. I'm trying to get to all of the arrays within the ArrayList with a 'for' loop but I cannot do .get
on the ArrayList for some reason. Any help would be much appreciated! Thanks!
public static double calc_SMA (Collection<Double> data_array, int bar_avg, int array_position){
//Create array to select which array in the ArrayList to pull from
double [] holding = new double [4];
//variable to hold the sum of the bars
double sum = 0.0;
//Create loop to pull data via...put into avg_calc
for (int i = 0; i < bar_avg; i++) {
//Cycle through arrays within the data_array ArrayList starting from first row to bar_avg - 1
holding = data_array.get(i);
//Add value to the previous value with 'sum'
//array_position is the place (0-3) that we are calculating avg of
sum = sum + holding[array_position];
//clear holding array
holding = null;
}
double average = sum/bar_avg;
return average;
}