Crashing based on

Created at 15 Aug 2019, 04:58
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

sascha.dawe

Joined 11.02.2019

Crashing based on
15 Aug 2019, 04:58


Hi,

I would like help with this date/time error. 

I have the following function defined:

 

 public DateTime TradingDateTime()
        {
            if (this.IsBacktesting)
            {
                return Server.Time;
            }
            return TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local);
        }

But, when I call this onBar with the following code:

 DateTime toda = TradingDateTime();
 DateTime today = toda.Date.AddHours(-7);

 int lastBarIndex = MarketSeries.OpenTime.GetIndexByTime(today) + 1;

I get the following error:


15/08/2019 11:50:00.900 | Crashed in OnBar with ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly.  For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone

What am I doing wrong here?
 

 


@sascha.dawe
Replies

PanagiotisCharalampous
26 Aug 2019, 09:56

Hi Sascha,

Chaeck this thread, it might be helpful for you.

Best Regards,

Panagiotis


@PanagiotisCharalampous

sascha.dawe
26 Aug 2019, 13:53

Hi Panagiotis,

Thanks for taking the time to research this problem.

This thread solved my problem.

Much Appreciated, 

Sascha


@sascha.dawe