Chart.RemoveObject not always working in Backtesting

Created at 05 Sep 2022, 10:44
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!
PR

prosteel1

Joined 04.07.2018

Chart.RemoveObject not always working in Backtesting
05 Sep 2022, 10:44


When Chart.RemoveObject is called in Backtesting mode the chart objects are not always removed. This used to work fine in an earlier version and can also be replicated in RealTime mode if it is left to run for long enough. Tested on Spotware version 4.3.11

The below example code draws a line from between previous candles OnBar and removes the previously drawn line.

The behaviour seems to be racing as different lines are not deleted each run.

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class DrawDeleteLines : Robot
    {
        [Parameter("Timeframe0", DefaultValue = "Minute")]
        public TimeFrame tf0 { get; set; }


        TimeFrame[] Frames = new TimeFrame[1];
        Bars[] series = new Bars[1];
        
        protected override void OnStart()
        {
            Chart.RemoveAllObjects();
            Frames[0] = tf0;
            series[0] = MarketData.GetBars(Frames[0]);
            
        }

        protected override void OnBar()
        {
            // Handle price updates here
            var line1 = Chart.DrawTrendLine(Frames[0] + "-" + (series[0].Count - 4) + "-" + (series[0].Count - 2), series[0].OpenTimes[(series[0].Count - 4)], series[0].LowPrices[(series[0].Count - 4)], series[0].OpenTimes[(series[0].Count - 2)], series[0].HighPrices[(series[0].Count - 2)], Color.Red);
            line1.IsInteractive = true;
            Chart.RemoveObject(Frames[0] + "-" + (series[0].Count - 5) + "-" + (series[0].Count - 3));
        }



        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

 


@prosteel1
Replies

jataraya
26 Oct 2022, 17:28

Same here


@jataraya

PanagiotisChar
27 Oct 2022, 09:21

Hi prosteel1,

I backtested this on 4.4.16 and there is no problem. Do you still experience this?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar