Loading…

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

SettingDefaultWhat it does
Trail start pips15.0Profit, pips, before trailing begins for a position
Trail distance pips10.0Stop distance behind price once trailing is active
Min change pips1.0Minimum SL improvement, pips, before a position is queued
Magic filter0Only manage this magic number, 0 = every position
Max modifications per burst3Cap on PositionModify calls per timer tick
Burst interval ms200Pause between modifications within a burst, milliseconds
Poll seconds1How often the queue is rebuilt and a burst is drained
Max retry attempts3Retries for a modification that hits a retryable error

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: Trailing Stop & Break-even · Martingale · News Trading · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria