Description
This is a Classic MACD with multiple Colors for a better Visualization.
Any Bug Please Report.
09/July/2022 The indicator got a update, to correct some errors in the output in the histogram.
11/July/2022 Another update was done to correct an error in the output.
Esto es un clásico indicador MACD con colores para una visualización mejor.
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 -->> http://t.me/ComunidadCtrader
Grupo CTrader em Português -->> http://t.me/ComunidadeCtrader
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Cloud("MACD", "Signal", Opacity = 0.2, FirstColor = "FF7CFC00")]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class MACDMultiColorsCandles : Indicator
{
public enum PaintingOptions
{
CrossOver,
CrossOverLine,
Histogram
}
[Output("Bull Up", PlotType = PlotType.Histogram, LineColor = "ForestGreen", Thickness = 4)]
public IndicatorDataSeries StrongBullish { get; set; }
[Output("Bull Down", PlotType = PlotType.Histogram, LineColor = "LawnGreen", Thickness = 4)]
public IndicatorDataSeries WeakBulish { get; set; }
[Output("Bear Down", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 4)]
public IndicatorDataSeries StrongBearish { get; set; }
[Output("Bear Up", 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("Fast Period", DefaultValue = 12)]
public int periodFast { get; set; }
[Parameter("Slow Period", DefaultValue = 26)]
public int periodSlow { get; set; }
[Parameter("Signal Period", DefaultValue = 9)]
public int periodSignal { get; set; }
[Parameter("Paint Options", DefaultValue = PaintingOptions.CrossOver)]
public PaintingOptions Option { get; set; }
private ExponentialMovingAverage emaSlow;
private ExponentialMovingAverage emaFast;
private ExponentialMovingAverage emaSignal;
private IndicatorDataSeries closePrice;
private IndicatorDataSeries macd;
protected override void Initialize()
{
closePrice = CreateDataSeries();
macd = CreateDataSeries();
emaSlow = Indicators.ExponentialMovingAverage(closePrice, periodSlow);
emaFast = Indicators.ExponentialMovingAverage(closePrice, periodFast);
emaSignal = Indicators.ExponentialMovingAverage(macd, periodSignal);
}
public override void Calculate(int index)
{
closePrice[index] = Bars.ClosePrices[index];
double prevMACD = emaFast.Result[index - 1] - emaSlow.Result[index - 1];
double currentMACD = emaFast.Result[index] - emaSlow.Result[index];
MACD[index] = emaFast.Result[index] - emaSlow.Result[index];
macd[index] = MACD[index];
Signal[index] = emaSignal.Result[index];
double signalValue = emaSignal.Result[index];
double Histogram = MACD[index] - emaSignal.Result[index];
double prevHistogram = MACD[index - 1] - emaSignal.Result[index - 1];
if (Histogram > 0.0)
{
if (prevHistogram >= Histogram)
{
WeakBulish[index] = MACD[index] - emaSignal.Result[index];
StrongBullish[index] = 0;
WeakBearish[index] = 0;
StrongBearish[index] = 0;
}
else
{
StrongBullish[index] = MACD[index] - emaSignal.Result[index];
WeakBulish[index] = 0;
WeakBearish[index] = 0;
StrongBearish[index] = 0;
}
}
else if (Histogram < 0.0)
{
if (Histogram <= prevHistogram)
{
StrongBearish[index] = MACD[index] - emaSignal.Result[index];
WeakBearish[index] = 0;
StrongBullish[index] = 0;
WeakBulish[index] = 0;
}
else
{
WeakBearish[index] = MACD[index] - emaSignal.Result[index];
StrongBearish[index] = 0;
StrongBullish[index] = 0;
WeakBulish[index] = 0;
}
}
}
}
}
TraderExperto
Joined on 07.06.2019
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: MACD Multi Colors.algo
- Rating: 0
- Installs: 4090
- Modified: 11/07/2022 15:42
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.
marcelo.l.u Tudo Certo pode baixar agora!
MA
Olá
, existe uma forma de aplicar nesse indicador MACD um sinal de aviso quando o Histograma apresentar coloração diferente? Exemplo, o histograma começa a ficar verde, logo depois ele apresenta um verde claro, assim que o candle fechar e essa barra do histograma ficar verde claro que ele possa emitir um sinal de aviso. Obrigado !
Hi, I received this error message: .NET 4 algo files are not supported by cTrader Mac.
Would you please help me with that?