Description
This MACD Histogram with Colors indicator allows you to set colors for both positive and negative values of the Histogram.
Based on MACD Crossover with Colors from njardim.
// -------------------------------------------------------------------------------------------------
//
// This code is a cAlgo API MACD Crossover indicator provided by naoki.shinya@gmail.com on Dec 2015.
//
// Based on indicator "MACD Crossover with color" from njardim.
//
// -------------------------------------------------------------------------------------------------
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 MACDHistogramwithColors : 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("Histogram > 0", PlotType = PlotType.Histogram, Color = Colors.Green, Thickness = 2)]
public IndicatorDataSeries HistogramPositive { get; set; }
[Output("Histogram < 0", PlotType = PlotType.Histogram, Color = Colors.Red, Thickness = 2)]
public IndicatorDataSeries HistogramNegative { get; set; }
[Output("Signal", Color = Colors.Purple, LineStyle = LineStyle.Lines)]
public IndicatorDataSeries Signal { get; set; }
protected override void Initialize()
{
MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
}
public override void Calculate(int index)
{
if (MacdHistogram.Histogram[index] > 0)
{
HistogramPositive[index] = MacdHistogram.Histogram[index];
}
if (MacdHistogram.Histogram[index] < 0)
{
HistogramNegative[index] = MacdHistogram.Histogram[index];
}
Signal[index] = MacdHistogram.Signal[index];
}
}
}
BigDeal
Joined on 03.12.2015
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: MACD Histogram with Colors.algo
- Rating: 5
- Installs: 6030
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
thank you