McGinley Dynamic (MCGD)
Summary
McGinley Dynamic (John R. McGinley, Jr.): a moving average whose speed adjusts to the market. Each bar closes a fraction 1 / (N * (x/MD)^4) of the gap to the price: less than RMA's 1/N while the price is above the line, more while it is below, so the line tracks falling prices faster than rising ones.
McGinley suggests a period of about 60% of the simple moving average being emulated: a Dynamic of 12 to follow a 20-bar average.
Chart
Chart metadata i
Outputs
outReal:line
Formula
N = optInTimePeriod
MD[0] = x[0]
for i >= 1: MD[i] = MD[i-1] + ( x[i] - MD[i-1] ) / ( N * ( x[i] / MD[i-1] )^4 )
The first output is at bar N-1.
Notes
- Where the price is 0, or so small against the line that the step overflows, the step is undefined and the line keeps its previous value. A line at 0 stays at 0.
- Being recursive, an output depends on how much history precedes it. Close to the price the seed's influence decays by a factor of
1 - 1/Nper bar, as inRMA; the unstable period is how much of the warm-up to discard. - The line is scale-equivariant but meant for positive prices: a series crossing zero sends it off to meaningless values, and a single bar far enough below the line can take the line to 0 or below it.
- Some implementations seed with the simple average of the first N bars. They agree with this one only once the seed's influence has decayed.
- Some implementations write the step's denominator as
0.6 * P * (x / MD)^4. That is this function at a period of0.6 * P, when that is an integer.
Inputs
inReal— Data on which to compute the average
Outputs
outReal— McGinley Dynamic line
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 14 | 2–100000 | The N of the step's denominator |
Properties
Numerical Stability: Initial Unstable Period
| ✅ Overlap Input i |
| ☐ Independent Y-Axis |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ✅ Input Must Be Positive i |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_MCGD( 0, n - 1, series, 14, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %f\n", outNBElement, outBegIdx, out[outNBElement - 1] );use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.mcgd(0, series.len() - 1, &series, 14, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.mcgd(0, series.length - 1, series, 14, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + out[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Mcgd(0, series.Length - 1, series, 14, outReal);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outReal = {outReal[r.Count - 1]}");import { mcgd } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = mcgd(series, { timePeriod: 14 });
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.8.3 (ta-lib-python 0.8.3).
TA-Lib Definition: mcgd.c · mcgd.yaml
| Native | File |
|---|---|
| C | ta_MCGD.c |
| Rust | mcgd.rs |
| Java | Core_MCGD.java |
| C# | Core_MCGD.cs |
| TypeScript | mcgd.ts |
Python: talib.MCGD (ta-lib-python 0.8.3 or later), see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
McGinley Dynamic, MD, MGD
See Also
References
- John R. McGinley, Jr., "McGinley Dynamics", MTA Journal (Market Technicians Association), Summer-Fall 1997, pp. 15-18. The original definition, with the fourth-power adjustment and the 60% rule for choosing N.