MACD Histogram with Color m free

by Vitali Gajdabrus in category Trend at 18/12/2019
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.

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
// -------------------------------------------------------------------------------------------------
//    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];
            }
        }
    }
}
Comments
0