Skip to content
All library documents

Guarding MQL5 Trades Against High Latency and Disconnection

Article MQL5 code base

Summary

This document describes an MQL5 class that acts as a pre-trade execution gate for Expert Advisors. It reads the terminal’s latest server ping and combines that figure with a wall-clock execution delay recorded around a trade operation. If the combined latency exceeds a configured threshold, the check rejects the trade attempt and logs a diagnostic message.

The guard also blocks trades when the terminal reports no server contact. Read-only accessors expose the ping, latest execution delay, combined value, threshold, and whether an execution sample has been recorded. The document outlines integration and version changes, including resetting stored state on reinitialization. It explains the mechanism but provides no performance tests or evidence that a chosen threshold prevents losses; the threshold and the timing of measurements require appropriate configuration for the trading environment.

Key ideas

  • The guard combines terminal ping with a measured wall-clock delay around a trade operation.
  • Trade attempts are blocked when combined latency exceeds the configured threshold.
  • A missing server connection also causes the safety check to reject trading.
  • Accessors expose latency readings, the threshold, and whether an execution sample exists.
  • The document describes implementation behavior but gives no empirical evaluation of its effectiveness.

Tags

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