High-Performance Time Functions (Time Utils)
This professional-grade solution for MetaTrader 5 helps traders achieve greater efficiency in their daily workflow. This library provides a collection of modular, reusable code. It is utilized by developers to organize common functions, allowing for the integration of complex logic across multiple Expert Advisors, indicators, or scripts without the need for code duplication.
How to Setup and Use High-Performance Time Functions (Time Utils)
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
Description & Settings
This library contains more than 80 different functions to deal with time variables. The primary aim is to provide high-performance time functions. The performance mode (which can be controlled at compile time via a #define) is disabled by default. This mode is not a requirement to include the library into your projects, as it can be included normally without it.
TIMEUTILS_PERFORMANCE_MODE
Optionally, performance-mode can be switched on at compile time via #defines before #include:
This will redirect all calls to MQL's built-in and functions to more efficient alternatives.
You can compile the script "performance_mode.mq5" with and without TIMEUTILS_PERFORMANCE_MODEto check for the difference in speed on your machine. This will be beneficial to high-performance programs performing heavy or many time-related tasks (e.g., scanning all the quotes history for H1 bars at the start of trading weeks or collecting other statistics).
Listing of all functions in the library:
The function names should be self-explanatory; also, you can find a short description for a specific function in the TimeUtils.mqh file.
List of all available time formats:
The two attached scripts "basic.mq5" and "advanced.mq5" shows the basic and advanced usage examples.
An example output from "advanced.mq5" script:
Updates:
2024.12.03 - v.1.10 : Initial release.
2024.12.05 - v.1.15 : Added functions for business days and for Nth() weekday of the month. Optimized calculations in DaysInMonth() function.
2024.12.09 - v.1.20 : Added TimeFormat() function to format the time according to the passed string of tokens.
2024.12.09 - v.1.25 : Optimized calculations in TimeToStructFast() function.
2024.12.10 - v.1.30 : Optimized TimeFormat(), StartOfYear() and EndOfYear() functions. Updated descriptions of some functions.
2024.12.15 - v.1.35 : Optimized GetNthWeekdayInYearMonth() function.
2024.12.18 - v.1.40 : Added IsCurrentXXX(), IsToday(), IsTomorrow() and IsYesterday() functions.
2024.12.19 - v.1.45 : Optimized AddMonths() and GetNthWeekdayInYearMonth() functions.
2024.12.20 - v.1.50 : More code clean-up.
2024.12.21 - v.1.55 : Simplified calculations in AddMonths(): replaced the complex logic of adjusting months and years with a simpler total months calculation.