Loading…

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 · MT5 · v1.0 · Free

About OCO Order Manager

OCO Order Manager is an expert advisor (trading robot) for MetaTrader 5. 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.ex5, OcoManager.mq5, OcoManager.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Base price0.0Centre price for the straddle, 0 = current market price at deployment
Distance pips20Distance of each leg from the centre price, in pips
Lots0.01Lot size for each leg
Stop loss pips50Stop-loss per leg, in pips from that leg's own entry (0 = none)
Take profit pips40Take-profit per leg, in pips from that leg's own entry (0 = none)
Expiry hours24Pending order expiry, hours (0 = good till cancelled)
Redeploy after resolutionfalseDeploy a fresh pair around current price once this one resolves
Magic number20260702Magic number for both legs of this pair
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds
Scan interval sec10Seconds between checks - kept short to cancel the partner promptly

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: Pending Orders · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria