Error Breadcrumb Context
GetLastError() alone tells you what went wrong, never where in the logic it happened. A trade-server error 130 (invalid stops) could come from a dozen different call sites in a larger EA, and the Journal line by itself does not say which validation step let a bad stop distance through. Reproducing the path by hand from a bare error code and a timestamp is slow, especially once an EA has grown past a handful of functions. This header keeps a small fixed-size ring buffer of breadcrumb labels. EbcPush records a short string at each meaningful step ("checking margin", "sending order", "validating stops"); EbcBuildErrorReport combines an error code, its description (via the standard stdlib.mqh ErrorDescription function), and the current trail into one report string worth actually logging or alerting on. EbcClear resets the trail at the start of a fresh logical operation (typically the top of OnTick) so an old trail never leaks into a report for an unrelated later error. Notes and limitations Fixed ring capacity of 16 breadcrumbs (EBC_MAX_TRAIL) - pushing further silently overwrites the oldest entry rather than growing or erroring, so this is a bounded recent-history trail, not a complete step-by-step log of an entire run. The trail is a single global buffer, not per-function or per-thread scoped (MQL4 is single-threaded per program instance, so this is not a concurrency concern, but two unrelated logical operations that forget to call EbcClear between them will show a mixed trail). Depends on the standard stdlib.mqh library shipped with every MetaTrader installation for ErrorDescription() - this is the platform's own standard library, not another catalogue project, so it does not break self-containment.
Script · MT4 · v1.0 · Free
About Error Breadcrumb Context
Error Breadcrumb Context is an expert advisor (trading robot) for MetaTrader 4. It moves the stop loss behind price (trailing stop / break-even). It has 1 setting, such as Simulated error code. MQL source code included.
Files in the download: ErrorBreadcrumbContext.mqh, ErrorBreadcrumbContext.txt, ErrorBreadcrumbContextDemo.mq4.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Simulated error code | ERR_INVALID_STOPS | error code the demo reports on |
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: Trailing Stop & Break-even · MT4 Script · MQL4 Source Code