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

Signals using moving averages

Now that our analytic functions are lazy and we can join them into one list, we can start thinking about what signals we may be interested in. A simple and direct signal is finding out whether the EMA in one tick element has crossed above the SMA from a previous element. Another signal would be the inverse of this—we can find out whether, in the first element, the EMA has crossed below the SMA from the second element. This is another process criteria where a current tick needs to know about a previous tick. However, in this situation, the previous computation isn't needed by the current one. We can just partition our ticks by two to check for a crossover. Let's take a look at an implementation now:

(defn moving-averages-signals ...

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