Topics

Forum Topics not found

Replies

zoo.digitaladv
03 May 2024, 14:15 ( Updated at: 03 May 2024, 14:50 )

RE: How to Reference chart count down Timer/Clock

amusleh said: 

Hi,

You can't use the bar counter on chart from Automate API, and there is no need for it.

You can easily code one, each bar has an open time and if you know the time frame you can subtract the bar open time from current time, ex:

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 NewcBot : Robot    {        private TimeSpan _barTimeLeft;        protected override void OnStart()        {            Timer.Start(1);        }                protected override void OnTimer()        {            var previousBarTimePeriod = Bars.LastBar.OpenTime - Bars.Last(1).OpenTime;            _barTimeLeft = previousBarTimePeriod - (Server.Time - Bars.LastBar.OpenTime);                        // Check logs, it should match with chart counter            Print("{0:hh':'mm':'ss}", _barTimeLeft);            // Close all positions if the time left is less than or equal 10 seconds            if (_barTimeLeft.TotalSeconds <= 10)            {                foreach (var position in Positions)                {                    ClosePosition(position);                }            }        }    }}

By any chance, there is one for mobile Android CTrader app? 

 


@zoo.digitaladv

zoo.digitaladv
03 May 2024, 14:15 ( Updated at: 03 May 2024, 14:50 )

RE: How to Reference chart count down Timer/Clock

amusleh said: 

Hi,

You can't use the bar counter on chart from Automate API, and there is no need for it.

You can easily code one, each bar has an open time and if you know the time frame you can subtract the bar open time from current time, ex:

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 NewcBot : Robot    {        private TimeSpan _barTimeLeft;        protected override void OnStart()        {            Timer.Start(1);        }                protected override void OnTimer()        {            var previousBarTimePeriod = Bars.LastBar.OpenTime - Bars.Last(1).OpenTime;            _barTimeLeft = previousBarTimePeriod - (Server.Time - Bars.LastBar.OpenTime);                        // Check logs, it should match with chart counter            Print("{0:hh':'mm':'ss}", _barTimeLeft);            // Close all positions if the time left is less than or equal 10 seconds            if (_barTimeLeft.TotalSeconds <= 10)            {                foreach (var position in Positions)                {                    ClosePosition(position);                }            }        }    }}

By any chance, there is one for mobile Android CTrader app? 

 


@zoo.digitaladv