Order Error Code Decoder
MQL4's trade error codes are just integers, and the built-in constant names (ERR_INVALID_STOPS, ERR_TRADE_CONTEXT_BUSY, and so on) explain what happened without explaining what to actually do about it. This EA carries a decode table covering the common and the awkward codes - connection issues, request validation failures, and broker-side rejections - each with a plain sentence describing the likely cause and the concrete fix, not just a restatement of the constant name. An optional self test demonstrates the decoder live without any financial risk: both requests it sends are built to fail before they can ever reach the market - a lot size deliberately below the symbol's own minimum, and a stop loss pinned exactly at the current price - so every code produced is a genuine rejection with nothing ever filled. The self test is off by default and prints a plain warning when armed, because a program that calls OrderSend() at all deserves that regardless of how safe the specific calls are. DecodeError() and the OrderSendDecoded() wrapper are written to be useful beyond the demo: dropping OrderSendDecoded() in place of a direct OrderSend() call anywhere gives that call automatic plain language logging on every failure. Notes and limitations The decode table covers the documented error code set for each platform (MQL4's ERR_* codes, MQL5's TRADE_RETCODE_* enumeration); an uncommon or broker-specific code outside that set is reported with the raw number and a pointer to check the reference rather than a guessed explanation. The self test's two requests can occasionally succeed instead of failing on brokers with unusual minimum lot or stop level configuration - the EA detects that case and closes the resulting position immediately rather than leaving it open.
Expert advisor · MT4 · v1.0 · Free
About Order Error Code Decoder
Order Error Code Decoder is an expert advisor (trading robot) for MetaTrader 4. It has 3 settings, such as Run self test, Self test every min and Magic number. MQL source code included.
Files in the download: OrderErrorCodeDecoder.ex4, OrderErrorCodeDecoder.mq4, OrderErrorCodeDecoder.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Run self test | false | Send two deliberately invalid test requests to demonstrate live decoding (never fills - see header) |
| Self test every min | 5 | Minutes between self test cycles while armed |
| Magic number | 20261210 | Magic number used only by the self test's requests |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: MT4 Expert Advisor · MQL4 Source Code