Hold trendlines after restart bot

Created at 22 Dec 2022, 23:09
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!
R.

r.stipriaan

Joined 05.02.2021

Hold trendlines after restart bot
22 Dec 2022, 23:09


Hi, does anyone know if it is possible to keep chart drawings after restarting a bot?

When I start a bot it automatically draws a trendline right through the chrart until it gets drawn. if I stop the bot and start it again, the trendlines disappear and they are all across the chart again.

this problem does not happen in backtest.

Thank you in advance!

 

For example:



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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.WEuropeStandardTime, AccessRights = AccessRights.None)]
    public class RS : Robot
    {


        private ChartTrendLine _trendLine1;


        protected override void OnStart()
        {

            
         _trendLine1 = Chart.DrawTrendLine("High1", Chart.FirstVisibleBarIndex, Chart.BottomY, Chart.LastVisibleBarIndex, Chart.TopY, Color.Red);

                                 
        }

        protected override void OnBar()
        {
        }


        protected override void OnTick()
        {
         
            _trendLine1.IsInteractive = true;
                   
            
            if (Bars.Last(0).High > Bars.Last(1).High & Bars.Last(1).High > Bars.Last(2).High )

            {
                DateTime x2 = Bars.Last(0).OpenTime;
                DateTime x1 = Bars.Last(10).OpenTime;
                double y1 = Bars.Last(0).High;
                double y2 = Bars.Last(0).High;

                Chart.DrawTrendLine("High1", x1, y1, x2, y2, Color.Red);
                

                
             }
            
        }
    }
}





 


@r.stipriaan
Replies

PanagiotisChar
23 Dec 2022, 09:48

Hi there,

You need to make the line interactive

            _trendLine1 = Chart.DrawTrendLine("High1", Chart.FirstVisibleBarIndex, Chart.BottomY, Chart.LastVisibleBarIndex, Chart.TopY, Color.Red);
            _trendLine1.IsInteractive = true;

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

r.stipriaan
23 Dec 2022, 10:35

i made it interactive as you can see in the code above, line stays when the bot stops but not when it starts again.


@r.stipriaan