CExecutionSafety - Ping + Execution Delay Protection for MQL5 EA - MetaTrader 5 Library


CExecutionSafety is a lightweight MQL5 included class designed to protect Expert Advisors from executing transactions under poor network or execution conditions.
It measures two latency components: real-time terminal ping and real wall-clock execution latency, and blocks transaction attempts when their combined value exceeds a configurable threshold.
Most EAs will execute blindly regardless of network conditions. Spikes in ping or broker-side execution latency during critical orders can result in slippage, requotes, or execution failures.
CExecutionSafety introduces a pre-trade safety gate that blocks execution if conditions deteriorate.
This class uses two data sources:
The two values are added and compared to your configured threshold. If the combined latency exceeds the threshold, CheckExecutionSafety() returns false and prints a diagnostic log entry.

TERMINAL_PING_LAST returns -1 when the terminal has no server contact. The class detects this and automatically returns false, preventing transaction attempts on disconnected terminals.
Include the file and instantiate the class in your EA:
#include
The following read-only accessors can be used for dashboard display or external logic:
Attachment download
📎 CExecutionSafety.mqh (3.76 KB)
Source: MQL5 #70033
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •