2. Entry management (advanced): a pair of pending entry orders bracketing the current price. Example: with price at 1.1000, place a buy-stop at 1.1020 and a sell-stop at 1.0980. When price breaks out in either direction, one order fills and the other is cancelled. This is a classic breakout-entry pattern.
3. Conditional logic (rare): more complex OCO chains can implement decision trees — buy at one level if X happens, sell at another level if Y happens, all linked so only one executes.
MetaTrader implementation:
- Position SL/TP: automatic OCO. When one is hit, the position closes and the other is irrelevant.
- Pending order pairs: MetaTrader does not natively link pending orders as OCO. Implementation requires EA logic to monitor pending orders and cancel paired orders when one executes. The EA tracks order IDs of paired orders and triggers cancellation on fill event.
Use cases:
- Breakout entry: buy-stop above current range, sell-stop below. EA monitors fills; on either fill, cancels the other.
- Range trading: buy-limit at range low, sell-limit at range high. On range exit (either order fills), cancel the other.
- Stop-and-reverse strategies: position with SL, plus pending opposite-direction entry at the SL distance. If SL is hit (position closes), the reverse entry fills automatically.
Implementation considerations:
- Timing: OCO requires near-instant cancellation when the paired order fills. EA must monitor order fills and issue cancellation requests within milliseconds.
- Partial fills: if one order partially fills while the other is also active, the EA must decide whether to cancel the unfilled remainder of the paired order or wait for full fill.
- Slippage: in fast markets, both OCO orders might fill before cancellation reaches the broker. EA must handle the unlikely case of both orders executing.
- Reliability: network delays between EA and broker can produce edge cases where one fills but cancellation doesn't reach the broker in time. Robust EAs include reconciliation logic that checks position state after expected OCO events.