Working with Dates, Timers, New Bars, and Time Filters in MQL5
Summary
This programming tutorial explains how MQL5 represents date and time values and applies them in trading-system logic. It introduces the datetime type as a count of seconds, shows how to compare and adjust timestamps, and describes conversions between strings and datetime values. It also covers the MqlDateTime structure for accessing calendar fields, plus the timer event for running code at a chosen interval.
The practical examples include detecting a new bar, filtering activity by time, and allowing a trade at a specified time. These examples show how timestamp operations can support scheduling and avoid repeated actions. The article is instructional rather than an empirical trading study: it provides code-oriented demonstrations but no tests of profitability, execution quality, or behavior across brokers and time zones. Calendar intervals and timestamp conventions should be handled carefully when adapting the examples, particularly where trading-session boundaries or daylight-saving rules matter.
Key ideas
- MQL5 datetime values can be compared and adjusted using seconds.
- MqlDateTime converts timestamps into calendar fields and can be converted back.
- The timer event runs code at a configured interval.
- New-bar detection and time filters can control when strategy logic runs.
- A time-based trade trigger should track prior execution to avoid repeated signals.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.