edited calculateEMA function