Uninstall Cleanup Helper
Most EAs and indicators leave litter behind after removal: global variables that never get deleted, CSV files sitting in MQL4\Files, chart objects orphaned when the program is detached rather than properly deinitialised. This library gives two complementary ways to clean that up. The REGISTRY mode is meant to run inside the tool's own lifetime: call CleanupRegisterGlobal/Object/File() at the point each item is actually created, then CleanupRunRegistered() at OnDeinit to delete exactly those names. It is precise - it will never touch something it did not itself create, even if another tool happens to use a similar naming pattern. The PREFIX SWEEP mode is for the practical uninstall case: the user is removing the tool and the program that created the litter may not even be attached to a chart any more, so there is no registry left in memory to run. CleanupSweepGlobalsByPrefix/ObjectsByPrefix/FilesByPrefix (and the CleanupSweepEverythingByPrefix convenience wrapper) instead walk the terminal's actual global variable list, the given chart's object list, and the MQL4\Files directory, deleting anything whose name starts with a chosen prefix - so a tool that consistently prefixes everything it creates (a sensible habit regardless of this library) can be fully swept by a small standalone "uninstall" script run once, independent of whether the original EA/indicator is still running. Notes and limitations - File cleanup is sandboxed exactly like every other MQL4 file function: it can only reach MQL4\Files (or MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common with useCommon=true), never the terminal's history folder, the tool's own compiled .ex4/.ex4 binary, .set input-preset files, or anything outside the sandbox. Those are outside what any MQL4 program can delete about itself, by design. - A running program cannot delete its own compiled binary or currently- open files while it is executing - the file is locked by the terminal. Cleanup of a tool's OWN .ex4 (as opposed to files/globals/ objects it created) is not something any MQL4 script can do to itself; the user still removes the file from the Navigator or the MQL4 folder manually as the final uninstall step. - The prefix sweep matches by simple StringFind-at-position-0, not a wildcard/regex pattern - a prefix that happens to also be the start of an unrelated global variable, object or file name from a different tool will be swept too. Choose a genuinely distinctive prefix (a project-specific tag, not something generic like "Trade_") to avoid this. - Deleting a global variable or object that does not currently exist is treated as a no-op, not an error - the deleted counters only count items that were actually removed, so re-running cleanup twice in a row is safe and simply reports 0 the second time. - CleanupRunRegistered() only knows about names registered THIS run (or carried over if CleanupRegistryReset() was not called); it is not a substitute for the prefix sweep when the registering program is no longer running.
Script · MT4 · v1.0 · Free
About Uninstall Cleanup Helper
Uninstall Cleanup Helper is a script for MetaTrader 4. It has 1 setting, such as Prefix. MQL source code included.
Files in the download: UninstallCleanupHelper.mqh, UninstallCleanupHelper.txt, UninstallCleanupHelperDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Prefix | UCH_Demo_ | Prefix used for every item this demo creates |
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: MT4 Script · MQL4 Source Code