Loading…

Global Variable Migration Packer

Terminal global variables (GlobalVariableSet/GlobalVariableGet) are a convenient way for an EA or script to remember a value across restarts, but they live entirely inside the terminal's own memory - there is no built-in export or import, so moving a namespace of them to a new terminal (a rebuild, a VPS migration, a broker switch) means either losing that state or re-entering it by hand. This script runs in two modes from the same file. In Pack mode it enumerates every global variable whose name starts with InpPrefixFilter (leave it empty to pack everything) and writes each name/value pair into a plain-text file under MQL4\Files. Copy that file to the destination terminal's own MQL4\Files folder, then run the same script there in Restore mode to recreate each variable with GlobalVariableSet. Only variables that exist at the moment the script runs get packed. MQL4 itself silently deletes a GlobalVariableSet-created variable after roughly four weeks of no access - if a namespace has gone quiet that long, the variable is already gone before this tool ever sees it, and no packing script can bring back a value the terminal has already discarded. Notes and limitations - This tool moves terminal-wide global variables, not indicator buffers, chart objects, .set presets, or an EA's own internal state that never went through GlobalVariableSet. - Values are stored as plain doubles with 8 decimal digits of precision, matching what GlobalVariableGet itself returns - there is no separate string/int type to preserve, since MQL4 global variables are numeric only. - A namespace untouched for roughly four weeks may already have been auto-deleted by the terminal before this script ever runs; that is a platform behaviour this tool cannot see around, only report on (packing an already-expired namespace simply packs zero variables). - Restore mode skips any variable that already exists on the destination terminal unless InpOverwriteExisting is turned on.

Script · MT4 · v1.0 · Free

About Global Variable Migration Packer

Global Variable Migration Packer is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Mode, Prefix filter and File name. MQL source code included.

Files in the download: GlobalVarMigrationPacker.mq4, GlobalVarMigrationPacker.txt.

Settings

SettingDefaultWhat it does
ModeMODE_PACKPack (write file) or Restore (apply file)
Prefix filterOnly variables whose name starts with this are packed (empty = all)
File nameGlobalVarMigration.packFile under MQL4\Files used for both pack and restore
Overwrite existingfalseRestore only: overwrite a variable that already exists on this terminal
Dry run onlyfalseReport what would happen without writing globals or the file

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