Config Hot Reload Engine
A config file an EA re-reads mid-session is only safe if a bad edit cannot half-apply. Reading and assigning fields one at a time as they are parsed means a typo partway through a file can leave an EA running with half the new settings and half the old ones - a state that never existed in either the old file or the new one. This library validates the whole file before committing anything. RegisterField() declares each expected key's type (double, int, bool, or string) and, for numeric types, a valid range, once during OnInit. Poll() then reads the file, and only if every single field passes its registered check does it become the new active set - a single field failing (out of range, wrong type, an unregistered key) rejects the reload entirely and the previously-applied values keep running unchanged, which is the rollback-on-error behaviour the name promises. MQL4 has no function pointers, so there is no way for a library to call arbitrary caller validation code directly. This is solved with data instead of callbacks: the schema itself IS the validation logic, which also means it can be exercised with fabricated file content in a test without touching disk. Change detection uses a cheap content hash of the whole file rather than a file-modified-time API, since MQL4 has no reliable equivalent - re-reading and re-validating an unchanged file costs one file open and a hash, not a full re-apply. Notes and limitations - The config file format is plain KEY=VALUE, one per line; lines starting with # and blank lines are skipped, and a line with no '=' is skipped rather than aborting the whole parse. - An unregistered key present in the file causes that Poll() to be rejected (treated as a validation failure), so every key actually used must be registered even if it has no meaningful range. - Change detection is a content hash, not a filesystem timestamp - a file rewritten with byte-identical content is correctly treated as unchanged, but this means Poll() must actually open and read the file on every call; it is not free. - A rejected reload does not update the remembered content hash, so the same bad file is re-validated (and re-rejected) on every subsequent Poll() until it is actually fixed on disk.
Script · MT5 · v1.0 · Free
About Config Hot Reload Engine
Config Hot Reload Engine is a script for MetaTrader 5. MQL source code included.
Files in the download: ConfigHotReload.mq5.mqh, ConfigHotReload.txt, ConfigHotReloadDemo.ex5, ConfigHotReloadDemo.mq5.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trading Sessions · MT5 Script · MQL5 Source Code