Replies

marwaha1@gmail.com
28 Feb 2018, 14:26

RE:

Hi Panagiotis Charalampous,

Thanks for the help. Does this mean that i would have to manually change the Month and Day and Year in the cBot or is there a way to set the year, month,day to current values.

kind regards,

mohit marwaha

 

Panagiotis Charalampous said:

Hi marwaha1@gmail.com,

Thanks for posting in our forum. See below an example that might be helpful

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0)]
        public int Minute { get; set; }
        [Parameter(DefaultValue = 12)]
        public int Hour { get; set; }
        [Parameter(DefaultValue = 1)]
        public int Day { get; set; }
        [Parameter(DefaultValue = 1)]
        public int Month { get; set; }
        [Parameter(DefaultValue = 2018)]
        public int Year { get; set; }

        private DateTime _closeDateTime;
        protected override void OnStart()
        {
            _closeDateTime = new DateTime(Year, Month, Day, Hour, Minute, 0);
        }

        protected override void OnTick()
        {
            if (DateTime.Now > _closeDateTime)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
            }
        }

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

You can adjust accordingly based on your needs.

Best Regards,

Panagiotis

 


@marwaha1@gmail.com