ver 3.8 Draw functions issue

Created at 12 Jun 2020, 13:03
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!
GE

gennimatas

Joined 19.09.2018

ver 3.8 Draw functions issue
12 Jun 2020, 13:03


Following snippet duplicates drawings when changing symbol or timeframe as shown in the attached image

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestDraw : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("O", LineColor = "Cyan", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries O { get; set; }

        [Output("H", LineColor = "Lime", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries H { get; set; }

        [Output("L", LineColor = "Tomato", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries L { get; set; }

        [Output("C", LineColor = "White", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries C { get; set; }


        public List<IndicatorDataSeries> Outs = new List<IndicatorDataSeries>();

        protected override void Initialize()
        {
            Outs.Add(O);
            Outs.Add(H);
            Outs.Add(L);
            Outs.Add(C);
        }

        public override void Calculate(int index)
        {
            O[index] = Bars.OpenPrices.LastValue;
            H[index] = Bars.HighPrices.LastValue;
            L[index] = Bars.LowPrices.LastValue;
            C[index] = Bars.ClosePrices.LastValue;

            string txt = "";
            if (IsLastBar)
            {
                for (int i = 0; i < Outs.Count; i++)
                {
                    DrawIcon(i);
                    txt += Outs[i].LastValue + "\n";
                }
                DrawText(txt);
            }
        }

        public void DrawIcon(int n)
        {
            ChartIconType it;
            Color ic;
            if (Outs[n].IsRising())
            {
                it = ChartIconType.UpArrow;
                ic = Color.Lime;
            }
            else if (Outs[n].IsFalling())
            {
                it = ChartIconType.DownArrow;
                ic = Color.Tomato;
            }
            else
            {
                it = ChartIconType.Circle;
                ic = Color.Yellow;
            }

            IndicatorArea.DrawIcon("icon" + n, it, Bars.Count + 1 + n, Outs[n].LastValue, ic);
        }

        public void DrawText(string txt)
        {
            double mid = (IndicatorArea.TopY + IndicatorArea.BottomY) / 2;
            VerticalAlignment va = Bars.MedianPrices.LastValue > mid ? VerticalAlignment.Bottom : VerticalAlignment.Top;

            IndicatorArea.DrawStaticText("statxt", txt, va, HorizontalAlignment.Right, Color.White);
        }

    }
}

 


@gennimatas
Replies

PanagiotisCharalampous
12 Jun 2020, 14:13

Hi Takis,

Thanks, we managed to reproduce this behavior and we will fix it.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

PanagiotisCharalampous
18 Jun 2020, 11:10

Hi Takis,

This should have been fixed in the latest hotfix.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Anka Software
08 Sep 2020, 00:13

RE:

PanagiotisCharalampous said:

Hi Takis,

This should have been fixed in the latest hotfix.

Best Regards,

Panagiotis 

Join us on Telegram

Hi,

    Problem is still present in the current version.

Regards

Vivek


@Anka Software

PanagiotisCharalampous
08 Sep 2020, 09:52

Hi Takis,

We cannot reproduce such a behavior. Can you please provide steps to reproduce?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

ctid976384
11 Sep 2020, 12:39 ( Updated at: 21 Dec 2023, 09:22 )

Not sure if this is the same issue, but I am experiencing the same behavior if an indicator is based on external data series and those external data series get recalculated. As an example, you can take the code below which draws a circle on each slope change of the source data series. Create a new chart with an Oscillator, let's take Stochastic as an example, then attach the custom indicator below and set the Stochastic %D as its source. Once set up, try to change %K Period and you will see that dots will remain from the prior result, although the custom indicator recalculates and prints new dots.

Note: By changing the Parameter in the indicator you can force the recalculation which will successfully remove old objects. Explicitly adding Chart.RemoveObject didn't fix the issue.

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleBug : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }

        [Parameter]
        public int Parameter { get; set; }

        public override void Calculate(int index)
        {
            if (index < 3 || Source[index] > Source[index - 1] == Source[index - 1] > Source[index - 2])
            {
                Chart.RemoveObject(index.ToString());
            }
            else
            {
                IndicatorArea.DrawIcon(index.ToString(), ChartIconType.Circle, index - 1, Source[index - 1], Color.Red);
            }
        }
    }
}


@ctid976384

PanagiotisCharalampous
18 Sep 2020, 11:50

Hi ctid976384,

You should use

IndicatorArea.RemoveObject(index.ToString());

instead

Chart.RemoveObject(index.ToString());

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous