How to add Exponential Moving Averages to Your Trading Arsenal

Step-by-step examples using Python

Raposa.Trade
Raposa Technologies
4 min readMay 13, 2021

--

Moving average indicators are used in a variety of trading strategies to spot long-term trends in the price data. One potential drawback of simple moving average strategies is that they weight all of the prices equally, whereas you might want more recent prices to take on a greater importance. The exponential moving average (EMA) is one way to accomplish this.

Photo by Luke Chesser on Unsplash

TL;DR

We walk through the EMA calculation with code examples and compare it to the SMA.

Calculating the Exponential Moving Average

The EMA gives more weight to the most recent prices via a weighting multiplier. This multiplier is applied to the last price so that it accounts for a larger chunk of the moving average than the other data points.

The EMA is calculated by taking the most recent price (we’ll call it 𝑃𝑡, or “price at time 𝑡”) and subtracting the EMA from the previous time period (𝐸𝑀𝐴𝑡−1). This difference is weighted by the number of time periods you set your EMA to (𝑁) and added back to the 𝐸𝑀𝐴𝑡−1.

Mathematically, we can write it like this:

--

--