Remote Config Fetcher
A remote-config pattern (an EA polling a hosted settings file on a timer so parameters can be changed without recompiling) has two recurring problems the naive version ignores. First, re-parsing an identical file every poll wastes work and, worse, can trigger spurious "config changed" handling in the caller even when nothing actually changed. Second, a transfer can silently truncate or corrupt on a poor connection, and applying a half-downloaded config is worse than not updating at all. RcfgFetch() checksums every successful download (a 32-bit FNV-1a checksum - MQL4 has no built-in cryptographic hash) and compares it against the checksum of the last cached copy, so result.changed is only true when the content genuinely differs. If the caller supplies expectedChecksumHex (a checksum the config's author published separately, the same idea as a software download's SHA256SUMS file), the download is verified against it BEFORE the cache is touched - a mismatch leaves the existing cache exactly as it was and reports checksumMismatch=true rather than applying a corrupted or unexpectedly different file. If the network attempt itself fails outright (host not whitelisted, connection down, non-2xx status), RcfgFetch() falls back to serving whatever is already cached, however old, rather than leaving the caller with nothing. Notes and limitations - The checksum is a 32-bit FNV-1a value, not a cryptographic hash - MQL4 has no built-in hashing function to reach for. It reliably catches accidental corruption/truncation and detects real content changes, but a determined adversary controlling both the download and the "published" checksum could construct a collision. Do not treat expectedChecksumHex as a substitute for HTTPS/host trust when the config controls anything safety-critical (e.g. risk limits). - WebRequest() only reaches hosts the terminal has explicitly whitelisted. Every fetch fails with error 4060 until the config host is added there - this is a terminal setting the library cannot configure for itself. - The cache file is a single self-describing text file (two header lines plus the raw config body) written to the sandbox (MQL4\Files, or MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common with commonFolder=true) - it is not encrypted or access-controlled beyond the sandbox's own permissions. - A checksum mismatch against expectedChecksumHex leaves the previous cache completely untouched and returns ok=false - the caller must check checksumMismatch explicitly and decide what to do (retry, alert, keep running on the last good config) rather than assuming a failed fetch always means "no config available at all".
Script · MT5 · v1.0 · Free
About Remote Config Fetcher
Remote Config Fetcher is a script for MetaTrader 5. It has 2 settings, such as Config url and Expected checksum. MQL source code included.
Files in the download: RemoteConfigFetcher.mq5.mqh, RemoteConfigFetcher.txt, RemoteConfigFetcherDemo.ex5, RemoteConfigFetcherDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Config url | paste a real raw config URL (e.g. a GitHub raw link) to test a live fetch | |
| Expected checksum | optional 8-hex-digit checksum to verify the download against, leave blank to skip |
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: MT5 Script · MQL5 Source Code