Export Global Variables To CSV
Terminal global variables are the scratch memory a lot of EAs use to remember a state across restarts, or to talk to each other on the same terminal: a trade counter, a "last signal" timestamp, a flag that says a news filter is active. There is no built-in way to see all of them at once - the Global Variables window in the terminal shows them, but you cannot export that window, sort it usefully, or hand it to someone else for debugging. This script does that: it walks every global variable with GlobalVariablesTotal() and GlobalVariableName(), reads each one's value and its last-set-or-accessed time, sorts the list by name, and writes it to a CSV in the sandbox. It never calls GlobalVariableSet, GlobalVariableSetOnCondition or GlobalVariableDel - nothing it touches is left different from how it found it. The trap this avoids is precision. A quick way to print a double is to hand it straight to Print or StringFormat with %G-style default formatting, and that silently rounds to a handful of significant digits. For a chat message that is harmless. For an export it is not: a global variable used as a running counter, an order ticket, or a Unix timestamp can easily exceed the digits that default formatting keeps, and a truncated export reports a different number than the one the EA is actually reading. This script writes every value with DoubleToString(value, 8), which is the same precision doubles are stored at, so the CSV matches the terminal exactly. This is a companion to "Backup Global Variables To File" (catalogue S097, folder BackupGlobalVars), not a replacement for it. That script actually persists global variables to a file and can restore them, which is what you want before closing the terminal or moving to a new machine. This script does not restore anything - it exists purely so you can look at what is currently set, at full precision, sorted in a way that is easy to scan or diff against an earlier export. Notes and limitations - Terminal global variables are per terminal installation, not per trading account. Two accounts opened in the same terminal share the same set of global variables; the same account opened in a different terminal installation sees none of them. This script exports whatever the running terminal currently holds, nothing more. - The terminal expires a global variable after its configured idle period (four weeks unless the platform or an EA changes that setting) if nothing reads or writes it in the meantime. A variable missing from the export may simply have expired rather than never existed. - The exported time is whichever the terminal reports through GlobalVariableTime(): the last moment the variable's value was set. It is not updated by a read-only GlobalVariableGet() call, so a variable that is frequently read but rarely written will show an old timestamp even though it is actively in use. - This is a snapshot, not a live view. Re-run the script to capture a later state; nothing in this file updates itself. - The file name embeds the export time so repeated runs do not overwrite one another. Old exports are left in the Files sandbox and are not cleaned up by this script.
Script · MT4 · v1.0 · Free
About Export Global Variables To CSV
Export Global Variables To CSV is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 1 setting, such as Csv delimiter. MQL source code included.
Files in the download: ExportGlobalVars.ex4, ExportGlobalVars.mq4, ExportGlobalVars.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Csv delimiter | , | Field delimiter for the CSV file |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Buy/Sell Arrows · News Trading · Alerts · MT4 Script · MQL4 Source Code