Exploring the McGinley Dynamic: An Innovative Indicator
Written on
Chapter 1: Understanding Moving Averages
Moving averages come in various forms, each with its own set of benefits and drawbacks. This article delves into a lesser-known type known as the McGinley Dynamic, a distinctive smoothing method.
Following the success of my previous book, "Trend Following Strategies in Python," I have released a new publication that includes advanced contrarian indicators and strategies. It features a dedicated GitHub page where the continuously updated code can be accessed. If you're interested, you can purchase the PDF version for 9.99 EUR via PayPal. Please include your email in the note so that it can be sent to the correct address. Once you receive it, ensure you download it through Google Drive.
Section 1.1: Basics of Moving Averages
The simplest form of moving average is the simple moving average (SMA), calculated by dividing the sum of a set of values by the number of values. Here’s the mathematical representation of how to compute a simple mean from a dataset:
Thus, the SMA is the total of the values divided by their count. In technical analysis, moving averages are primarily used to discern underlying trends and generate trading signals. For instance, observe the chart below that illustrates a 60-period simple moving average applied to the hourly values of Ethereum against USD (ETH/USD).
Assuming you have an OHLC data array imported into Python (as demonstrated in my prior articles), you can implement the following foundational functions to facilitate better data manipulation:
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 data
def delete_column(data, index, times):
for i in range(1, times + 1):
data = np.delete(data, index, axis=1)return data
def delete_row(data, number):
data = data[number:, ]
return data
To compute a simple moving average, you can use the following function:
def ma(data, lookback, close, position):
data = add_column(data, 1)
for i in range(len(data)):
try:
data[i, position] = (data[i - lookback + 1:i + 1, close].mean())except IndexError:
passdata = delete_row(data, lookback)
return data
It’s crucial to grasp the underlying concepts rather than just the code. Most of my strategies are documented in my books, focusing on understanding the techniques and methodologies.
I have recently partnered with Lumiwealth, offering hands-on courses in algorithmic trading, blockchain, and machine learning. I encourage you to explore the link below for more information.
Chapter 2: The McGinley Dynamic
The McGinley Dynamic is not widely recognized but holds significant potential. Invented by John R. McGinley, this lag-reducing technique functions similarly to moving averages. It adjusts based on market speed and is calculated using the following formula:
The initial value of the McGinley Dynamic is the price itself, followed by the application of the formula mentioned above. The constant 'k' is set at 0.60, and 'N' represents the lookback period. Just as we adjust the lookback periods for moving averages, the same can be applied to the McGinley Dynamic.
def mc_ginley_dynamic_average(Data, lookback, close, where):
Data = add_column(Data, 1)
for i in range(len(Data)):
if Data[i - 1, where] == 0:
Data[i, where] = Data[i, close]elif Data[i - 1, where] > 0:
Data[i, where] = Data[i - 1, where] + ((Data[i, close] - Data[i - 1, where]) / (0.6 * lookback * (Data[i, close] / Data[i - 1, where])**4))return Data
The chart below demonstrates the McGinley Dynamic in action, showing how it adapts to market movements while minimizing false signals.
The above video explains how to effectively utilize the McGinley Dynamic indicator, highlighting its advantages over traditional moving averages.
The McGinley Dynamic also possesses a psychological element, speeding up in declining markets and slowing down during uptrends. This is rooted in the long-only mentality, where sellers in panic tend to act more quickly, necessitating an indicator that swiftly confirms downward movements.
The second video elaborates on why the McGinley Dynamic is considered a superior alternative to traditional moving averages, showcasing its unique features and benefits.
In summary, I aim to contribute to the realm of objective technical analysis, advocating for transparent strategies that are thoroughly back-tested prior to implementation. This approach can enhance the credibility of technical analysis, distancing it from its often subjective reputation.
When evaluating a trading technique or strategy, I recommend the following steps:
- Maintain a critical mindset, free from emotional bias.
- Conduct back-testing using real-life simulations and conditions.
- If promising, optimize the strategy and perform a forward test.
- Incorporate transaction costs and slippage into your simulations.
- Always consider risk management and position sizing in your analyses.
Even after following these steps, remain vigilant and monitor the strategy, as market dynamics may evolve and render the strategy less effective.