OCO Order Manager
RISK WARNING: this EA sends live pending orders and can open a real market position the instant one leg fills. Confirm InpLots, the stop distance and the straddle distance on a demo account before running it live. MT4 has no native one-cancels-other order type - a straddle placed by hand is two independent pending orders, and if the trader forgets to cancel the one that did not fill, it can sit on the book and trigger later at a price that no longer makes sense for the trade. This EA deploys both legs together under one magic number and watches them: the moment either leg is no longer an open pending order, the other is cancelled if it is still pending. "No longer open" deliberately covers more than a fill. A true OCO pair means whichever side leaves the pool first, for any reason, cancels its partner - so an expired or manually deleted leg cancels the other side just as a filled leg does. Treating a fill as the only trigger would leave an orphaned pending order sitting on the book after the untouched side simply expired on its own. If only one leg can be sent - the broker rejects the other, for instance - the lone leg is deleted rather than left live. A single unhedged pending order is not the OCO pair the trader asked for, and leaving it in place would silently change the trade's risk profile. Notes and limitations - There is an unavoidable gap between one leg resolving and the other being cancelled, bounded by InpScanIntervalSec - in the rare case both legs are triggered within that same window (a large gap move), both could fill before the cancellation reaches the broker. - This EA only manages the pair it deploys itself; it does not adopt or manage pre-existing pending orders placed by hand or by another EA. - If InpDistancePips places a leg inside the broker's minimum stop distance from current price, deployment is skipped entirely rather than sending an order the broker would reject - widen the distance and try again. - On a netting MQL5 account, this EA will not deploy (or redeploy) a pair while a foreign-magic position already sits on the chart symbol - see the differences section above.
Expert advisor · MT4 · v1.0 · Free
About OCO Order Manager
OCO Order Manager is an expert advisor (trading robot) for MetaTrader 4. It places pending buy/sell stop or limit orders. It has 11 settings, such as Base price, Distance pips and Lots. MQL source code included.
Files in the download: OcoManager.ex4, OcoManager.mq4, OcoManager.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 |
|---|---|---|
| Base price | 0.0 | Centre price for the straddle, 0 = current market price at deployment |
| Distance pips | 20 | Distance of each leg from the centre price, in pips |
| Lots | 0.01 | Lot size for each leg |
| Stop loss pips | 50 | Stop-loss per leg, in pips from that leg's own entry (0 = none) |
| Take profit pips | 40 | Take-profit per leg, in pips from that leg's own entry (0 = none) |
| Expiry hours | 24 | Pending order expiry, hours (0 = good till cancelled) |
| Redeploy after resolution | false | Deploy a fresh pair around current price once this one resolves |
| Magic number | 20260702 | Magic number for both legs of this pair |
| Max retries | 5 | Attempts per order action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Scan interval sec | 10 | Seconds between checks - kept short to cancel the partner promptly |
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: Pending Orders · MT4 Expert Advisor · MQL4 Source Code