i keep trying

Created at 18 Aug 2020, 20:57
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!
SA

samuel.jus.cornelio

Joined 19.03.2020

i keep trying
18 Aug 2020, 20:57


Hello, I'm trying to create a code to start trading at a specific time. But I'm not succeeding

follow the example below

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 bot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

  [Parameter("Begin Trading Hour", DefaultValue = 6)]
        public int Begin { get; set; }

        [Parameter("Ending Trading Hour", DefaultValue = 18)]
        public int Ending { get; set; }

   private DateTime startTime;
        private DateTime endTime;

    protected override void OnTick()
        {
 

 startTime = Server.Time.Date.AddHours(Begin);
                endTime = Server.Time.Date.AddHours(Ending);

                if (Trade.IsExecuting)
                    return;

                bool tradeTime = false;
                if (Begin < Ending)
                    tradeTime = Server.Time.Hour >= Begin && Server.Time.Hour < Ending;
                if (Ending < Begin)
                    tradeTime = Server.Time.Hour >= Begin || Server.Time.Hour <= Ending;

                if (!tradeTime)
                    return;


@samuel.jus.cornelio
Replies

samuel.jus.cornelio
19 Aug 2020, 02:28

RE:

samuel.jus.cornelio said:

Hello, I'm trying to create a code to start trading at a specific time. But I'm not succeeding

follow the example below

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 bot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

  [Parameter("Begin Trading Hour", DefaultValue = 6)]
        public int Begin { get; set; }

        [Parameter("Ending Trading Hour", DefaultValue = 18)]
        public int Ending { get; set; }

   private DateTime startTime;
        private DateTime endTime;

    protected override void OnTick()
        {
 

 startTime = Server.Time.Date.AddHours(Begin);
                endTime = Server.Time.Date.AddHours(Ending);

                if (Trade.IsExecuting)
                    return;

                bool tradeTime = false;
                if (Begin < Ending)
                    tradeTime = Server.Time.Hour >= Begin && Server.Time.Hour < Ending;
                if (Ending < Begin)
                    tradeTime = Server.Time.Hour >= Begin || Server.Time.Hour <= Ending;

                if (!tradeTime)
                    return;

 

I already managed to solve the problem


@samuel.jus.cornelio