Orders & positions
Order & Position Filtering
Filtering of Orders and Positions
It is always recommended to use testnet/sandbox first!
Filtering of Orders
# cancel all orders that have a custom id STARTING with ANY of the listed ids cancel=order id=SOME_ID,ANOTHER_ID
By type
# cancel only the stop loss orders (keeps the take profits and open entries) cancel=sl # cancel only the take profit orders cancel=tp # cancel only open limit orders (e.g. unfilled entries), keep all stops cancel=open # cancel only stop orders cancel=stops
By side, id and reduce-only
# cancel only buy orders cancel=buy # cancel orders whose custom id STARTS with ENTRY or DCA cancel id=ENTRY,DCA # cancel orders whose custom id CONTAINS DCA cancel id=*DCA # cancel everything EXCEPT orders whose id starts with TP (inverted filter) cancel id=TP reverse # cancel only orders that are not reduce-only (entries), keep closing orders cancel reduce=0 # cancel only reduce-only orders (closing orders), keep the entries cancel reduce
By count and price
# cancel the 2 oldest orders cancel maximum=2 order=oldest # cancel the order with the lowest price (e.g. the deepest DCA level) cancel maximum=1 order=lowest # cancel orders priced more than 2% above the current bid/ask cancel gt=+2% # cancel orders below an absolute price cancel lt=@60000
Note: A plain
cancel doesn't remove an SL/TP set on the entry order on exchanges with stops-on-fill: there it is an attribute of the position, not an order. On Bybit close sl=0 market changes it, see Stops-on-fill for the other exchanges.Filter Support for Orders
| Exchange | fp= | tp=1 | sl=1 | so=1 | ts=1 | t=limit | t=market | t=open | t=close | r=0/1 | iso= | id= | price⁴ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Binance | – | – | – | – | – | ||||||||
| Binance Futures | – | – | |||||||||||
| Bitfinex | ³ | ³ | – | – | – | – | – | ¹ | |||||
| Bybit | ³ | ³ | ³ | ³ | ³ | – | |||||||
| Coinbase Advanced | – | – | – | – | – | – | ¹ | ||||||
| Deribit | ³ | ³ | – | – | – | – | – | – | |||||
| Gemini | – | – | – | – | – | – | – | – | – | – | |||
| Kraken | – | – | – | – | – | – | – | – | – | – | ¹ | ||
| Kraken Futures | – | – | – | – | ¹ | ||||||||
| KuCoin | – | – | – | – | – | ||||||||
| KuCoin Futures | ³ | ³ | ³ | – | ³ | – | |||||||
| OANDA | – | – | – | – | – | – | |||||||
| OKX | – | – | |||||||||||
| Phemex | – | – | – | ||||||||||
| Poloniex | – | – | – | – | – | – | – | – | – | – | ¹ | ||
| SimpleFX | – | – | – | – | – | – | – | – | – | – |
¹ ID cache for all orders² ID cache for stops³ Equal (all stop orders)⁴ via gt=/gte=/lt=/lte= (absolute or relative)
Filtering of Positions
# close half the position, but only if it is more than 1% in profit close=50% minpl=1% # close all losing positions on all symbols at market marketclose maxpl=0 sym=* # close only the biggest position across all symbols close sym=* maximum=1 order=biggest # close a long only if its entry price is above 65000 close=long gt=@65000 # close only if the position is bigger than 10% of the balance ub close mins=10%
Note: A size filter in percent (
mins= / maxs=) needs balance info. Without it – no order, ub or "Test API" before and nothing cached – the filter is skipped with a warning and every position matches. That's what the ub line before the close is for.Filter Support for Positions
| Exchange | s=* | fp= | l= | pm= | size%² | pnl%³ | price⁴ |
|---|---|---|---|---|---|---|---|
| Binance Futures | |||||||
| Bitfinex | – | – | – | ||||
| Bybit | – | ||||||
| Deribit | – | – | |||||
| Kraken | – | ||||||
| Kraken Futures | – | – | |||||
| KuCoin Futures | – | – | – | ||||
| OANDA | – | – | ¹ | ¹ | |||
| OKX | – | ||||||
| Phemex | – | ||||||
| Poloniex | – | – | – | – | – | – | – |
| SimpleFX | – | – | ¹ | ¹ |
¹ not for all markets² via minsize=/maxsize= (absolute or relative)³ via minpl=/maxpl= (absolute or relative)⁴ via gt=/gte=/lt=/lte= (absolute or relative)
Checks with jumps
# only enter if there is no position on this symbol yet ifpos=abort long=10% sl=-1% tp=2%
# take profit only on a position that is in profit, otherwise stop ifpos=inProfit minpl=0.5% abort :inProfit close tp=[+]1% p=[+]1.1%
# wait up to 30s for the entry order to fill, then cancel it iforder=retry id=ENTRY retrydelay=3s maxtime=30s iftimeout=cancel
More of these on the Checks & Conditionals page.
Found at all, or found after filtering
iffound= / ifnone= (and ifpos= / ifnopos= …) look at the result after the filters. nopos= / noorder= look at whether anything at all is open, before any filter. When a line uses nopos=, write the other case as ifnomatch= (an alias of ifnone=), so it doesn't read as if both reacted to "nothing found":
# nothing open at all → "flat"; a position is open but not 5% in profit → "notYet" close minpl=5% nopos=flat ifnomatch=notYet
Side and ownership: the OCC flip line
# flip only positions that this strategy opened marketclose=[!side] nopos=entry wrongside=abort checkid=[id] wrongid=abort
marketclose=[!side]: close the position on the side opposite to our entry, at market.nopos=entry: nothing open at all → jump straight to the entry.wrongside=abort: a position is open, but on the other side than the filter[!side], i.e. already on our own side → stop, don't add to it.checkid=[id]: before closing, check that open orders with this id exist (prefix match). The OCC scripts name every order after the alert ([id]-TP,[id]-SL…), so this tells whether the position belongs to this strategy.wrongid=abort: no order with that id → stop, so a position of another strategy is never flipped.
Note:
checkid= only works on closing commands, a check (ifpos= … checkid=) ignores it: there the same key is the id of cancel… / close… jump targets (cancelid= / closeid=). Any open order with a matching id counts, on either side, and an SL/TP set on the entry order (stops-on-fill) has no id, so it doesn't count. The OCC scripts place separate TP/SL orders, so they're fine.The line closes first and enters after
:entry, which works on every exchange. Don't flip with one non-reduce order of double size (close=[!side] q=200% reduce=0): not every exchange accepts it.Good to know
id=filters match the start of the id,*for "contains", a comma list for several ids.- Percentages in
minpl=/maxpl=are of the position PnL (since 1.3.110, before: leveraged). The suffix%luses the leveraged PnL,%ethe PnL relative to the account:close minpl=20%l,close minpl=0.5%e. - For a check, prefer the one-key shortcuts:
ifpos=X=check=pos iffound=X,ifnopos=X=check=pos ifnone=X, same foriforder=/ifnoorder=. maximum=(cm=) takes a number or a percentage,order=(cmo=) decides which ones come first:oldest(default),newest,lowest,highest,smallest,biggest,random.reverse(cr) inverts the whole filter,reduce/reduce=0(r) picks the reduce-only / the other orders. Both are flags, bare means 1.- Relative
gt=/lt=use the current bid/ask, or a plot:gt=_myplot+5%.
Checks & Conditionals: click here for more useful syntax snippets!
Attention: Always double check that you are using the right syntax/alert!