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

firemyst since: 26 Mar 2019;

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

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.

PanagiotisChar's avatar

PanagiotisChar since: 15 Sep 2022;

  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

Cofounder and Chief Technologist at Aieden Technologies

firemyst since: 26 Mar 2019;

  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 :-)

pick since: 04 Oct 2022;

  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.

firemyst since: 26 Mar 2019;

  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. :-)