Loading…

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 · MT4 · v1.0 · Free

About Global Variables JSON Bridge

Global Variables JSON Bridge is a script for MetaTrader 4. 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.mq4, GlobalVarsJsonBridge.txt.

Settings

SettingDefaultWhat it does
ModeModeDumpMode
Json fileJSON filename in MQL4\Files (Dump: optional, Restore: required)
Overwrite existingfalseRestore: overwrite variables that already exist
Confirm firsttrueRestore: ask for confirmation before writing

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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 · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria