Settings Schema Migrator
An EA that changes its own settings format between versions has a choice: force every user to delete and rebuild their saved settings, or silently misread the old file (a renamed key reads as missing, a field whose UNITS changed reads as a wildly wrong number). Neither is acceptable for anything that keeps state across upgrades. This library takes the versioned-migration approach used by database schema tools and rebuilds it for a plain key/value store. Each step is registered once against the version it applies FROM: AddRenameStep for a key that changed name, AddDefaultStep for a genuinely new field that needs a safe value for anyone upgrading from before it existed, AddRemoveStep for a key that no longer means anything, and AddScaleDoubleStep for a field whose stored unit changed (pips to points is the canonical case). MigrateToLatest() reads the store's own version tag, replays every step registered for that version, bumps the version, and repeats until no further step applies - so a store several versions behind catches up in one call, not one upgrade at a time. MQL4 has no function pointers, so a migration step here is DATA (an opcode plus up to two key names and a value string), not a callback - the same steps can be unit-tested against a fabricated store built with the library's own static SetValue/RemoveKey/GetValue helpers, with no file or GUI involved. Notes and limitations - The store is a flat key/value pair list, not a nested structure - fine for a typical EA's saved-inputs file, not meant for a deeply structured document. - The version tag is stored as an ordinary key ("__SchemaVersion") inside the same store, so a store that never had this library applied to it is correctly treated as version 0. - Migrating an already-current store is a safe no-op: MigrateToLatest() finds no step registered for the current version and returns immediately without touching anything. - This library does not read or write the settings file itself - it operates on parallel key/value arrays the caller already loaded, so it works with FILE_CSV, FILE_TXT, or a GlobalVariable-backed store equally.
Script · MT4 · v1.0 · Free
About Settings Schema Migrator
Settings Schema Migrator is a script for MetaTrader 4. MQL source code included.
Files in the download: SettingsSchemaMigrator.txt, SettingsSchemaMigratorDemo.mq4.
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