Category Trend  Published on 01/03/2020

McGinley Dynamic Indicator

Description

Developer notes:

Default settings are a period of 20 and k of 0.6

I thought about using it as a slow baseline, and gathering signals from crossings between it and a fast baseline. The fast baseline could be either this indicator with a faster period, or another line of your choice (ichimoku, zlema, time series MA, etc.);

If you find good results, I'd really enjoy if you share'em with me.

----

Description copied from investopedia.com:

The McGinley Dynamic indicator is a type of moving average that was designed to track the market better than existing moving average indicators. It is a technical indicator that improves upon moving average lines by adjusting for shifts in market speed. Invented by John R. McGinley.

 

The McGinley Dynamic looks like a moving average line, yet it is actually a smoothing mechanism for prices that turns out to track far better than any moving average. It minimizes price separation, price whipsaws, and hugs prices much more closely. And it does this automatically as a factor of its formula.

Because of the calculation, the Dynamic Line speeds up in down markets as it follows prices yet moves more slowly in up markets. One wants to be quick to sell in a down market, yet ride an up market as long as possible. The constant N determines how closely the Dynamic tracks the index or stock. If one is emulating a 20-day moving average, for instance, use an N value half that of the moving average, or in this case 10.

It greatly avoids whipsaws because the Dynamic Line automatically follows and stays aligned to prices in any market—fast or slow—like a steering mechanism of a car that can adjust to the changing conditions of the road. Traders can rely on it to make decisions and time entrances and exits.

----

 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class dynamicMa : Indicator
    {

        //   [Parameter("Source")]
        //   public DataSeries Source { get; set; }
        [Parameter("Period", DefaultValue = 20)]
        public int Period { get; set; }
        [Parameter("K", DefaultValue = 0.6, MinValue = 0.1, MaxValue = 2)]
        public double k { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        public override void Calculate(int index)
        {
            Result[index] = double.IsNaN(Result[index - 1]) ? Bars.ClosePrices[index] : Result[index - 1] + ((Bars.ClosePrices[index] - Result[index - 1]) / (Period * k * (Math.Pow(Bars.ClosePrices[index] / Result[index - 1], 4))));
            //  Result[index] = double.IsNaN(Result[index - 1]) ? Source[index] : Result[index - 1] + ((Source[index] - Result[index - 1]) / (Period * k * (Math.Pow(Source[index] / Result[index - 1], 4))));
        }
    }
}


lorenzopvella's avatar
lorenzopvella

Joined on 22.08.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: McGinley Dynamic Indicator.algo
  • Rating: 0
  • Installs: 1835
Comments
Log in to add a comment.
BA
BartNL · 2 years ago

This is what I found in the MT McGinley Dynamic source code:

   mcg[i]   = ma[i+1]+(price-ma[i+1])/(McgConstant*McgPeriod*MathPow(price/ma[i+1],4));

Where ma = the moving average over selected price (default Close)
mcg = the computed output
The indices are in reverse order: higher indices go back in time.

Note that the MT version is not McGinley at all, not even McGinley computed over a moving average, because the term mcg[i+1] is missing on the right side.

BA
BartNL · 2 years ago

The description of the MetaTrader version https://stonehillforex.com/2022/01/mcginley-dynamic-indicator-as-a-baseline-indicator/

BA
BartNL · 2 years ago

The metatrader version of the McGinley Dynamic indicator includes a moving average of selectable type and a "constant" parameter that seems to blend the actual McGinley with the moving average (SMA, EMA,Weighted, etc)

Does anyone have an idea what the MetaTrader version is doing so I can reproduce it exactly on cTrader?