Global Variables JSON Bridge
Terminal global variables are plain name/value pairs, but the terminal gives no built-in way to see or edit them as a file - the Global Variables window only shows a live list inside MetaTrader itself. This script writes that list out as a JSON object instead, one member per variable, so it can be opened in any editor, diffed against a previous snapshot, or edited by hand before being loaded back in. MQL4 has no built-in JSON reader or writer, so both directions are hand- rolled here. The Dump side escapes variable names into valid JSON string literals (quotes, backslashes and control characters are all escaped, not just the common ones). The Restore side is a small character-by-character parser that only ever needs to understand one shape - a flat object of quoted string keys mapped to plain numbers - which is what keeps a hand- written JSON parser honest to write and to trust. It stops at the first malformed member rather than guessing past it, and reports the exact character position and how many variables parsed successfully before that point, rather than silently skipping bad data or failing with no detail. Like the CSV-based backup tools in this catalogue, Restore never overwrites an existing variable unless explicitly told to - the default is to leave anything that already exists alone and report it as skipped. Notes and limitations - The JSON parser only understands a flat object of string keys and number values - the exact shape this script's own Dump mode produces. Nested objects, arrays, booleans, null and string-valued members are not supported and will stop parsing at that point. - \u-escaped characters above code point 0xFF are truncated when decoded, since the parser builds the result byte by byte. Global variable names are practically always plain ASCII in real use, so this is unlikely to matter in practice, but it is not a fully Unicode-correct decoder. - Values are written and read at 8 decimal places, matching the terminal's own display precision for global variables. - The restore file must already be in MQL4\Files - this script does not fetch files from anywhere else and does not accept a full path. - This is a snapshot, not continuous protection. Nothing here runs on a schedule.
Script · MT5 · v1.0 · Free
About Global Variables JSON Bridge
Global Variables JSON Bridge 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 Mode, Json file and Overwrite existing. MQL source code included.
Files in the download: GlobalVarsJsonBridge.ex5, GlobalVarsJsonBridge.mq5, GlobalVarsJsonBridge.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Mode | ModeDump | Mode |
| Json file | JSON filename in MQL5\Files (Dump: optional, Restore: required) | |
| Overwrite existing | false | Restore: overwrite variables that already exist |
| Confirm first | true | Restore: ask for confirmation before writing |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT5 Script · MQL5 Source Code