Layered Configuration Resolver
Most experts read settings from exactly one place - their own inputs - and that is fine until you need the same strategy to behave differently across several charts, or want to nudge a parameter while it is running without restarting it, or need one settings file shared by several EAs. At that point "just use inputs" stops working and people reach for ad hoc combinations of GlobalVariableGet, hand-rolled file parsing, and input fallbacks scattered across the code with no single place that says which one actually won. This header gives that merge a fixed, documented precedence, highest to lowest: an explicit override (what the user actually typed into an input dialog, or set from code) beats a value loaded from a shared sandbox file, which beats a value read from a terminal global variable, which beats the safe default baked into the code. Every layer is optional - a key can be resolved purely from its default with nothing else ever touching it. The one genuine trap is that terminal global variables only ever hold a double on both platforms - there is no string storage on either. Rather than give that layer a different, narrower API, every value in this header is normalised to a string internally (the global-variable layer converts through DoubleToString), so GetString, GetDouble, GetInt and GetBool behave identically regardless of which layer actually supplied the value. You do not need to remember that one particular layer is numeric-only. DumpEffective prints every known key, its winning value, and which layer supplied it, in one call - the single log line that turns "why is this setting what it is" from a debugging session into a glance at the Experts tab. Notes and limitations - LoadFromGlobalVariables reads whatever is in the terminal's global variable pool at the moment it is called. It is a snapshot, not a live subscription - call it again if you expect a variable to change while the EA runs. - GetBool only recognises true/false, yes/no, on/off and 1/0 (case insensitive). Anything else falls back to the caller-supplied default rather than guessing, which matters if a hand-edited file has a typo. - LoadFromFile treats a missing "=" as a malformed line and skips it rather than aborting the whole file - one bad line should not silently discard every other setting in the file. - No locking or thread safety is needed or attempted; both platforms run experts single-threaded per chart. - This header resolves configuration, it does not validate it. Range and sanity checks on the resolved values remain the caller's job.
Script · MT4 · v1.0 · Free
About Layered Configuration Resolver
Layered Configuration Resolver is a script for MetaTrader 4. MQL source code included.
Files in the download: LayeredConfig.mqh, LayeredConfig.txt, LayeredConfigDemo.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