Using Regular Expressions in MQL5 to Parse Trading History
Summary
This document describes a MetaTrader 5 port of the .NET regular-expression library and demonstrates its use in an expert advisor. It outlines the library’s matching, capture, and options components; explains cache management and iteration through matches; and notes differences from C#, including the need to escape control characters explicitly in MQL5 strings.
The worked example parses an HTML trading-history file containing Orders and Deals tables. It matches text between angle brackets, uses match counts to distinguish row types, extracts fields into arrays, and places records in lists that can be filtered by column and saved to CSV. The document also mentions example scripts and compatibility with a specified minimum terminal build. This is an implementation example rather than a trading strategy: the parser’s assumptions depend on the input HTML structure and fixed match counts, and no validation against changed report formats is provided.
Key ideas
- The MQL5 library ports regular-expression functionality from .NET.
- MQL5 patterns must explicitly escape control characters in strings.
- A static cache stores compiled expressions and can be cleared after use.
- The example parses HTML Orders and Deals rows using match counts and text extraction.
- The approach depends on the trading-history file retaining the expected structure.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.