Freeze Aware Modification Queue
A trailing-stop or breakeven routine that calls OrderModify every tick and just logs the failure when it lands inside STOPLEVEL or FREEZELEVEL gives up on that tick and never revisits it. The stop then only actually moves the next time an unrelated recalculation happens to try again from scratch - which, depending on the EA's structure, might be the next significant price move rather than the very next tick after the block clears, leaving the position under-protected for longer than it needed to be. This header keeps the request alive instead of discarding it. Enqueue(ticket, sl, tp) records the desired change once - either value can be FAMQ_UNCHANGED to touch only the other one - and Process(), called once per tick or on your own poll interval, re-checks the SAME freeze/stop-level test this catalogue's other trade-management headers use (freeze blocks outright regardless of direction, stop level is direction-specific, measured from the side the terminal actually checks against) and applies the change the moment it clears. A ticket that closes or gets deleted elsewhere while still queued is dropped silently - there is nothing left to modify, and "wait for it to become legal" has no meaning for a ticket that no longer exists. Notes and limitations - Process() sends real OrderModify calls once a queued item's ticket is legal to touch - this is an acting header, not a pure-computation one. Only enqueue values you actually want applied. - A legal-per-this-header's-own-check request can still be rejected by the server for an unrelated reason (requote, trade context busy). Such an item is left queued rather than dropped, so the next Process() call retries it - this is a feature, not a bug, but it means a persistently failing item stays in the queue until you Dequeue() it yourself if the underlying rejection reason never clears. - The queue is entirely in memory. It does not survive an EA recompile/restart/terminal restart - re-enqueue on OnInit from whatever state your EA already tracks if a queued change must survive one. - Only one change can be queued per ticket at a time; a second Enqueue() call for the same ticket replaces the first rather than stacking, since the latest request is the one that should fire, not an older superseded one.
Script · MT5 · v1.0 · Free
About Freeze Aware Modification Queue
Freeze Aware Modification Queue is an expert advisor (trading robot) for MetaTrader 5. It moves the stop loss behind price (trailing stop / break-even) and has a news filter. MQL source code included.
Files in the download: FreezeAwareModifyQueue.mq5.mqh, FreezeAwareModifyQueue.txt, FreezeAwareModifyQueueDemo.ex5, FreezeAwareModifyQueueDemo.mq5.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
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 · News Trading · MT5 Script · MQL5 Source Code