Print the Robot TimeZone

Created at 25 Aug 2013, 23:45
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!
lec0456's avatar

lec0456

Joined 14.11.2012

Print the Robot TimeZone
25 Aug 2013, 23:45


How can I use a print statement to printout the TimeZone setting being used by the robot?


@lec0456
Replies

cAlgo_Development
26 Aug 2013, 16:42

You can read timezone directly from the attribute:

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime)]
    public class MyBot : Robot
    {
        protected override void OnStart()
        {
            var attribute = (RobotAttribute)typeof(MyBot).GetCustomAttributes(typeof(RobotAttribute), false)[0];
            Print("My timezone: {0}", attribute.TimeZone);
        }
    }
}

But this will not work if you want to do it from a nested indicator.


@cAlgo_Development

lec0456
02 Sep 2013, 07:44

Is there a way to set a TimeZoneInfo variable equal to the TimeZone setting of the robot?

 TimeZoneInfo myTimeZone =<RobotTimeZone>;


@lec0456

cAlgo_Development
02 Sep 2013, 12:52

You can use FindSystemTimeZoneById() method:

    [Robot(TimeZone = TimeZones.CentralAmericaStandardTime)]
    public class TimeZonesRobot : Robot
    {
        protected override void OnStart()
        {
            TimeZoneInfo myTimeZone = TimeZoneInfo.FindSystemTimeZoneById(TimeZones.CentralAmericaStandardTime);
            Print("Time Zone: {0}, UTC Offset: {1}", myTimeZone.Id, myTimeZone.BaseUtcOffset);
        }
    }

 

If you want to grab timezone id directly from the attribute, you can use code from my previous post.


@cAlgo_Development