Modification Burst Batcher
MQL4 has exactly one trade context for the whole terminal, shared across every EA and every order. A trailing routine that walks the order pool and fires OrderModify() on every eligible order back to back is a common way to trip ERR_TRADE_CONTEXT_BUSY on the later calls in the sweep, especially with several EAs or a large order count on the same account - the calls that fail are exactly the stops that most needed to move. This EA rebuilds a modification queue each pass from the current order pool: any order (subject to an optional magic filter) that has moved far enough into profit to start trailing, and whose computed new stop would be a real improvement over its current one past a minimum-change threshold, gets queued. It then drains only a bounded number of entries from that queue per pass, waiting out IsTradeContextBusy() before each call and pausing a configurable interval between successful modifications. Anything left in the queue simply gets rebuilt and reconsidered next pass - there is no separate "pending" state to lose track of. A transient failure (busy context, requote, timeout) is retried a bounded number of times before being logged as given up for that pass; a permanent failure (e.g. invalid stops) is not retried at all, since retrying it would only waste the burst budget on something that cannot succeed. Notes and limitations The stop is only ever moved in the trade's favour - toward locking in more profit - never loosened, and never placed inside the broker's own stop-level distance for that symbol. Sleep() calls used to pace the burst and to wait out a busy trade context block this EA's own event processing for their duration. At the default settings that is a few hundred milliseconds at most per pass, not a concern in practice, but very large InpBurstIntervalMs or InpMaxRetryAttempts values would extend it. Anything left unmodified after a burst is simply picked up again next pass - there is no guarantee every eligible order is trailed within any specific time bound if the order count consistently exceeds InpMaxModificationsPerBurst per InpPollSeconds. This EA never opens or closes a position - it only modifies the stop-loss of orders that already exist.
Expert advisor · MT5 · v1.0 · Free
About Modification Burst Batcher
Modification Burst Batcher is an expert advisor (trading robot) for MetaTrader 5. It increases the lot size after a losing trade (martingale), moves the stop loss behind price (trailing stop / break-even) and has a news filter. It has 8 settings, such as Trail start pips, Trail distance pips and Min change pips. MQL source code included.
Files in the download: ModificationBurstBatcher.ex5, ModificationBurstBatcher.mq5, ModificationBurstBatcher.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 |
|---|---|---|
| Trail start pips | 15.0 | Profit, pips, before trailing begins for a position |
| Trail distance pips | 10.0 | Stop distance behind price once trailing is active |
| Min change pips | 1.0 | Minimum SL improvement, pips, before a position is queued |
| Magic filter | 0 | Only manage this magic number, 0 = every position |
| Max modifications per burst | 3 | Cap on PositionModify calls per timer tick |
| Burst interval ms | 200 | Pause between modifications within a burst, milliseconds |
| Poll seconds | 1 | How often the queue is rebuilt and a burst is drained |
| Max retry attempts | 3 | Retries for a modification that hits a retryable error |
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 → Experts.
- 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 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 · Martingale · News Trading · MT5 Expert Advisor · MQL5 Source Code