Config As Code Template
Most "configurable" EAs are configured through the MetaTrader input dialog, which means every parameter change is a manual, unaudited, per-chart edit with no record of what changed or when. A "config as code" EA instead reads its entire behaviour from a plain text file that can be version-controlled, reviewed, diffed and deployed like any other artefact - and, crucially, it validates that file before trusting a single value out of it. This template demonstrates the pattern with a genuinely working (if intentionally simple) moving-average crossover strategy: every parameter the strategy needs - MA periods and method, risk percentage, stop and take-profit distances, magic number, trading session and even which symbol the config is meant for - comes from the config file, not from `input`. Before any value is applied, the whole file is checked against a fixed schema: every required key must be present, every value must parse to its declared type, and every value must fall inside a declared valid range. A SchemaVersion mismatch, a missing key, or an out-of-range value fails the WHOLE load and the EA refuses to initialise (`INIT_FAILED`) rather than running with defaults silently substituted for whatever was missing - a half-validated config never gets a chance to trade. The actual moving-average crossover logic is deliberately minimal. The reusable part of this project is the config-loading and schema-validation scaffold above it - copy that pattern into a real strategy and swap the entry rule for something with an actual edge. Notes and limitations The config file format is a simple line-based "Key = Value" scheme, not real JSON or YAML - MQL4 has no built-in parser for either. A literal '#' character cannot appear inside a value (it is treated as the start of a comment) and there is no support for multi-line values, nested structures, or lists. The schema check is hand-written per key, not a generic schema-description language - adding a new config key means adding both a required-key entry and its own validation rule in the source, not editing a separate schema file. Config is loaded once, in OnInit. Editing the config file while the EA is already running on a chart has no effect until the EA is removed and reattached (or the terminal restarted) - there is no live file-watching or hot reload. The bundled trading rule (a moving-average crossover) is a genuine, working strategy, not a stub, but it is intentionally simple and has no claim of edge attached to it. Its only job in this project is to prove every config value actually reaches and drives real order-placement logic, correctly risk-sized from live account equity and the symbol's live tick value/size - never a hardcoded contract size. The Symbol key must exactly match the chart the EA is attached to. This EA does not trade a symbol other than its own chart's - a config written for one symbol cannot be pointed at another chart without editing the file.
Expert advisor · MT5 · v1.0 · Free
About Config As Code Template
Config As Code Template is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It trades only in the hours you set (time filter) and can size trades from your balance and risk percent. It has 2 settings, such as Config file name and Expected schema version. MQL source code included.
Files in the download: ConfigAsCodeTemplate.ex5, ConfigAsCodeTemplate.mq5, ConfigAsCodeTemplate.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Config file name | config_as_code_template.cfg | File in MQL5\Files\ - see .txt for the format |
| Expected schema version | 1 | Config files declaring a different SchemaVersion are refused outright |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Time Filter · Risk & Lot Size · Moving Average · MT5 Expert Advisor · MQL5 Source Code