Category Trend  Published on 18/05/2023

Donchian Channel Colors

Description

This is a simple Donchian Channel that paints the candles with colors based on the trend and channel area.

 

You can find me by joyining this Telegram Group http://t.me/cTraderCoders

Grupo de Telegram Para Brasileiros, Portugueses e todos aqueles que falam portugues:http://t.me/ComunidadeCtrader

Grupo CTrader en Español para Latinos:  http://t.me/ComunidadCtrader

 

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Cloud("Upper Channel", "Middle Channel", FirstColor = "Green")]
    [Cloud("Middle Channel", "Bottom Channel", FirstColor = "Coral")]
    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
    public class DonchianChannelExperto : Indicator
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        [Output("Upper Channel", LineColor = "LawnGreen")]
        public IndicatorDataSeries DChannel_Upper { get; set; }
        
        [Output("Middle Channel", LineColor = "Gold")]
        public IndicatorDataSeries DChannel_Middle { get; set; }
        
        [Output("Bottom Channel", LineColor = "Coral")]
        public IndicatorDataSeries DChannel_Bottom { get; set; }
        
        public DonchianChannel DChannel;

        protected override void Initialize()
        {
            DChannel = Indicators.DonchianChannel(20);
        }

        public override void Calculate(int index)
        {
            DChannel_Upper[index] = DChannel.Top[index];
            
            DChannel_Middle[index] = DChannel.Middle[index];
            
            DChannel_Bottom[index] = DChannel.Bottom[index];
            
            if(Bars.ClosePrices[index] >= DChannel_Middle[index])
            {
                if(Bars.ClosePrices[index] >= Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.LawnGreen);
                else if(Bars.ClosePrices[index] < Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.YellowGreen); 
            }
            else if(Bars.ClosePrices[index] < DChannel_Middle[index])
            {
                if(Bars.ClosePrices[index] <= Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.Red);
                else if(Bars.ClosePrices[index] > Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.Coral);   
            
            }
            
        }
    }
}

TraderExperto's avatar
TraderExperto

Joined on 07.06.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Donchian Channel Experto.algo
  • Rating: 5
  • Installs: 1547
  • Modified: 25/10/2022 00:52
Comments
Log in to add a comment.
No comments found.