Skip to content
All library documents

Using Terminal Global Variables to Track MQL5 Program State

Article MQL5 articles

Summary

The article explains how MQL4/5 terminal global variables can provide shared state for programs running within one terminal. It proposes object-oriented wrappers for creating, reading, updating, and deleting variables, along with a list class for managing groups of them. Variables can be temporary or persist across terminal restarts; the article also describes encoding a temporary marker in names because the platform does not directly expose that property when reading a variable.

A trading robot example uses persistent variables as checkpoints around stages such as opening, closing, and trailing positions. If execution stops midway, the next launch can inspect the flags and report which stage may have been interrupted. The article demonstrates this as a way to detect incomplete processing, not as a mechanism that automatically repairs or safely resumes the operation. It also includes a curiosity-driven creation-speed test, but the excerpt supplies no specific performance findings. Care is needed when multiple programs share state and when interpreting stale flags after a failure.

Key ideas

  • Terminal global variables share named values among programs running in the same terminal instance.
  • Temporary variables disappear when the terminal closes, while persistent variables are stored across restarts.
  • An object-oriented wrapper can standardize variable creation, access, and group management.
  • Stage flags can help a trading robot identify where execution stopped unexpectedly.
  • Checkpoint flags detect possible interruptions but do not themselves guarantee safe recovery.

Tags

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