Formula for calculating EMA
With the calculation formula of the SMA, it is too simple a problem that everyone learns: averaging the price in a certain period.
For example, SMA14 means that you will add up the closing price of the 14-day trade and divide it by 14.
Meanwhile, the formula of the EMA will be much different, in order to solve a problem that the SMA cannot do, eliminate the price taking place in the form of a spread throughout the cycle, instead the EMA will only focus on price closest to the current price, by reducing lag by applying more weight to recent prices. The weighting applied to the most recent price depends on the number of periods in the moving average. EMAs differ from simple moving averages in that the calculation of a given day's EMA depends on EMA calculations for all days prior to that date. Therefore, to accurately calculate the EMA will require more than 10 days of data. This also explains why shorter period EMAs are more likely to be broken, while longer period EMAs are harder to break.
Three steps to calculate exponential moving average (EMA).
Let's calculate a simple moving average for the initial EMA value. The exponential moving average (EMA) has to start somewhere, so the simple moving average is used as the previous period's EMA in the first calculation.
Calculate weights.
Calculate the exponential moving average for each day between the original EMA value and today, using the price, coefficient, and EMA value of the previous period.
Assume this is the EMA formula for the 10-day EMA.
Initial SMA: 10 period total / 10
Weight: 2 / (Duration + 1) = 2 / (10 + 1) = 0.1818 (18.18%)
EMA: {Close – EMA (previous day)} x weight + EMA (previous day)