More than 1 coded instance of a chart type in an indicator fails to show

Created at 25 Mar 2022, 20:26
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!
BD

bdfx

Joined 22.09.2016

More than 1 coded instance of a chart type in an indicator fails to show
25 Mar 2022, 20:26


I want to use two chart.Draw types , a rectangle and a trend line together within an indicator. Either the rectangle is visible or the line, but not both.

Here's a simple test indicator. Is there something wrong with the code or is it an issue?

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 Test : Indicator
    {

        [Parameter("Show Rectangle", DefaultValue = false)]
        public bool Rectangle { get; set; }

        [Parameter("Show Line", DefaultValue = false)]
        public bool Line { get; set; }


        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public double y1 { get; set; }
        public double y2 { get; set; }
        public double y3 { get; set; }


        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {
            y1 = this.Bars[Bars.Count - 3].High;
            y2 = this.Bars[Bars.Count - 1].Low;
            y3 = Math.Round((y1 + y2) / 2, Symbol.Digits);

            Start = this.Bars[Bars.Count - 3].OpenTime;
            End = this.Bars[Bars.Count - 1].OpenTime;

            if (RunningMode != RunningMode.Optimization)
            {
                for (int i = 1; i <= 5; i++)
                {
                    if (Rectangle == true)
                    {
                        string rec = i.ToString();
                        Chart.DrawRectangle(rec, Start, y1, End, y2, Color.Yellow, 2, LineStyle.Solid);
                    }

                    if (Line == true)
                    {
                        string lin = i.ToString();
                        Chart.DrawTrendLine(lin, Start, y3, End, y3, Color.Yellow, 2, LineStyle.Solid);
                    }
                }
            }
        }
    }
}

 


@bdfx
Replies

bdfx
25 Mar 2022, 20:41

My bad. The string values aren't unique!


@bdfx