CLatencyMonitor is a lightweight MQL5 include-file library ( #include ) developed by DeeFX Precision Labs as part of the LagShield Pro product suite. It provides three tightly integrated capabilities in a single reusable class:
Drop the file into MQL5/Include/DeeFX/ and add a single #include to any EA or service that needs latency awareness.
Execution-sensitive EAs can suffer silent fill degradation or risk miscalculation when the terminal's tick feed lags behind the market. Standard MQL5 provides no built-in mechanism to:
CLatencyMonitor addresses all three gaps with a single, dependency-free class.
Inter-tick delta
On every call to OnTick() , the class computes the elapsed milliseconds since the previous tick. The first tick is used only to seed the timer — no spurious alert is raised at startup.
ATR volatility gate
Before declaring a lag, the class checks whether the current ATR value exceeds AtrSmaMultiplier × SMA(ATR, AtrPeriod) . The SMA is calculated manually from the raw ATR buffer, making the threshold instrument-agnostic and self-normalising across all pairs and timeframes. If the ATR handle is unavailable or history is insufficient, the gate fails open (lag detection remains active) so protection is never silently disabled.
Persistence and GlobalVariable IPC
A repeating timer calls CheckPersistence() . Once a lag condition has remained active for longer than PersistenceSec seconds, the class performs a read-before-write check on the named GlobalVariable "Terminal_Lag_Detected" and sets it to 1.0 only if no other EA has already claimed it. Ownership is tracked internally; when the lag clears, only the owning instance resets the flag.
Clean lifecycle
Init() resets all timing and lag state, preventing stale values across OnDeinit / OnInit cycles. Deinit() releases the ATR indicator handle and deletes the GlobalVariable only if owned. The destructor is intentionally empty — explicit resource management follows the MQL5 standard.
#include <DeeFX/CLatencyMonitor.mqh> input ulong InpLagThresholdMs = 500; input int InpPersistenceSec = 3; input int InpAtrPeriod = 14; input double InpAtrSmaMultiplier = 1.5; CLatencyMonitor g_latency; int OnInit() { if(!g_latency.Init(InpLagThresholdMs, InpPersistenceSec, InpAtrPeriod, InpAtrSmaMultiplier, _Symbol, _Period)) return INIT_FAILED; EventSetTimer(1); // 1-second timer for persistence checks return INIT_SUCCEEDED; } void OnDeinit(const int reason) { EventKillTimer(); g_latency.Deinit(); } void OnTick() { bool newLag = g_latency.OnTick(); if(newLag) Comment("DeeFX | LAG DETECTED — trade execution paused"); } void OnTimer() { bool persistent = g_latency.CheckPersistence(); if(persistent) Alert("DeeFX | Persistent lag > ", InpPersistenceSec, "s — GV flag set"); if(!g_latency.IsLagActive()) Comment(""); }
Any other EA on the same terminal can read the shared flag independently:
// In a second EA — no include required if(GlobalVariableGet("Terminal_Lag_Detected") >= 1.0) Print("Terminal lag signal received — skipping order placement.");
Init() parameters
Public methods
Read-only accessors
GlobalVariable IPC
CExecutionSafety - Ping + Execution Latency Guard for MQL5 EAs
Include class that validates combined terminal ping + execution latency before trade operations. Returns false if threshold is exceeded.
Combine Multi Timeframe Trends into one trend using MA.
Combine Multi Timeframe Trends into one trend using MA.
ExMachina SafeScalping
ExMachina Safe Scalping is a professional-grade Expert Advisor built for conservative breakout scalping on Gold (XAUUSD), Silver (XAGUSD), and Forex majors.
Last Structure Indicator : LSB Explorer
This is an experimental Last Structure Break (LSB) price action indicator that uncovers meaningful market structures and potential trading edges through intelligent support and resistance analysis.