This looks a lot cleaner than using an int to set time.
inputstring LocalOpenHourSydney = "9:0-17:0";
inputstring LocalOpenHourTokyo = "8:0-17:0";
inputstring LocalOpenHourFrankfurt = "8:0-17:0";
inputstring LocalOpenHourLondon = "8:00-16:30";
inputstring LocalOpenHourNewYork = "9:30-16:0";
int startHours, startMinutes, endHours, endMinutes, startInt, endInt;
ConvertTimeRangeToInt(LocalOpenHourSydney, startHours, startMinutes, endHours, endMinutes, startInt, endInt);
syd.BeginLocalTime(startHours, startMinutes);
syd.EndLocalTime(endHours, endMinutes);
// Function to convert double time to integer representation and output hours and minutesint ConvertTimeToInt(double time, int &hours, int &minutes)
{
// Extract the hours and minutes
hours = (int)time;
minutes = (int)((time - hours) * 100);
// Check for valid hour and minute valuesif(hours > 23 || hours < 0)
{
Print("Error: Invalid hour value. The value should be between 0 and 23.");
return -1; // Indicate an error
}
if(minutes > 59 || minutes < 0)
{
Print("Error: Invalid minute value. The value should be between 0 and 59.");
return -1; // Indicate an error
}
// Combine hours and minutes into a single integer representationint timeInt = hours * 100 + minutes;
return timeInt;
}
// Function to convert time range string to integer representationsvoid ConvertTimeRangeToInt(string timeRange, int &startHours, int &startMinutes, int &endHours, int &endMinutes, int &startInt, int &endInt)
{
// Split the time range stringstring times[];
StringSplit(timeRange, '-', times);
// Convert start timedouble startTime = StringToDouble(times[0]);
startInt = ConvertTimeToInt(startTime, startHours, startMinutes);
// Convert end timedouble endTime = StringToDouble(times[1]);
endInt = ConvertTimeToInt(endTime, endHours, endMinutes);
}
This looks a lot cleaner than using an int to set time.
Nice suggestion, and thanks for the codes.
I know strings looks more human ;), but, I am using int for two reasons:
With integers, optimaizations are possible in the strategy tester (start, step, stop values for "int" session hours) to optimize trading a specific session.
Working with strings contradicts with the level of performance that won't slow the MT5 terminal.
PS: the code reminds me of the int parser in compiler codes.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Update 26 October 2024 - version 1.95
Added two new static methods: TimeGMTOffset() and TimeDaylightSavings().
Renamed the HistoryBrokerOffset() method to TimeServerGMTOffset().
Update 28 October 2024 - version 1.97
Converted all macros for dealing with time to functions to avoid double evaluation of parameters inside macro body. More code clean-up in other lines.
Update 1 November 2024 - version 1.99
Added an option to switch off the default loading of Gold symbol for estimation of the server's TZ/DST.
Call CTimeZoneInfo::SetUsingGoldSymbol() with 'false' to use the current chart's symbol, instead.
This looks a lot cleaner than using an int to set time.
This looks a lot cleaner than using an int to set time.
Nice suggestion, and thanks for the codes.
I know strings looks more human ;), but, I am using int for two reasons:
- Working with strings contradicts with the level of performance that won't slow the MT5 terminal.
PS: the code reminds me of the int parser in compiler codes.Update 13 November 2024 - version 2.00
Improved estimation of online server tz/dst and in the strategy strategy
TimeGMT library is no longer needed, all the functionality is included within TimeZoneInfo.
Constructor accepts place and time parameters.
New public methods for working with data of datetime type.
Improved error handling and debugging support.
Update 14 November 2024 - version 2.02
Fixed error ERR_HISTORY_NOT_FOUND (4401) when trying to access the XAUUSD,H1 quotes history by the server timezone object.
Update 12 December 2024 - version 2.10
Improved performance of HistoryServerGMTOffset() and HistoryServerDaylightSavings() functions, and other minor code changes.
Update 12 January 2025 - version 2.15
Fixed issue in HistoryServerDaylightSavings() of searching for quotes history earlier than the loaded history in the strategy tester.