INI Config Reader
Most MQL settings either live as EA inputs, which cannot change without a recompile and reattach, or as hand-rolled string parsing scattered through OnInit. CIniConfig gives a small self-contained alternative: parse an INI file once, read typed values by section and key, edit them, and save the file back out. Storage is one flat array of (section, key, value) rows rather than a nested section-of-keys structure. Neither MQL4 nor MQL5 has templates, so a genuine map-of-maps would need two levels of hand-rolled association anyway; a flat row list with one lookup routine gets the same behaviour with less code, and it is what makes GetSectionNames() and GetKeyNames() straightforward linear scans instead of a second data structure to keep in sync. Every typed getter takes a default value and never raises an error. A missing section, a missing key, or a value that fails to parse (a GetInt() call on a value that is not actually numeric) all fall back to that default. A config reader that halts the EA on a typo in a hand-edited settings file is worse than one that runs on a safe default and lets the trader notice the value looks wrong in the log - this header always chooses the second behaviour. Boolean parsing accepts true/false, yes/no, on/off and 1/0, case- insensitively, because those are the four spellings a trader actually types into a text file by hand. ParseText() also tolerates the messiness of a hand-edited file directly: blank lines, ; and # comments, an implicit section before the first [Header] for settings that do not belong to any particular group, a key repeated later in the same section silently overwriting the earlier value, and a malformed line (no '=' and not a section header) being skipped rather than aborting the whole parse. SaveToFile() writes values only, grouped by section in first-seen order - it does not preserve comments or original formatting, because the library stores parsed values, not source text. Say so plainly to anyone editing a file by hand and also driving it from code: round-tripping through SaveToFile() will drop their comments. Notes and limitations - Values are always stored as text internally; typed getters convert on read. A value written with SetDouble and read with GetInt truncates via StringToInteger the same way it would from raw text - this is a text format, not a typed store. - SaveToFile() does not preserve comments, blank-line grouping, or key order from a file that was only ever loaded and never re-parsed from its own saved text - it writes section/key/value only. - Files live in the sandbox (Files or Files\Common with FILE_COMMON, which this header does not use). It cannot read or write arbitrary paths on disk, on either platform. - Not thread-safe, which matches both platforms' single-threaded-per-chart execution model; nothing here changes that.
Script · MT4 · v1.0 · Free
About INI Config Reader
INI Config Reader is a script for MetaTrader 4. It has 1 setting, such as File name. MQL source code included.
Files in the download: IniConfig.mqh, IniConfig.txt, IniConfigDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| File name | IniConfigDemo_roundtrip.ini | Sandbox filename for the save/load demo |
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