cBot Draw an Icon and let it stay after cBot stop?

Created at 27 Jan 2022, 23:31
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!
Capt.Z-Fort.Builder's avatar

Capt.Z-Fort.Builder

Joined 03.06.2020

cBot Draw an Icon and let it stay after cBot stop?
27 Jan 2022, 23:31


Hi Support Team,

I have below code to draw an up arrow below the last bar lowest price. But it only exists when the Bot is running. Is there any way that I can let the UpArrow stay even the cBot stopped?

Thanks,

L

using cAlgo.API;

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

        protected override void OnStart()
        {
            string sMessage = "Long " + Bars.LastBar.OpenTime;
            Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));
        }

        protected override void OnTick() {}

        protected override void OnStop() {}
    }
}

 


@Capt.Z-Fort.Builder
Replies

amusleh
28 Jan 2022, 08:27

Hi,

You can set the object IsInteractive flag to True:

using cAlgo.API;

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

        protected override void OnStart()
        {
            string sMessage = "Long " + Bars.LastBar.OpenTime;
            var icon = Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));

            icon.IsInteractive = true;
            icon.IsLocked = true;
        }

        protected override void OnTick() {}

        protected override void OnStop() {}
    }
}

The IsLocked is an additional optional step which disables moving of object, but you can turn it on/off from object settings.


@amusleh

Capt.Z-Fort.Builder
28 Jan 2022, 14:08 ( Updated at: 28 Jan 2022, 16:16 )

RE:

Hi Musleh,

I've just tested the code, there are some error information when compiling. 

L

amusleh said:

Hi,

You can set the object IsInteractive flag to True:

using cAlgo.API;

namespace cAlgo.Robots
{
...    
}

The IsLocked is an additional optional step which disables moving of object, but you can turn it on/off from object settings.

 


@Capt.Z-Fort.Builder

Capt.Z-Fort.Builder
28 Jan 2022, 14:22

RE:

Hi Musleh,

I've just tested the code. Please advise.

 

amusleh said:

Hi,

You can set the object IsInteractive flag to True:

using cAlgo.API;

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

        protected override void OnStart()
        {
            string sMessage = "Long " + Bars.LastBar.OpenTime;
            var icon = Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));

            icon.IsInteractive = true;
            icon.IsLocked = true;
        }

        protected override void OnTick() {}

        protected override void OnStop() {}
    }
}

The IsLocked is an additional optional step which disables moving of object, but you can turn it on/off from object settings.

 


@Capt.Z-Fort.Builder

amusleh
31 Jan 2022, 08:04 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

TheNiatpac said:

Hi Musleh,

I've just tested the code. Please advise.

 

Hi,

There is no such issue on my posted code, most probably you made some changes on it, the error says that the variable "icon" does not exist.

 


@amusleh

Capt.Z-Fort.Builder
31 Jan 2022, 12:22 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

Hi Musleh,

Thanks for the reply. I found the problem. 

            var icon = Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));

I should define the icon first. So that we can set the properties for it.  

Much appreciated.

L

amusleh said:

TheNiatpac said:

Hi Musleh,

I've just tested the code. Please advise.

 

Hi,

There is no such issue on my posted code, most probably you made some changes on it, the error says that the variable "icon" does not exist.

 

 


@Capt.Z-Fort.Builder

mpaggini
05 Sep 2022, 09:57

RE:

amusleh said:

Hi,

You can set the object IsInteractive flag to True:

using cAlgo.API;

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

        protected override void OnStart()
        {
            string sMessage = "Long " + Bars.LastBar.OpenTime;
            var icon = Chart.DrawIcon(sMessage, ChartIconType.UpArrow, Bars.LastBar.OpenTime, Bars.LastBar.Low * 0.999, Color.FromHex("#DDE7E7E7"));

            icon.IsInteractive = true;
            icon.IsLocked = true;
        }

        protected override void OnTick() {}

        protected override void OnStop() {}
    }
}

The IsLocked is an additional optional step which disables moving of object, but you can turn it on/off from object settings.

This not work for me, when bot stop all drawed object disappar, also in backtest


@mpaggini