Bot stopps when TimeTillClose()

Created at 30 Nov 2020, 13:35
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!
SC

Schaitan

Joined 30.11.2020

Bot stopps when TimeTillClose()
30 Nov 2020, 13:35


Hello,

my bot stopps sometimes when backtesting. I could figure out that it has something to do with TimeTillClose().

 

Symbol: USPJPY, m1

Error: "Crashed in OnTick with InvalidOperationException: Die Sequenz enthält keine Elemente." - "Bot was stopped"

Some Stopping Dates: 11 Feb 2011, 29 Apr 2011, 14 Nov 2014, 16 Mar 2018 (always a Friday)

 

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            // Put your core logic here
            var list = Symbol.MarketHours.Sessions;

            if (Time.TimeOfDay == TimeSpan.FromMinutes(1019))
            {
                TimeSpan tim = new TimeSpan();
                tim = Symbol.MarketHours.TimeTillClose();
            }
        }

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

 


@Schaitan
Replies

PanagiotisCharalampous
30 Nov 2020, 16:09

Hi Schaitan,

I could not reproduce the reported issue. Please let us know your broker, the symbol and the data sources (ticks, m1 bars etc)

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Schaitan
30 Nov 2020, 16:25

RE:

Hi Panagiotis,

Broker: ICMarkets

Symbol: USDJPY

Data Sources: m1

It only occurs sometimes in a backtest. When testing only 2020 everything works fine.

Best Regards


@Schaitan