Skip to content
All library documents

Handling Time Zones, Sessions, and Bar Times in MQL5

Article MQL5 articles

Summary

This programming guide explains MQL5 date and time functions and applies them to common trading-platform tasks: acting at a specified time, restricting actions to a session, identifying bars, and calculating day or week boundaries. It discusses functions for reading server or local time, converting between time structures and strings, copying bar timestamps, and extracting date components. Examples include pivot indicators, time-point and session indicators, and checks for trading days and trading time within a week.

The article emphasizes practical sources of errors: server and computer clocks can differ, brokers may omit bars or include Sunday data, and weekends, time zones, and daylight-saving rules complicate calendar logic. It also distinguishes server time from local and GMT-related functions and notes that Strategy Tester behavior has its own peculiarities. The examples provide implementation techniques rather than a trading edge or performance evaluation. Time-zone rules and broker conventions can change or vary, so code built from these examples needs to be matched to the intended server, data feed, and testing environment.

Key ideas

  • MQL5 time functions support timestamp conversion, date-component extraction, and bar-time lookup.
  • Trading rules can be triggered at a point in time or restricted to daily or weekly sessions.
  • Server time, local time, and GMT-based time may differ and should be chosen deliberately.
  • Missing bars, Sunday quotes, weekends, and daylight-saving changes can affect calendar logic.
  • The article supplies indicator and utility examples but does not evaluate a trading strategy.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.