Argument String Parser
MQL4 programs never receive a real argv array - every "arguments" input is one plain string field. This library parses that string the way a getopt-style command-line parser would: double-quoted substrings keep their spaces together, "--name=value" and "--name value" both set a long option, "-abc" expands into three boolean short flags, and a bare "--" ends option parsing so everything after it is treated as positional even if it starts with a dash. The detail that makes this more than a naive space-split is deciding whether a bare token after an option is that option's VALUE or the next flag. A token only "looks like an option" here if it starts with a dash and is not itself a negative number - so "--offset -5" correctly attaches -5 as the value of --offset instead of being misread as an unknown flag "-5". Getting this wrong is the most common bug in hand-rolled option parsers that need to accept negative numeric arguments (offsets, thresholds, pip distances). An unterminated quote is reported through ErrorCount()/Error() rather than silently swallowing the rest of the line. Notes and limitations - No escape-character support inside quotes - a literal quote character cannot appear inside a quoted value. - A repeated flag/option is last-wins; earlier occurrences are simply overwritten, not accumulated into a list. - A clustered short-flag group ("-abc") is always three boolean flags - it can never consume a following value. Only a single "-f value" form attaches a value to a short flag. - This is a general-purpose tokeniser/classifier, not a schema-validating parser - it has no concept of "this option is required" or "this option must be numeric"; callers validate GetValue() results themselves.
Script · MT5 · v1.0 · Free
About Argument String Parser
Argument String Parser is a script for MetaTrader 5. MQL source code included.
Files in the download: ArgumentStringParser.mq5.mqh, ArgumentStringParser.txt, ArgumentStringParserDemo.ex5, ArgumentStringParserDemo.mq5.
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