Implementation of the moving average convergence divergence

Let's implement a moving average convergence divergence signal with a fast EMA period of 10 days, a slow EMA period of 40 days, and with default smoothing factors of 2/11 and 2/41, respectively:

num_periods_fast = 10 # fast EMA time periodK_fast = 2 / (num_periods_fast + 1) # fast EMA smoothing factorema_fast = 0num_periods_slow = 40 # slow EMA time periodK_slow = 2 / (num_periods_slow + 1) # slow EMA smoothing factorema_slow = 0num_periods_macd = 20 # MACD EMA time periodK_macd = 2 / (num_periods_macd + 1) # MACD EMA smoothing factorema_macd = 0ema_fast_values = [] # track fast EMA values for visualization purposesema_slow_values = [] # track slow EMA values for visualization purposes ...

Get Learn Algorithmic Trading now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.