Skip to content
All library documents

Using MetaTrader Terminal Global Variables for EA State and Coordination

Article MQL5 articles

Summary

This guide explains MetaTrader terminal global variables, which store numeric values beyond the lifetime of a script or terminal session. It covers setting and retrieving values, checking whether a name exists, reading access time, listing or deleting variables, forcing persistence, and creating temporary variables. It also notes that variables expire after four weeks without access and that names are limited in length.

Practical examples include tracking maximum or minimum account equity, grouping variables by name, and using conditional updates to coordinate Expert Advisors. The article also describes a helper class intended to simplify common operations. Its examples and functions are specific to MQL5, and the document presents programming techniques rather than measured trading results. Persistent shared state can support EA reliability and coordination, but developers still need to design naming, initialization, and update logic around their application’s requirements.

Key ideas

  • Terminal global variables preserve numeric state across program runs and terminal restarts.
  • Check for existence when initializing minimum values so a missing value does not act as zero.
  • Global variables can be enumerated, grouped by name, deleted, or explicitly flushed to storage.
  • Conditional updates support coordination between concurrently running Expert Advisors.
  • Unused variables are automatically removed after four weeks without access.

Tags

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