For example, to calculate a 21-day moving average, the closing prices of the last 21 days are added up and the total is divided by 21. We perform the same calculation with each new trading day forward. Each time, only the prices of the last 21 days are used in the calculation. This is why it is called a moving average.