Drawing lines with Cbot (not indicator) in backtest

Created at 07 Apr 2022, 08:32
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!
MA

Drawing lines with Cbot (not indicator) in backtest
07 Apr 2022, 08:32


There are many questions about this from 5+ years ago, The answer then was that backtesting does NOT show lines drawn using:

Chart.DrawHorizontalLine("OK", 1.6, Color.Red);

Even in Visual mode.

 

Is this still true?
I am running backtests, and this line is never drawn for me. I can never see it. i can see the backtest playing out in visual mode. I can see my algo running, and print statements appearing in the logs.. But I cannot see a red line through the 1.6 price point.


@manoj.clsd.kumar@gmail.com
Replies

amusleh
07 Apr 2022, 09:16 ( Updated at: 21 Dec 2023, 09:22 )

Hi,

The Chart drawings are working fine in Visual back test mode, ex:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestDrawing : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Price { get; set; }

        protected override void OnStart()
        {
            var line = Chart.DrawHorizontalLine("1", Price, Color.Red);
            
            line.IsInteractive = true;
        }
    }
}

Result:

If you set the IsInteractive property of a chart object to True then it will remain on chart even if back test stop, otherwise the objects will be removed from the chart on back test stop.

In non visual mode the chart drawings will not show up.


@amusleh

manoj.clsd.kumar@gmail.com
07 Apr 2022, 09:28

Ah I'm not sure what I'm doing wrong, but your example is working for me too!

 

Thnaks.


@manoj.clsd.kumar@gmail.com