code: public static double simpleMovingAverage(FlatDataList flatDataList, int N) {
          double SMA=0;
  
          int counter=0;
          for(int i=flatDataList.size()-1;i>=0;--i) {
              double Yti = flatDataList.getDouble(i);
              if(counter>=N) {
                  break;
              }
              SMA+=Yti; //possible numeric overflow 
              ++counter;
          }
  
          SMA/=counter;
  
          return SMA;
      }
docs: Simple Moving Average
  
  @param flatDataList
  @param N
  @return