Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 4 Libraries | ErrorHandler - Trade Error Classifier for MQL4 | Source Code Included

New free code from MQL5: indicators, EAs, and scripts for traders.

Image for ErrorHandler - Trade Error Classifier for MQL4

CErrorHandler is a robust, self-contained trade error classifier and automated recovery framework designed for MQL4 Expert Advisors.


### Features
- Maps MQL4 trade server return codes onto five distinct recovery actions (IGNORE, RETRY, WAIT, STOP_EA, ALARM).
- Tracks repeat-failure series per individual error code with configurable escalation limits.
- Implements integer-based exponential back-off delays to prevent EA thread blocking and eliminate busy-loops.
- Provides built-in diagnostic hints for error codes that are frequently misread or mishandled (e.g., ERR_INVALID_STOPS, ERR_TRADE_TOO_MANY_ORDERS).

### Minimal Usage
#include "ErrorHandler.mqh"
CErrorHandler g_err("MyEA");

for(int attempt = 0; attempt < 10; attempt++)
{
ResetLastError();
int ticket = OrderSend(...);
if(ticket >= 0) { g_err.ResetRetry(); break; }

switch(g_err.Handle(GetLastError(), "OrderSend BUY"))
{
case EH_ACTION_RETRY:
case EH_ACTION_WAIT: continue;
case EH_ACTION_ALARM: continue;
case EH_ACTION_STOP_EA: ExpertRemove(); return;
case EH_ACTION_IGNORE: break;
}
}

Reduce lag and improve accuracy with the NonLagMA Expert Advisor for MT4/MT5. Discover it.

Thanks for reading. Discover premium MetaTrader solutions at RobotFX.

77027

Best MetaTrader Indicators + Profitable Expert Advisors