Discussing the article: "Property-Based Testing for Trading Rules in MQL5 (Part 1): Generate Market Scenarios, Test Invariants, Find Edge Cases"

Check out the new article: Property-Based Testing for Trading Rules in MQL5 (Part 1): Generate Market Scenarios, Test Invariants, Find Edge Cases.

Property-based tests exercise a sizing rule across thousands of generated scenarios instead of a few hand-picked cases. A deterministic MQL5 runner creates seeded symbol contracts, checks eight risk-volume properties, and writes text and CSV reports for reproducible evidence. A second script intentionally rounds volume the wrong way, replays the failing seed, and shrinks the counterexample to the half-step boundary, making the defect minimal and diagnosable.

A risk-based volume function can pass three examples and still increase a request at a rounding boundary. A trader who has checked a small account, a familiar currency pair, and a normal stop distance has evidence for those inputs. Fractional steps, minimum-volume transitions, unusual tick values, and large caps remain separate questions. A profitable backtest does not systematically exercise those arithmetic boundaries.

This article builds a deterministic MQL5 test harness for a simplified pre-cost sizing rule. Eight properties check generated scenarios, while fixed tests cover known boundaries and invalid inputs. Deliberately wrong outputs test whether the checker catches the errors it is meant to detect.

A separate demonstration finds, replays, and shrinks an intentional nearest-step rounding defect. The scripts place no orders and require no broker connection. When a check fails, we investigate the test machinery as well as the sizing rule; the failure alone does not identify which component is wrong.

Author: Sahil Bagdi