Yaml Subset Reader
Full YAML (anchors, tags, flow style, multi-line block scalars, multiple documents) is a large spec with no MQL4 implementation, and most config files a trading tool actually needs to read use only a small, well-behaved slice of it. This library reads exactly that slice and documents it explicitly rather than quietly failing (or worse, silently misinterpreting) anything outside it: - scalar "key: value" pairs, unquoted or wrapped in ' or " - nested maps via indentation, 2 spaces per level, consistently - simple lists: a "key:" line followed by "- item" lines one level deeper, where each item is a SCALAR (a list of maps is out of scope) - full-line and trailing "# comment" comments, and blank lines Explicitly NOT supported: flow style ({...}/[...]), anchors/aliases, multi-line block scalars (| and >), tags, multiple documents in one file, and lists containing maps. A line outside the subset is skipped rather than guessed at, and GetLastWarning() reports the most recent line that was skipped and why - so a config author gets a clear signal rather than a silently wrong value. Internally the parser flattens the document into dot-separated paths ("server.timeout.connect_seconds", "symbols[0]", "symbols[1]") instead of building an actual nested tree structure. MQL4 has no natural recursive/variant node type to hold a real YAML tree conveniently, and a flat path lookup is what almost every config-reading caller wants to do with the result anyway. Notes and limitations - Tabs in indentation are rejected outright (the line is skipped and a warning recorded) - the subset requires consistent space indentation, matching real YAML's own tab prohibition. - GetBool() only recognises "true"/"false" (case-insensitive), not YAML's broader yes/no/on/off/y/n set. - A list item's value is read as a single scalar string with quotes stripped - no escape-sequence interpretation inside quoted scalars. - "key:" with no value AND no indented children under it parses as present-but-empty rather than a null the caller can query specifically - GetString() on such a key returns "". - GetLastWarning() only holds the MOST RECENT skipped line, not a full list - for a config with several out-of-subset lines, fix and re-parse iteratively, or copy the warning after each ParseText/ ParseFile call if a running log is needed.
Script · MT4 · v1.0 · Free
About Yaml Subset Reader
Yaml Subset Reader is a script for MetaTrader 4. MQL source code included.
Files in the download: YamlSubsetReader.mqh, YamlSubsetReader.txt, YamlSubsetReaderDemo.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