Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Librerie

CExecutionSafety - Ping + Execution Latency Guard for MQL5 EAs - libreria per MetaTrader 5

Visualizzazioni:
124
Valutazioni:
(2)
Pubblicato:
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

Overview

CExecutionSafety is a lightweight MQL5 include class designed to protect Expert Advisors from executing trades under poor network or execution conditions.
It measures two latency components live terminal ping and real wall-clock execution delay and blocks trade attempts when their combined value exceeds a configurable threshold.

The Problem It Solves

Most EAs execute blindly regardless of network conditions. A spike in ping or broker-side execution lag during a critical order can result in slippage, requotes, or failed fills.
CExecutionSafety introduces a pre-trade safety gate that prevents execution when conditions are degraded.

How It Works

The class uses two data sources:

  • TERMINAL_PING_LAST: reads the most recent ping recorded by MetaTerminal (in milliseconds)
  • RecordExecDelay(): accepts a wall-clock measurement you wrap around any CTrade operation

These two values are summed and compared against your configured threshold. If the combined latency exceeds the threshold, CheckExecutionSafety() returns false and prints a diagnostic log entry.
Figure 1: Terminal_Ping_Last

Disconnection Guard

When the terminal has no server contact, TERMINAL_PING_LAST returns -1. The class detects this and automatically returns false, preventing trade attempts on a disconnected terminal.

Integration Example

Include the file and instantiate the class in your EA:

#include <DeeFX/CExecutionSafety.mqh> CExecutionSafety safety; int OnInit() { safety.Init(150); // 150ms combined threshold return INIT_SUCCEEDED; } void OnTick() { if(!safety.CheckExecutionSafety()) return; ulong t0 = GetTickCount64(); trade.PositionClose(ticket); safety.RecordExecDelay(GetTickCount64() - t0); }

Accessors

The following read-only accessors are available for dashboard display or external logic:

  • GetPingMs(): current terminal ping in ms
  • GetExecDelayMs(): last recorded execution delay in ms
  • GetCombinedMs(): ping + exec delay combined (returns 9999 if disconnected)
  • HasExecSample() : true once at least one measurement has been recorded
  • GetThresholdMs(): configured safety threshold

Changelog

  • v1.0 — Initial release
  • v1.1 — Guard macro renamed. %I64u format specifiers replaced with (string) casts
  • v1.2 — Init() return type changed void → bool. State reset on reinit to prevent stale samples
Combine Multi Timeframe Trends into one trend using MA. Combine Multi Timeframe Trends into one trend using MA.

Combine Multi Timeframe Trends into one trend using MA.

Previous Day highs and lows Previous Day highs and lows

Draws the previous day High, Low, and Close as horizontal reference lines on the chart for a configurable number of past days. Yesterday's levels extend into today as live support and resistance, with optional touch alerts.

CLatencyMonitor -  Inter-Tick Latency Tracker with ATR Volatility Gate and GlobalVariable IPC for MQL5 EAs CLatencyMonitor - Inter-Tick Latency Tracker with ATR Volatility Gate and GlobalVariable IPC for MQL5 EAs

Include-file class that measures inter-tick latency, filters false alarms via a self-normalising ATR volatility gate, and broadcasts persistent lag alerts to other EAs via GlobalVariable IPC.

MACD Signals MACD Signals

Indicator edition for new platform.