O'Reilly logo

Clojure for Finance by Timothy Washington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The exponential moving average

An exponential moving average (EMA) basically weights newer prices more than older ones, thereby reducing lag and applying more weight to recent prices (for more details on EMA, visit https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average). This way, more recent price changes have a greater effect on the overall average. Let's build our EMA function. To begin, I'll use raw algebra to outline the equation:

  1. The EMA is a function of the SMA. Thus, we use the SMA as the price input to our function.
  2. We also have to decide the time period (or tick-window) for which our EMA will apply. Since our SMA has used 20 time periods (or ticks), we're also going to use this number for our EMA.
  3. Next, we'll calculate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required