Loading…

Reset All Global Variables

Clearing global variables by hand means opening the terminal's Global Variables window and deleting rows one at a time, which is slow and easy to get wrong when there are dozens of them from several EAs sharing the terminal. A prefix convention (each EA's variables starting with its own name) makes a targeted wipe possible, but only if the tool doing it can filter by that prefix rather than clearing everything. The naive version of a reset script deletes first and worries about recovery later, if at all. This one writes a full backup CSV of every variable in scope - name, value and last-access time - before it deletes anything, and if that backup write fails for any reason, the deletion does not proceed. A reset you cannot undo is a bad trade for the two seconds a backup costs. Deleting also has to survive the same trap that closing an order pool does: the global variable table shifts as entries are removed, so an index-based loop that deletes while it iterates will skip entries. This script collects the full list of names in scope first, into a fixed array, and only then deletes from that list - which is exactly the "collect first, act after" principle a correct order-closing script also needs. Wiping every global variable with no prefix filter is the one version of this that can cost every EA and script running on the terminal its saved state simultaneously, so that specific case gets a louder warning dialog and defaults to No rather than the ordinary Yes/No question a prefixed delete gets. Notes and limitations - The prefix match is a plain "starts with" test, not a wildcard or regular expression. There is no way to match a suffix or a substring in the middle of a name. - The backup this script writes is in the same CSV shape that Backup And Restore Global Variables produces and consumes, so the two are interchangeable, but this script itself never restores anything. - Global variables are terminal-wide. Running this against an empty or overly broad prefix on a terminal shared by several EAs affects all of them, not just the one you had in mind. - Nothing here touches variables set by other terminals or other machines - only the terminal instance the script runs on.

Script · MT5 · v1.0 · Free

About Reset All Global Variables

Reset All Global Variables is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Prefix filter and Confirm first. MQL source code included.

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

Settings

SettingDefaultWhat it does
Prefix filterPrefix to match (empty = every global variable)
Confirm firsttrueAsk for confirmation before deleting

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