Category Trend  Published on 18/12/2019

MACD Histogram with Color m

Description

This MACD Histogram with Colors indicator allows you to set colors for both positive and negative and Growing and Falling values of the Histogram and Signal.

 


// -------------------------------------------------------------------------------------------------
//    Based on indicator "MACD Histogram with Color"
// -------------------------------------------------------------------------------------------------

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

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

        public MacdHistogram MacdHistogram;

        [Parameter()]

        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        [Parameter("Signal Periods", DefaultValue = 9)]
        public int Periods { get; set; }


        [Output("Growing > 0", PlotType = PlotType.Histogram, LineColor = "SpringGreen", Thickness = 1)]
        public IndicatorDataSeries GrowingPositive { get; set; }
        [Output("Growing < 0", PlotType = PlotType.Histogram, LineColor = "ForestGreen", Thickness = 1)]
        public IndicatorDataSeries GrowingNegative { get; set; }


        [Output("Falling > 0", PlotType = PlotType.Histogram, LineColor = "Crimson", Thickness = 1)]
        public IndicatorDataSeries FallingPositive { get; set; }
        [Output("Falling < 0", PlotType = PlotType.Histogram, LineColor = "Tomato", Thickness = 1)]
        public IndicatorDataSeries FallingNegative { get; set; }

        [Output("SignalGrowing", LineColor = "LightBlue", PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries SignalGrowing { get; set; }

        [Output("SignalFalling", LineColor = "Purple", PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries SignalFalling { get; set; }

        protected override void Initialize()
        {

            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
        }

        public override void Calculate(int index)
        {
            if (MacdHistogram.Histogram[index - 1] < MacdHistogram.Histogram[index])
            {
                if (MacdHistogram.Histogram[index] > 0)
                    GrowingPositive[index] = MacdHistogram.Histogram[index];
                else
                    GrowingNegative[index] = MacdHistogram.Histogram[index];
            }
            else if (MacdHistogram.Histogram[index - 1] > MacdHistogram.Histogram[index])
            {
                if (MacdHistogram.Histogram[index] > 0)
                    FallingPositive[index] = MacdHistogram.Histogram[index];
                else
                    FallingNegative[index] = MacdHistogram.Histogram[index];
            }

            if (MacdHistogram.Signal[index - 1] < MacdHistogram.Signal[index])
            {
                SignalGrowing[index] = MacdHistogram.Signal[index];
                if (MacdHistogram.Signal[index - 2] > MacdHistogram.Signal[index - 1])
                    SignalFalling[index] = MacdHistogram.Signal[index];
            }

            else if (MacdHistogram.Signal[index - 1] > MacdHistogram.Signal[index])
            {
                SignalFalling[index] = MacdHistogram.Signal[index];
                if (MacdHistogram.Signal[index - 2] < MacdHistogram.Signal[index - 1])
                    SignalGrowing[index] = MacdHistogram.Signal[index];
            }
        }
    }
}


VI
Vitali Gajdabrus

Joined on 20.08.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: MACDcolorM.algo
  • Rating: 5
  • Installs: 1931
Comments
Log in to add a comment.
VA
valeretrader · 1 month ago

tres bon indicateur. il manque juste de rajouté les alerts.

il faut ajouté l'alerte quand l'histogram passe au dessus et en dessous de la ligne 0

il faut aussi ajouté l'alerte de la ligne signal MACD