Skip to content
All library documents

Checking Broker Trading Sessions Against Server Time

Article MQL5 code base

Summary

The document describes a MetaTrader helper that determines whether a symbol’s market is open by comparing broker server time with that symbol’s configured trading session. It converts server time to a weekday and time of day, then checks whether the time falls within the session interval. The function returns a Boolean result, with closed as the default when time conversion or session lookup fails.

The examples emphasize that session hours can vary by weekday and broker, and that polling frequency affects whether an opening or closing window is detected. The author notes that checks at bar opens or on daily and longer periods may miss sessions that begin a few minutes after midnight. The sample code contains a weekday condition written with a logical OR, which is true for every weekday value; users should review that logic before relying on it. The page gives no tests or broader handling for multiple sessions, holidays, or overnight sessions.

Key ideas

  • Market status is determined by comparing broker server time with the symbol’s configured trading session.
  • The helper returns closed when time conversion or session lookup fails.
  • Broker trading hours may differ by weekday, so session checks should use the relevant symbol and day.
  • Checks performed only at bar opens can miss a session that starts between bars.
  • The sample weekday condition should be reviewed because its OR logic does not exclude weekends.

Tags

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