Skip to content
All library documents

Using Finite-State Automata to Structure Trading System Logic

Article MQL5 articles

Summary

This article advocates finite-state automata as a way to design and implement Expert Advisor logic. It argues that informal design notes, a developer’s mental model, and program code can diverge, making complex behavior hard to review and maintain. The proposed approach identifies program states explicitly, represents transitions between them, and implements the control flow through a single multi-valued state variable and switch-based structure.

The article frames unspecified combinations of control conditions as a source of unreliable behavior, including failures around gaps, margin calls, and position handling. It recommends defining the states and possible transitions during design, then using a mathematical model, graphical notation, and consistent implementation method to keep the specification aligned with code. The discussion is conceptual and illustrative rather than a tested trading system or performance study. It provides no measured comparison against other programming approaches, and explicit state modeling still depends on correctly identifying relevant states and transitions.

Key ideas

  • A finite-state model makes an Expert Advisor’s control states and transitions explicit.
  • The article argues that code and design documents can diverge when developers rely on informal mental models.
  • A single state variable can organize control flow through cases for each defined state.
  • Unspecified combinations of control conditions may lead to unexpected or unsafe program behavior.
  • The method supports design, implementation, debugging, and documentation, but the article gives no comparative performance evidence.

Tags

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