Category Trend  Published on 22/06/2023

McGinley Dynamic

Description

McGinley Dynamic Indicator Definition (investopedia.com)

McGinley Dynamic is moving average that seeks to adapt to different market conditions, depending on if it's ranged, trending up or down it will adjust accordingly.
Better to be used on Daily Timeframes or above.

Buy Waxy a Coffee. ko-fi.com/waxycodes - Ko-fi ❤️ Where creators get support from fans through donations, memberships, shop sales and more! The original 'Buy Me a Coffee' Page.


//Formula for McGinley Dynamic can be found here
//https://www.investopedia.com/terms/m/mcginley-dynamic.asp

//You can support/contact me via Ko-Fi
//https://ko-fi.com/waxycodes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo;

[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class McGinleyDynamic : Indicator
{
    [Parameter("Source")] 
    public DataSeries InputSource { get; set; }

    [Parameter("Length", DefaultValue = 10)] 
    public int InputLength { get; set; }

    [Parameter("Constant", DefaultValue = 1, MinValue = 0.01)]
    public double InputConstant { get; set; }
    
    [Output("Main", LineColor = "FF00FFFF", Thickness = 2)]
    public IndicatorDataSeries Result { get; set; }

    private ExponentialMovingAverage _ema;

    protected override void Initialize()
    {
        _ema = Indicators.ExponentialMovingAverage(InputSource, InputLength);
    }

    public override void Calculate(int index)
    {
        var previous = double.IsNaN(Result[index - 1]) ? _ema.Result[index - 1] : Result[index - 1];
        
        Result[index] = previous + (InputSource[index] - previous) / (InputConstant * InputLength * Math.Pow(InputSource[index] / previous, 4));
    }
}

Waxy's avatar
Waxy

Joined on 12.05.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: McGinley Dynamic.algo
  • Rating: 0
  • Installs: 642
  • Modified: 22/06/2023 17:36
Comments
Log in to add a comment.
No comments found.