Loading…

Error Code Decoder

Working out what a numeric error or result code actually means usually costs a trip to the documentation, and working out what to DO about it - retry, change the request, or give up - is left entirely to the developer, every single time, for the same handful of conditions that come up again and again: server busy, requote, off quotes, invalid stops, invalid volume, trading disabled, not enough money, market closed, timeout, price changed, too many requests. On MQL4, all of that comes back from GetLastError() after OrderSend, and the MQL4 half of this submission decodes it directly: ErrorDescription returns the plain-English explanation, ErrorSuggestedResponse returns a short, consistent verdict, IsRetryableTradeError gives the same verdict as a bool, and ErrorSummary combines all of it into one line ready for Print(). MQL5 moved this entire layer, which is why the MQL5 half of this submission is a genuine rewrite rather than a syntax port. A broker's accept/reject verdict on a trade request no longer comes back through GetLastError() at all - it arrives as the retcode field of the MqlTradeResult struct (or CTrade::ResultRetcode() when using the standard trade class), using the TRADE_RETCODE_* enumeration. GetLastError() on MQL5 mostly only confirms whether the terminal-side API call itself failed to fire, not what the broker decided about a request that did fire. A caller who kept calling GetLastError() the MQL4 way after moving to MQL5 would silently stop seeing requotes, invalid stops, no-money and every other broker-side rejection, because that information now lives somewhere else entirely. The MQL5 header therefore centres on TradeRetcodeDescription, decoding the full TRADE_RETCODE_* range with the same plain-English intent as the MQL4 table, plus TradeRetcodeSuggestedResponse, IsRetryableTradeRetcode and TradeRetcodeSummary - direct counterparts to the MQL4 functions, just keyed on the code that actually carries the information on this platform. Every switch in the MQL5 header is keyed on the built-in TRADE_RETCODE_* named constants rather than a memorised numeric literal, so the table's accuracy rests on the compiler's own definitions, not on a number copied down by hand. A slimmer ErrorDescription(code) is kept on the MQL5 side too, for the residual case of confirming GetLastError() is clean. Notes and limitations - MQL4 side: the table focuses on trade-relevant codes. General runtime errors unrelated to trading (array bounds, file I/O, string conversion) are not included - use the platform documentation for those. - MQL5 side: TradeRetcodeDescription covers the full TRADE_RETCODE_* range as defined by the terminal build this was compiled against. A future terminal build that adds new retcodes falls through to the generic "unlisted retcode" message, which still includes the numeric value, so a gap in coverage never hides information. - MQL5's ErrorDescription(code) deliberately stays shallow. It reports whether GetLastError() is 0 (clean) or not; it does not attempt a full general-runtime-error table the way the MQL4 header's 4106-4111 entries do, because MQL5's general error range is large and this header was not built or tested against every entry in it - an honest "not decoded here" is safer than a guessed description. - Both suggested-response verdicts are a starting point, not a guarantee. A "retry" verdict still needs a retry limit around it; retrying forever on a broker that is genuinely down is its own bug. Pair either platform's header with a bounded retry loop. - Codes/retcodes are matched by exact value (name on MQL5, number on MQL4). A broker that returns a non-standard or vendor-specific code falls through to the generic "unlisted" message on either platform. - No money-per-point or contract-size calculation appears anywhere in this header on either platform - it decodes codes only, so the tick-value/ contract-size scaling this catalogue's house style calls out for money calculations does not apply here.

Script · MT5 · v1.0 · Free

About Error Code Decoder

Error Code Decoder is an expert advisor (trading robot) for MetaTrader 5. MQL source code included.

Files in the download: ErrorDescription.mq5.mqh, ErrorDescription.txt, ErrorDescriptionDemo.ex5, ErrorDescriptionDemo.mq5.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Volume · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria