Daily market Open Price Reference in cBot

jwandia2022 since: 30 Sep 2022;

  30 Sep 2022, 18:16
Daily market Open Price Reference in cBot

Hi All,

Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?

Joyce.

ctid3999979 since: 05 Jul 2021;

  01 Oct 2022, 10:53
RE:

jwandia2022 said:

Hi All,

Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?

Joyce.

If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as 

dailyBars = MarketData.GetBars("Daily");

protected override void OnBar()
        {

            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ExecuteMarketOrder()
            }
        }

jwandia2022 since: 30 Sep 2022;

  03 Oct 2022, 10:53
RE: RE:

ctid3999979 said:

jwandia2022 said:

Hi All,

Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?

Joyce.

If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as 

dailyBars = MarketData.GetBars("Daily");

protected override void OnBar()
        {

            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ExecuteMarketOrder()
            }
        }

Thanks. Will try working with this solution and see what happens.

jwandia2022 since: 30 Sep 2022;

  03 Oct 2022, 12:50
RE: RE:

ctid3999979 said:

jwandia2022 said:

Hi All,

Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?

Joyce.

If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as 

dailyBars = MarketData.GetBars("Daily");

protected override void OnBar()
        {

            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ExecuteMarketOrder()
            }
        }

Hi Again,

Which syntax should I use before "dailyBars = MarketData.GetBars("Daily")" to call the method?

jwandia2022 since: 30 Sep 2022;

  03 Oct 2022, 14:02
RE: RE: RE:

jwandia2022 said:

ctid3999979 said:

jwandia2022 said:

Hi All,

Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?

Joyce.

If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as 

dailyBars = MarketData.GetBars("Daily");

protected override void OnBar()
        {

            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ExecuteMarketOrder()
            }
        }

Hi Again,

Which syntax should I use before "dailyBars = MarketData.GetBars("Daily")" to call the method?

Below is a sample of the code

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.UTC, AccessRights = AccessRights.None)]
    public class New : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
            dailyBars = MarketData.GetBars("Daily");
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ///Execute Buy Trade
            }

            if (Bars.Last(0).Close < dailyBars.Last(0).Close)
            {
                ///Execute Sell Trade
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

ctid3999979 since: 05 Jul 2021;

  03 Oct 2022, 16:01
RE: RE: RE: RE:

jwandia2022 said:

jwandia2022 said:

ctid3999979 said:

jwandia2022 said:

Hi All,

Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?

Joyce.

If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as 

dailyBars = MarketData.GetBars("Daily");

protected override void OnBar()
        {

            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ExecuteMarketOrder()
            }
        }

Hi Again,

Which syntax should I use before "dailyBars = MarketData.GetBars("Daily")" to call the method?

Below is a sample of the code

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.UTC, AccessRights = AccessRights.None)]
    public class New : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
            dailyBars = MarketData.GetBars("Daily");
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ///Execute Buy Trade
            }

            if (Bars.Last(0).Close < dailyBars.Last(0).Close)
            {
                ///Execute Sell Trade
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

You forgot to declare the variable for the dailyBars. Above the OnStart() method you just need private Bars dailyBars;

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.UTC, AccessRights = AccessRights.None)]
    public class New : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private Bars dailyBars;

        protected override void OnStart()
        {
            // Put your initialization logic here
            dailyBars = MarketData.GetBars("Daily");
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ///Execute Buy Trade
            }

            if (Bars.Last(0).Close < dailyBars.Last(0).Close)
            {
                ///Execute Sell Trade
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

jwandia2022 since: 30 Sep 2022;

  05 Oct 2022, 10:16
RE: RE: RE: RE: RE:

Thanks. I had not noticed that beforehand.

jwandia2022 since: 30 Sep 2022;

  05 Oct 2022, 11:44
RE: RE: RE: RE: RE:

You forgot to declare the variable for the dailyBars. Above the OnStart() method you just need private Bars dailyBars;

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.UTC, AccessRights = AccessRights.None)]
    public class New : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private Bars dailyBars;

        protected override void OnStart()
        {
            // Put your initialization logic here
            dailyBars = MarketData.GetBars("Daily");
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {
            // Put your core logic here
            if (Bars.Last(0).Close > dailyBars.Last(0).Close)
            {
                ///Execute Buy Trade
            }

            if (Bars.Last(0).Close < dailyBars.Last(0).Close)
            {
                ///Execute Sell Trade
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

I'm still not able to get the sample code above to build on CTrader. Error messages:

Kindly assist.

Joyce.