Category Trend  Published on 11/07/2022

MACD ZeroLag

Description

This is my MACD Zero Lag with a much faster signal. This Indicator uses the Double EMA instead of a traditional EMA for the Signals.

You can take a look at the difference by comparing it with my other Classic MACD Multicolors. Example in the picture Bellow.

 

09/July/2022 The Indicator was updated, applying a correction on the histogram to prevent, to paint two different colors.

 

11/Jully/2022 Another little update was done to correct the output.

 

Grupo CTrader em Portugues -->>  https://t.me/ComunidadeCtrader

Para los que quieran participar de un Grupo CTrader en Español poder compartir estrategias, indicadores e mucho más, aquí abajo les dejo el link.

Grupo CTrader en Español -->> https://t.me/ComunidadCtrader

 



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

namespace cAlgo.Indicators
{
    [Cloud("MACD", "Signal", Opacity = 0.2, FirstColor = "FF7CFC00")]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MACDZeroLag : Indicator
    {

        [Output("Up Bullish", PlotType = PlotType.Histogram, LineColor = "ForestGreen", Thickness = 4)]
        public IndicatorDataSeries StrongBullish { get; set; }

        [Output("Down Bullish", PlotType = PlotType.Histogram, LineColor = "LawnGreen", Thickness = 4)]
        public IndicatorDataSeries WeakBullish { get; set; }

        [Output("Down Bearish", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 4)]
        public IndicatorDataSeries StrongBearish { get; set; }

        [Output("Up Bearish", PlotType = PlotType.Histogram, LineColor = "DarkSalmon", Thickness = 4)]
        public IndicatorDataSeries WeakBearish { get; set; }

        [Output("MACD", LineColor = "DodgerBlue", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries MACD { get; set; }

        [Output("Signal", LineColor = "Red", LineStyle = LineStyle.Lines, Thickness = 1)]
        public IndicatorDataSeries Signal { get; set; }

        [Parameter(DefaultValue = 12)]
        public int periodFast { get; set; }

        [Parameter(DefaultValue = 26)]
        public int periodSlow { get; set; }

        [Parameter(DefaultValue = 9)]
        public int periodSignal { get; set; }

        private ExponentialMovingAverage emaSlow;
        private ExponentialMovingAverage emaSlow2;
        private ExponentialMovingAverage emaFast;
        private ExponentialMovingAverage emaFast2;
        private ExponentialMovingAverage emaSignal;
        private ExponentialMovingAverage emaSignal2;
        private IndicatorDataSeries closePrice;
        private IndicatorDataSeries macd;


        protected override void Initialize()
        {
            closePrice = CreateDataSeries();
            macd = CreateDataSeries();
            emaSlow = Indicators.ExponentialMovingAverage(closePrice, periodSlow);
            emaSlow2 = Indicators.ExponentialMovingAverage(emaSlow.Result, periodSlow);
            emaFast = Indicators.ExponentialMovingAverage(closePrice, periodFast);
            emaFast2 = Indicators.ExponentialMovingAverage(emaFast.Result, periodFast);
            emaSignal = Indicators.ExponentialMovingAverage(macd, periodSignal);
            emaSignal2 = Indicators.ExponentialMovingAverage(emaSignal.Result, periodSignal);
        }

        public override void Calculate(int index)
        {
            closePrice[index] = Bars.ClosePrices[index];
            MACD[index] = (2 * emaFast.Result[index] - emaFast2.Result[index]) - (2 * emaSlow.Result[index] - emaSlow2.Result[index]);
            macd[index] = MACD[index];
            Signal[index] = (2 * emaSignal.Result[index] - emaSignal2.Result[index]);
            double HistogramValue = MACD[index] - emaSignal.Result[index];
            double prevHistogramValue = MACD[index - 1] - emaSignal.Result[index - 1];

            if (HistogramValue > 0.0)
            {
                if (prevHistogramValue >= HistogramValue)
                {
                    WeakBullish[index] = HistogramValue;
                    StrongBullish[index] = 0;
                    WeakBearish[index] = 0;
                    StrongBearish[index] = 0;
                }
                else
                {
                    StrongBullish[index] = HistogramValue;
                    WeakBullish[index] = 0;
                    WeakBearish[index] = 0;
                    StrongBearish[index] = 0;
                }
            }
            else if (HistogramValue < 0.0)
            {
                if (HistogramValue <= prevHistogramValue)
                {
                    StrongBearish[index] = HistogramValue;
                    WeakBearish[index] = 0;
                    StrongBullish[index] = 0;
                    WeakBullish[index] = 0;
                }
                else
                {
                    WeakBearish[index] = HistogramValue;
                    StrongBearish[index] = 0;
                    StrongBullish[index] = 0;
                    WeakBullish[index] = 0;
                }
            }
        }
    }
}



TraderExperto's avatar
TraderExperto

Joined on 07.06.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: MACD Zero Lag.algo
  • Rating: 5
  • Installs: 3220
  • Modified: 11/07/2022 15:41
Comments
Log in to add a comment.
KE
kenneyy_eur · 2 years ago

Hello,

I'm trying to improve this great indicator you released on here. I keep running into a brick wall

My aim is to add this indicator (for a higher timeframe) onto the current chart (M5).

I want to use it as a Divergence indicator. I have seen the other two you uploaded and have altered those ones, but this seems more promising.

Please help.

SO
sounsaleem97 · 3 years ago

Hello, 

can I get your email for Enquires about this Indicator please.

Thanks