Is there a way to have bots use cTrader's current "user time" programmatically without parameters?

Created at 24 May 2023, 04:44
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!
FI

firemyst

Joined 26.03.2019

Is there a way to have bots use cTrader's current "user time" programmatically without parameters?
24 May 2023, 04:44


Hi everyone:

Is there a way in bots and indicators to use cTrader's specified timezone that's set at the bottom of the application?

I have code based on specific times that people around the world use.

 

I don't want to have to keep setting the TimeZone directive in bots. Eg:

[Robot(TimeZone = TimeZones.xxx

and I don't want to have to implement a TimeZone or UTC offset parameter, and was hoping for something easy like:

Time.UserTime

that would return what the user has the chart set to:

Any ideas?

Thank you.


@firemyst
Replies

PanagiotisChar
24 May 2023, 08:58

Hi firemyst,

Unfortunately this info is not available through the API.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

firemyst
24 May 2023, 09:14

RE:

PanagiotisChar said:

Hi firemyst,

Unfortunately this info is not available through the API.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Thank you for the confirmation @PanagiotisChar . That's a bummer, but oh well... at least I didn't overlook something that's stupidly simple :-)


@firemyst

pick
24 May 2023, 11:54

I don't believe you can set the default for the indicator, but you can access the users current offset:

protected override void Initialize()
{
	TimeSpan t = this.Application.UserTimeOffset;
	Print("User time offset = " + t.TotalHours);
	this.Application.UserTimeOffsetChanged += Application_UserTimeOffsetChanged;

}

private void Application_UserTimeOffsetChanged(UserTimeOffsetChangedEventArgs obj)
{
	TimeSpan t = this.Application.UserTimeOffset;
	Print("User time offset changed = " + t.TotalHours);
}

From there, it's easy to just combine the utc time with the offset for user time.


@pick

firemyst
24 May 2023, 16:06

RE:

pick said:

I don't believe you can set the default for the indicator, but you can access the users current offset:

protected override void Initialize()
{
	TimeSpan t = this.Application.UserTimeOffset;
	Print("User time offset = " + t.TotalHours);
	this.Application.UserTimeOffsetChanged += Application_UserTimeOffsetChanged;

}

private void Application_UserTimeOffsetChanged(UserTimeOffsetChangedEventArgs obj)
{
	TimeSpan t = this.Application.UserTimeOffset;
	Print("User time offset changed = " + t.TotalHours);
}

From there, it's easy to just combine the utc time with the offset for user time.

 

Thank you for this. Appreciate your time! I'll give it a try. :-)


@firemyst