Loading…

Global Variable Namespace Audit

Terminal global variables live in one flat pool shared by every expert, script and indicator on the account, and there is no menu that shows them grouped by whoever created them. Two years of trying different EAs leaves a pool full of keys that nothing running today still reads, and the built-in Global Variables window just lists names alphabetically with no way to tell which ones are still alive. Most experts that use global variables at all follow some naming pattern - "EAName_State", "GridBot_Level3" - even though the platform enforces nothing about it. This script leans on that convention rather than inventing a real namespace the platform does not have: it splits each name on the first occurrence of a chosen separator and groups everything sharing that prefix together. It is a heuristic, stated as one, not a claim that the platform has namespaces it does not. The second half of the job is spotting the abandoned ones. Every global variable carries a last-access timestamp the platform updates whenever it is read or written. A key nothing has touched in thirty days almost certainly belongs to something no longer running, and the report flags it as STALE rather than making the user cross-reference it against every EA still on the account by hand. Notes and limitations - Grouping is a naming-convention heuristic, not a platform feature. A global variable with an unrelated name sits in its own one-member group rather than being mis-assigned to something it has nothing to do with. - STALE means "not accessed recently," not "safe to delete." A variable an EA reads only once a month, or once per new trading week, can be flagged even though something still depends on it - check before deleting. - The last-access time is whatever the terminal already tracks per global variable; this script does not add any tracking of its own and cannot see history from before it ran. - Terminal global variables are separate from per-symbol or per-chart variables and from anything an EA keeps only in its own memory - neither of those is visible to this audit.

Script · MT5 · v1.0 · Free

About Global Variable Namespace Audit

Global Variable Namespace Audit is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Separator, Stale days and Write csv report. MQL source code included.

Files in the download: GlobalVariableNamespaceAudit.ex5, GlobalVariableNamespaceAudit.mq5, GlobalVariableNamespaceAudit.txt.

Settings

SettingDefaultWhat it does
Separator_Character that splits a name into namespace and key
Stale days30Days since last access before a variable is flagged STALE
Write csv reporttrueAlso write a CSV report to MQL5\Files
Csv delimiter,Delimiter for the CSV report

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria