version using moving average