Skip to content
All library documents

A Compile-Time Assertion Framework for Testing MQL5 Trading Utilities

Article MQL5 articles

Summary

This article presents a lightweight unit-testing framework for MQL5 utility functions, designed to run as a standard script and report results in the terminal. Preprocessor assertion macros record expected and actual values along with the source file and line of each check. An interface groups related tests into suites, while a runner executes registered suites, collects outcomes, and formats a summary.

The examples focus on defects in trading calculations, including floating-point comparisons, lot-step rounding, broker digit conventions, currency-pair inversions, and invalid inputs. The article distinguishes exact equality checks from tolerance-based checks for decimal calculations, and explains how invalid-input behavior is checked using a flag or sentinel because MQL5 lacks conventional exceptions. Its evidence is an illustrative framework and sample test targets, rather than a measured reduction in production failures. The approach validates utility behavior for chosen cases; it does not establish that a strategy or its risk assumptions are sound.

Key ideas

  • Tolerance-based assertions are appropriate for floating-point financial calculations, while exact comparisons suit discrete outputs.
  • Test cases should cover lot-step boundaries, varying quote precision, currency conversions, and invalid inputs.
  • Preprocessor metadata lets assertion failures report the source location where each check was made.
  • Interfaces and a runner organize test suites and collect structured results in an MQL5 script.
  • The framework checks selected code behavior but cannot validate a trading strategy’s overall assumptions.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.