The McGinley Moving Average

Coding the McGinley Dynamic in Python

Sofien Kaabar, CFA
6 min readMay 1, 2022

--

Image source: www.pxfuel.com
Image source: www.pxfuel.com

Moving averages come in all shapes and forms and each type has its advantages and limitations. In this article, we will discuss a less common type called the McGinley dynamic, an unusual form of smoothing.

I have released a new book after the success of my previous one “Trend Following Strategies in Python”. It features advanced contrarian indicators and strategies with a GitHub page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below Amazon link (which contains a sample), or if you prefer to buy the PDF version, you could check the link at the end of the article.

Moving Averages

Moving averages come in all shapes and types. The most basic type is the simple moving average which is simply the sum divided by the quantity. The next mathematical representation shows how to calculate a simple mean given a dataset:

Therefore, the simple moving average is the sum of the values divided by their number. In technical analysis, you generally use moving averages to understand the underlying trend and to find trading signals. Check the next Figure which shows a 60-period simple moving average applied on hourly values of Ethereum versus USD.

ETHUSD with its 60-period simple moving average.

Assume you have an OHLC data array imported in Python (which I have shown how to do many times in previous articles). Write the below primal functions that allow you to better manipulate data:

def add_column(data, times):

for i in range(1, times + 1):

new = np.zeros((len(data), 1), dtype = float)

data = np.append(data, new, axis = 1)
return datadef delete_column(data, index, times):

for i in range(1, times + 1):

data =…

--

--

Sofien Kaabar, CFA

Top writer in Finance, Investing, Business | Trader & Author

Recommended from Medium

Lists

See more recommendations