Line Drawing Indicator

Created at 07 Feb 2021, 20:05
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!
JA

jackhpfilerrowson

Joined 26.11.2020

Line Drawing Indicator
07 Feb 2021, 20:05


Hi, can someone help me with this indicator. Its not drawing lines on the chart.

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class AverageLineforRanging : Indicator
    {

        private Fractals Frac;
        private double Top;
        private double Bottom;

        protected override void Initialize()
        {
            Frac = Indicators.Fractals(5);
        }

        public override void Calculate(int index)
        {
            if (index == 0)
                Displaylineonchart();

        }
        private void Displaylineonchart()
        {

            Top = ((Frac.UpFractal.Last(1) + Frac.UpFractal.Last(2) + Frac.UpFractal.Last(3) + Frac.UpFractal.Last(4)) / 4);

            Bottom = ((Frac.DownFractal.Last(1) + Frac.DownFractal.Last(2) + Frac.DownFractal.Last(3) + Frac.DownFractal.Last(4)) / 4);

            Chart.DrawHorizontalLine("Top", Top, Color.AliceBlue, 5, LineStyle.Solid);
            Chart.DrawHorizontalLine("Bottom", Bottom, Color.AliceBlue, 5, LineStyle.Solid);
        }
    }
}


@jackhpfilerrowson
Replies

PanagiotisCharalampous
08 Feb 2021, 08:38

Hi jackhpfilerrowson,

Where do you expect the lines to be drawn? You are trying to draw the lines at index 0 when all the indicator values are NaN.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous