Coloring bars

Created at 12 Mar 2016, 00:18
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!

Coloring bars
12 Mar 2016, 00:18


Hi All!

Can I change color of bars?

like in Alex Elder impulse system.

 


@Максим_Коваленко
Replies

croucrou
12 Mar 2016, 19:24

RE:

You can do this like this:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        private double open, close, high, low;

        private Colors color;

        public override void Calculate(int index)
        {
            open = MarketSeries.Open[index];
            high = MarketSeries.High[index];
            low = MarketSeries.Low[index];
            close = MarketSeries.Close[index];

            if (close > open)
            {
                color = Colors.Yellow; // your UpColor here
                ChartObjects.DrawLine("candle" + index, index, open, index, close, color, 5, LineStyle.Solid);
                ChartObjects.DrawLine("wick" + index, index, high, index, low, color, 1, LineStyle.Solid);
            }

            if (close < open)
            {
                color = Colors.Blue; // your DownColor here
                ChartObjects.DrawLine("candle" + index, index, open, index, close, color, 5, LineStyle.Solid);
                ChartObjects.DrawLine("wick" + index, index, high, index, low, color, 1, LineStyle.Solid);
            }
        }
    }
}

 


@croucrou

Максим_Коваленко
13 Mar 2016, 21:24

Here is complete indicator Elders impulse system:

 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace ImpulseSystem
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ImpulseSystem : Indicator
    {
        private MovingAverage ema;

        private MacdCrossOver macdCrossOver;

        /// <summary>
        /// Период скользящей средней
        /// </summary>
        [Parameter(DefaultValue = 13)]
        public int EmaPeriod { get; set; }

        /// <summary>
        /// Главный индикатор EMA
        /// </summary>
        [Output("EMA")]
        public IndicatorDataSeries Ema { get; set; }

        public override void Calculate(int index)
        {
            this.Ema[index] = this.ema.Result[index];

            if (this.ema.Result.IsRising() && this.macdCrossOver.Histogram.IsRising())
            {
                this.DrawBar(index, Colors.Green);
            }
            else if (this.ema.Result.IsFalling() && this.macdCrossOver.Histogram.IsFalling())
            {
                this.DrawBar(index, Colors.Red);
            }
            else
            {
                this.DrawBar(index, Colors.Aqua);
            }
        }

        /// <inheritdoc />
        protected override void Initialize()
        {
            this.ema = Indicators.MovingAverage(this.MarketSeries.Close, this.EmaPeriod, MovingAverageType.Exponential);
            this.macdCrossOver = Indicators.MacdCrossOver(this.MarketSeries.Close, 26, 12, 9);
        }

        private void DrawBar(int index, Colors color)
        {
            this.ChartObjects.DrawLine("candle" + index, index, MarketSeries.Open[index], index, MarketSeries.Close[index], color, 5);
            this.ChartObjects.DrawLine("wick" + index, index, MarketSeries.High[index], index, MarketSeries.Low[index], color);
        }
    }
}

 


@Максим_Коваленко

... Deleted by UFO ...

... Deleted by UFO ...