Broker Error Statistics Collector
"Retry three times, then give up" treats every broker, every symbol and every kind of failure identically, and the number three is almost always copied from another EA rather than measured against how this account and this broker actually behave. Two accounts can have completely different failure profiles - one might see occasional requotes clustered around a news-heavy hour, another might see a broker that rejects far more send attempts than modifies - and a single hardcoded retry count cannot adapt to either. This header just counts, in memory: RecordAttempt(opType) marks one attempt of a given operation (send, modify, close or delete), and RecordError(opType, errorCode) marks one failure with the actual broker/ terminal error code, typically read straight off GetLastError() in the branch where the trade call returned false. Both are timestamped and bucketed by hour of day. From that small histogram, GetMostCommonError() answers "what usually goes wrong on this operation", GetErrorRate() answers "what fraction of attempts actually fail" (returning -1.0 rather than 0.0 when there is no data yet, since those two mean genuinely different things), and GetHourlyErrorCounts() exposes the full 24-hour trend for a caller that wants to reason about, say, avoiding new entries during a historically bad hour rather than just retrying blindly through it. Notes and limitations - Entirely in-memory. Data does not survive an EA recompile/restart/ terminal restart - this header collects evidence for the CURRENT running session, not a persistent audit log. Layer your own file-based logging on top if you need history to survive a restart. - RecordError() alone, without a matching RecordAttempt(), makes GetErrorRate() meaningless for that operation - always pair the two so the denominator is real. - The error-code space is intentionally open-ended (broker-specific codes are accepted as plain integers) rather than restricted to the standard ERR_* constants, since some brokers do return codes outside that set. - GetMostCommonError()/GetHourlyErrorCounts() summarise WHAT and WHEN failures happened; they say nothing about WHY, and are not a substitute for reading the actual error code's documented meaning before deciding a retry policy.
Script · MT5 · v1.0 · Free
About Broker Error Statistics Collector
Broker Error Statistics Collector is a script for MetaTrader 5. MQL source code included.
Files in the download: BrokerErrorStats.mq5.mqh, BrokerErrorStats.txt, BrokerErrorStatsDemo.ex5, BrokerErrorStatsDemo.mq5.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: News Trading · MT5 Script · MQL5 Source Code