Moving Averages plotting a "straight line"?

Created at 05 Oct 2020, 03:10
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!
AR

arthur.albert990

Joined 23.09.2020

Moving Averages plotting a "straight line"?
05 Oct 2020, 03:10


Hello everyone, I'm trying to create a moving average that changes color if EMA1 < EMA2 but when condition is false the the other EMA color is plotted as a straight line, there is a way to remove the straight part?

Picture below.


@arthur.albert990
Replies

arthur.albert990
05 Oct 2020, 03:13

RE: Code below.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;


namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class EMACL : Indicator
    {

        [Parameter(DefaultValue = 9)]
        public int Period1 { get; set; }

        [Parameter(DefaultValue = 30)]
        public int Period2 { get; set; }

        [Parameter("Moving Average Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries Source { get; set; }

        [Output("Média Verde", LineColor = "Green", LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("Média Vermelha", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries Result2 { get; set; }

        private MovingAverage _MovingAverage1;
        private MovingAverage _MovingAverage2;

        protected override void Initialize()
        {
            _MovingAverage1 = Indicators.MovingAverage(Source, Period1, MAType);
            _MovingAverage2 = Indicators.MovingAverage(Source, Period2, MAType);
        }

        public override void Calculate(int index)
        {

            if (_MovingAverage1.Result[index] < _MovingAverage2.Result[index])
            {
                Result2[index] = _MovingAverage2.Result[index];
            }
            else
                Result1[index] = _MovingAverage2.Result[index];

        }
    }
}

 


@arthur.albert990

PanagiotisCharalampous
05 Oct 2020, 08:45

Hi arthur.albert990,

You need to use a DiscontinuousLine plot type.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

arthur.albert990
16 Oct 2020, 14:36

RE:

Hello PanagiotisCharalampous,

Thank you for your help, it worked great.!


@arthur.albert990