What Are OCO Orders and Why You Need Them
OCO stands for One-Cancels-Other, also known as a bracket order. It is the combination of a stop loss and a take profit placed around an open position, linked so that when one fills, the other is automatically cancelled. This is the standard risk management pattern used by professional traders across every asset class.
The concept is simple: you have a long position in BTCUSDT. You want to exit at +5% profit (take profit) or cut your loss at -2% (stop loss). You place both orders simultaneously. Price moves up and hits your take profit. The exchange fills your TP order. Now, the critical question: what happens to the stop loss order that is still sitting on the order book?
Without OCO, that stop loss order remains active. If you open a new position later, or if the market reverses after your TP filled, that orphan stop loss can trigger unexpectedly. You might find yourself in a short position you never intended to open, or your new long position gets stopped out by a stale order from a previous trade. Orphan orders are one of the most common causes of unexpected losses in automated trading.
The orphan order problem
A study of automated trading failures shows that orphan orders account for a significant portion of unintended trades. The scenario is always the same: a take profit fills, the stop loss is forgotten, and it triggers hours or days later on a completely different market context. OCO eliminates this entire category of risk.
OCO solves this definitively. The two orders are linked. When either one fills, the other is immediately cancelled. No orphans, no surprises, no manual cleanup. Your position goes from open-and-protected to closed-and-clean in a single atomic operation.
The Problem: Most Webhook Tools Do Not Support OCO
Most TradingView webhook automation tools treat stop loss and take profit as separate, independent operations. You send one webhook to place the stop loss, another webhook to place the take profit, and there is no link between them. When one fills, you need a third webhook (or manual intervention) to cancel the other.
This creates a cascade of problems for automated strategies:
- Race conditions on cancellation: Your TradingView alert fires to cancel the SL after TP hits, but the webhook arrives 500ms-30s later. In that window, the orphan SL can trigger.
- No fill detection: Most tools cannot detect that one side of the bracket has filled. They rely on you to send a cancellation webhook, which means your Pine Script needs complex state management.
- Exchange limitations: Some exchanges, like ByBit in hedge mode, do not support native OCO orders via their API. Tools that rely purely on the exchange for OCO simply cannot offer it on these platforms.
- Multiple alerts per trade: Instead of one alert that handles everything, you need 3-4 alerts per trade: entry, SL, TP, and cancellation logic. This multiplies complexity and failure points.
The result is that many traders either skip OCO entirely (leaving orphan orders as a known risk) or spend hours building complex Pine Script logic to manage the state machine of entry, protection, and cleanup. Neither approach is acceptable for serious automated trading.
How Flipr.Cloud Solves OCO
Flipr.Cloud offers two OCO mechanisms that work together to provide universal bracket order support across every exchange. The system automatically selects the best approach based on exchange capabilities. You never need to know which mechanism is being used. Your syntax is the same everywhere.
Native Exchange OCO
On exchanges that support conditional TP/SL orders natively (Binance, ByBit, OKX, Kraken, and most major platforms), Flipr places the stop loss and take profit directly on the exchange's matching engine as linked conditional orders. The exchange itself handles the cancellation when one side triggers.
- Sub-millisecond cancellation by the exchange's internal engine
- Orders survive even if Flipr goes offline (exchange-grade protection)
- Zero polling overhead, zero additional API calls
- The gold standard for bracket order execution
Smart OCO (Flipr Monitoring)
On exchanges that lack native OCO support, or in scenarios where the native mechanism is unreliable, Flipr activates Smart OCO. This is a background monitoring system that runs on Flipr's servers. It places both orders as separate limit/stop orders on the exchange, then polls their status continuously. When one order fills, Flipr immediately cancels the other.
- Works on every exchange regardless of native OCO support
- Polling interval of 1-2 seconds ensures rapid cancellation
- Both orders live on the exchange (protected if bot is offline)
- Automatic fallback when native OCO is unavailable
Both approaches, one syntax
You never need to specify which OCO mechanism to use. Flipr detects exchange capabilities at connection time and automatically routes to the optimal path. The same webhook command produces native OCO on Binance and Smart OCO on CoinEx, transparently.
Setting Up OCO via Webhook
There are three methods to create OCO bracket orders with Flipr. Each serves a different use case, and all three produce the same result: a position protected by linked SL and TP orders.
Method 1: Inline SL/TP with Market Order
The simplest and most common approach. Add sl and tp parameters directly to your market order. Flipr opens the position and immediately places both exit orders as an OCO pair.
Inline OCO (recommended)
This single command opens a 0.01 BTC long, places a stop loss at 2% below fill price, and a take profit at 5% above fill price. When either exit triggers, the other is cancelled. Total execution time: approximately 150-300ms for all three orders.
Method 2: Explicit sl-or-tp Command
Use sl-or-tp to add an OCO bracket to an existing open position. This is useful when you opened a position with a previous webhook and want to add protection later, or when your strategy logic separates entry and exit management.
Explicit OCO on existing position
The 100%p targets 100% of the current position size. The tp off 5% and sl off 2% define the exit levels as offsets from the current market price. Both orders are linked as an OCO pair.
Method 3: Separate Commands with Tag Grouping
For advanced strategies that need maximum control, you can place individual stoploss and takeprofit commands in a multi-line webhook. Flipr automatically groups them as OCO when they target the same position.
Multi-line OCO with separate commands
This approach gives you full control over each order's parameters independently. The market order opens the position, then the stoploss and takeprofit commands place the exit orders. Flipr detects that both target the same position and links them as OCO.
When to use each method
Method 1 (inline) is best for 90% of use cases: clean, concise, single-line. Method 2 (sl-or-tp) is ideal when adding protection to an existing position. Method 3 (separate commands) provides maximum flexibility for complex strategies with different SL and TP quantity allocations.
OCO with Multiple Take Profits
Professional traders rarely exit a position at a single price level. The standard approach is to scale out: close a portion of the position at the first target, another portion at the second, and let the remainder run toward a final target. This locks in partial profits while maintaining exposure for larger moves.
Smart Syntax supports multiple take profit levels in a single webhook. Each take profit specifies what percentage of the position to close at that level.
Scaling out with 3 take profit levels
This opens a 0.03 BTC long position, then places three take profit orders:
- First TP at +3%: Closes 33% of the position (0.01 BTC), locking in early profit
- Second TP at +5%: Closes another 33% (0.01 BTC), securing additional gains
- Final TP at +8%: Closes the remaining position, capturing the full move
The stop loss at 2% covers 100% of the position. As each take profit fills, the stop loss quantity is effectively reduced to match the remaining position size. If the stop loss triggers before any TPs, the entire position is closed and all pending TP orders are cancelled.
50/50 scaling with entry-relative levels
Partial profits, full protection
Multiple take profits with a single stop loss is one of the most effective risk management patterns in crypto trading. You secure guaranteed profits at the first target while keeping upside exposure. Many professional traders report that scaling out improves their risk-adjusted returns by 15-30% compared to single-exit strategies.
How Smart OCO Monitoring Works
Smart OCO is Flipr's background monitoring system that ensures bracket order integrity on exchanges that do not support native OCO. Understanding how it works helps you appreciate the reliability of your automated risk management.
When Flipr creates an OCO pair, it registers both orders in an internal tracking system. A background task continuously polls the exchange to check the status of each tracked order. The polling cycle works as follows:
- Order registration: Both the SL and TP orders are placed on the exchange and their IDs are stored in the OCO tracking database.
- Continuous polling: The monitor checks order status every 1-2 seconds, querying the exchange API for fill status.
- Fill detection: When one order's status changes to "filled" or "partially filled," the monitor triggers the cancellation workflow.
- Paired cancellation: The remaining order in the OCO pair is cancelled via the exchange API. The OCO group is marked as resolved.
- Confirmation: The monitor verifies the cancellation was successful. If the cancel fails (network glitch), it retries automatically.
1-2s Polling
Order status checked every 1-2 seconds. Rapid detection ensures minimal exposure to orphan orders.
Auto-Retry
Failed cancellations are automatically retried. Network glitches do not leave orphan orders behind.
Exchange-Safe
Both orders live on the exchange. Even if Flipr's monitor goes offline, your SL and TP remain active.
Orders survive outages
A key design principle of Smart OCO is that both orders are placed on the exchange, not held in memory. If Flipr's monitoring service restarts or experiences downtime, your stop loss and take profit remain active on the exchange. The only risk during downtime is a delayed cancellation of the paired order, not the loss of protection itself.
Exchange Compatibility
Every exchange supported by Flipr works with OCO orders. The table below shows which exchanges use native OCO (handled by the exchange's matching engine) and which use Smart OCO (monitored by Flipr). Your syntax is identical regardless of the mechanism.
Binance
Native OCO
ByBit
Native OCO
OKX
Native OCO
BloFin
Native OCO
Bitget
Native OCO
Kraken
Native OCO
KuCoin
Native OCO
HTX
Native OCO
Phemex
Native OCO
Bitunix
Native OCO
Toobit
Native OCO
Bitfinex
Native OCO
CoinEx
Smart OCO
BitMEX
Smart OCO
MEXC
Smart OCO
Universal OCO support
Regardless of which exchange you use, OCO always works with Flipr. Native OCO provides instant cancellation by the exchange. Smart OCO adds 1-5 seconds of cancellation delay but works on every platform. You never need to check compatibility or change your commands.
