Loading…

Shared Format Self Test

A lot of MQL4 tools reinvent the same handful of small text-file formats: a "key=value" line like a .set file, a "name and a tab and a value" packed pair, and hand-rolled comma-separated rows. Each format has its own quiet trap - a value that happens to contain the format's own delimiter, or an empty value, can come back different from what was written, and nothing about the file itself warns you. This script writes a shared batch of test values (plain text, an empty string, a numeric-looking string, and - when InpIncludeAwkwardCases is on - values containing a comma and a pipe) through four format implementations, all reimplemented locally for this test rather than shared with any other project: - KeyValueLine: "Field0=value", the .set-file convention. - PackedPair: "Field0<TAB>value", the packed-migration-file convention. - NaiveCsv: one row, fields joined with a bare comma, no quoting. - QuotedCsv: the same row, but a field containing a comma or quote is wrapped in quotes with internal quotes doubled. Each value is written to a real file under MQL4\Files and read back with the paired decoder, then compared against the original. A mismatch is printed as FAIL rather than PASS - and for NaiveCsv, a comma-bearing test value is EXPECTED to fail, since that format has no escaping at all. That expected failure is the whole point: it is a concrete, reproducible demonstration of why QuotedCsv exists, rather than an abstract warning. Notes and limitations - The reader/writer pairs here are small original reimplementations written specifically for this self test, not shared code pulled from any other project in this catalogue - house style forbids including another project's file, and every format used elsewhere in this catalogue is, in practice, exactly this simple to reimplement. - This is a format self-test, not a fuzzer: it checks a fixed, small batch of representative values, not every possible awkward input (embedded newlines, for instance, are not covered, since none of MQL4's own line-based FileReadString reads handle an embedded newline within a single field either). - NaiveCsv failing on comma-bearing values is a documented, expected result of running this script with default inputs, not a defect in the script itself. - This tool touches only its own temporary files under MQL4\Files. It has no connection to any account, symbol, order or open position.

Script · MT5 · v1.0 · Free

About Shared Format Self Test

Shared Format Self Test is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Test folder, Delete files after and Include awkward cases. MQL source code included.

Files in the download: SharedFormatSelfTest.ex5, SharedFormatSelfTest.mq5, SharedFormatSelfTest.txt.

Settings

SettingDefaultWhat it does
Test folderSharedFormatSelfTestSubfolder under MQL5\Files used for the round-trip files
Delete files aftertrueDelete the round-trip files when the test finishes
Include awkward casestrueInclude values containing each format's own delimiter (expected to expose real traps)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria