Loading…

Fixture Data Manager

A test fixture - a small file of sample data a test reads instead of hitting a live feed - is only useful if it is trustworthy. Rebuilding it from scratch on every single run is wasteful for anything beyond a few lines; silently reusing whatever happens to already be on disk is worse, because a test can keep passing against yesterday's fixture long after the code's expectations of that fixture's shape have moved on, and nobody notices until production behaves differently from the test. This header's answer is a version tag written as the fixture file's first line. FdmSetupFixture compares the version the caller is asking for against whatever is already on disk: an exact match reuses the file untouched (cheap, and safe, precisely because the version matched); anything else - a missing file, a version mismatch, or an explicit forceRegenerate - triggers a fresh write. The caller gets an explicit wasRegenerated flag back so tests can assert on which path was taken, which is often useful in itself (a fixture that unexpectedly regenerates every run usually means the version constant and the content generator have drifted out of sync somewhere). Teardown follows the same "leave what you didn't touch alone" idea in reverse: FdmTeardownAllCreatedThisSession only deletes fixtures this session actually created or regenerated, tracked internally by name. A fixture that was reused untouched this run survives teardown and keeps acting as a cache for the next run - deliberately, since deleting a still-valid, unchanged fixture on every teardown would defeat the whole point of versioning it in the first place. Notes and limitations Fixture files live in MQL4\Files\ (or MQL5\Files\ on the native MQL5 build) (the standard MQL4 file sandbox) named FDM_<fixtureName>.txt - there is no subfolder support here, so fixture names should be unique across whatever else a project keeps in that folder. FdmReadFixture caps reading at FDM_MAX_FIXTURE_LINES (500 by default) to avoid an unbounded loop against a corrupted or unexpectedly huge file; a fixture larger than that is silently truncated on read, not rejected. The tracked-created list used by teardown is capped at FDM_MAX_TRACKED (64) and lives only in memory for the current run - if the script or EA that created fixtures terminates abnormally before calling FdmTeardownAllCreatedThisSession, those files are simply left on disk (which is generally the safer failure mode for a test fixture manager, since the alternative would be losing fixture content the next run could have reused). Version tags are plain non-negative integers; there is no semantic-versioning or schema-diffing behind them, only equality.

Script · MT4 · v1.0 · Free

About Fixture Data Manager

Fixture Data Manager is a script for MetaTrader 4. MQL source code included.

Files in the download: FixtureDataManager.mqh, FixtureDataManager.txt, FixtureDataManagerDemo.mq4.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Trading Sessions · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria