public static double[] MA(Index[] data2,int n){
        Index[] data = new Index[data2.length];
        data=ReverseIndex(data2);
        double[] out = new double[data.length];
        for(int i=0;i<data.length;i++){
            if(data.length-n<=i){
                int nn=data.length-i;
                double avg_close=0;
                for(int j=i;j<data.length;j++){
                    avg_close+=data[j].getClose_val();
                }
                avg_close/=nn;
                out[i]=avg_close;
            }else{
                double avg_close=0;
                for(int j=i;j<i+n;j++){
                    avg_close+=data[j].getClose_val();
                }
                avg_close=avg_close/n;
                out[i]=avg_close;
            }
        }
        out=Reverse(out);
        return out;
    }