Skip to main content

Close & Cancel

Seven fields. Close = flat an existing position. Cancel = remove pending orders. Two different jobs that often happen together but are independently controlled.

TL;DR
  • isClose: true — close the open position on the pair, any direction (one-way mode). No entry.
  • closeCurrentPosition: true — together with isBuy / isSell: close the position first, then open the entry (flip).
  • closeLong: true / closeShort: true — close one side only. With the other side open, nothing is closed.
  • cancelAllOrders: true — cancel every pending order on the pair (entries, DCA, TP, SL).
  • cancelAllDcaOrders: true — cancel just the DCA mesh; leave TP/SL intact.
  • Standalone variants cancelAll and cancelAllDca exist for "no-op-payload-that-just-cancels" use cases.
TradingView placeholders

All fields on this page are booleans. No placeholders.

Quick reference table​

PropertyTypeRequiredDefaultDescription
closeCurrentPositionboolnofalseClose the open position on the pair before the entry of the same command runs (the flip pattern). Needs isBuy or isSell: a command with only closeCurrentPosition has no direction and is rejected. To close without an entry, send isClose: true.
cancelAllDcaOrdersboolnofalseNot an immediate cancel. A companion flag stored with the trade's trailing-stop record; when the trailing stop later closes the position, TVH also cancels the pair's remaining pending orders. Only meaningful alongside a trailing stop. For an immediate DCA-mesh cancel use cancelAllDca.
cancelAllOrdersboolnofalseCancel every open order on the pair (entries, DCA legs, TP, SL) before the entry of the same command. The cancel completes before the entry goes out. The new SL/TP of the same command are placed after the entry and are not cancelled.
closeLongboolnofalseClose only a long position. If a short is open, nothing is closed. Required when the account is in dual-position (hedge) mode and you want to flat one direction. In one-way mode a plain isClose: true closes the open position in either direction.
closeShortboolnofalseClose only a short position. If a long is open, nothing is closed. Hedge-mode helper, see closeLong.
cancelAllDcaboolnofalseStandalone trade command that cancels the pair's DCA mesh limit orders (TP/SL stay attached) and does nothing else. This is the field that actually clears a pending mesh immediately.
cancelAllboolnofalseStandalone command to cancel every pending order on the pair. Counterpart to cancelAllOrders when no entry is included.

Close vs cancel — conceptual difference​

TermWhat it does
CloseFlatten an existing position with an opposite-side market or limit order sized to whatever's open. A full close also cancels the pair's remaining pending orders (TP/SL, DCA legs, unfilled entries).
CancelRemove a pending order that hasn't filled yet. Does not affect the existing position.

A full close already cleans up. After flattening the position, a market close cancels every pending order left on the pair automatically — you do not need a separate cancelAllOrders alongside it. Two exceptions: a partial close (usePartialClose) keeps the existing take-profit orders and resizes them to the reduced position instead of cancelling, and a limit close (useLimitClose) leaves orders in place until the limit fills.

The two operations can also fire in the same payload. With cancelAllOrders: true on an entry, the order is cancel first, then trade: the cancel completes before the entry goes out, so the new order doesn't fight stale TPs/SLs. The SL/TP of the same payload are placed after the entry and are not cancelled. If the entry is rejected, the old orders are already gone and nothing replaces them.

Closing a position​

One-way mode close (default Binance Futures, Bybit, OKX net)​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"isClose": true,
"token": "<token>"
}

The auto-mapping logic (Anatomy → orderType auto-mapping) sets isClose=true, isMarket=true and disables chaseLimitOrder (unless useLimitClose=true). TVH then submits an opposite-side market order sized to the current position.

closeCurrentPosition is not a second way to write this. It needs an entry direction (isBuy or isSell), and a payload with only closeCurrentPosition: true is rejected for missing direction. Use it to close and re-enter in one payload (flip):

{
"isBuy": true,
"closeCurrentPosition": true,
"units": 0.05
}

Closes the existing short (if any) then opens a fresh long. The classic "flip" pattern.

What happens to a position in the same direction as the entry depends on the exchange:

ExchangeOpen long + isBuy + closeCurrentPosition
Binance Futures, Bybit, OKX, BitgetThe long stays open, the entry adds to it. Only an opposite position is closed.
KuCoin, Hyperliquid, CoinbaseThe long is closed, then a fresh long opens.

Bybit Spot and Binance Spot do not read closeCurrentPosition. On these two exchanges the flag has no effect, and only the entry runs.

Hedge-mode close (Binance Futures dual-position)​

In hedge mode, closeCurrentPosition only closes the side opposite to an entry (see Common mistakes). To close one side without an entry, use the helpers:

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"isClose": true,
"closeLong": true,
"hedgeMode": true,
"token": "YOUR_TOKEN"
}

Closes the long side. The short, if any, stays open.

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"isClose": true,
"closeShort": true,
"hedgeMode": true,
"token": "YOUR_TOKEN"
}

Closes the short side only.

closeLong closes only a long, closeShort closes only a short, also in one-way mode. If the other side is open, nothing is closed. In one-way mode, use a plain isClose: true to close whatever is open.

Auto-reset rule: TVH changes closeLong / closeShort only when the payload carries both strategyComment and strategyCloseValue. If the comment does not match strategyCloseValue, TVH resets both to false, because it assumes a fresh entry. If it matches, TVH keeps closeLong only with orderType="sell" and closeShort only with orderType="buy". Without strategyCloseValue, the flags stay as you sent them. See Anatomy → strategyComment auto-close.

Flip with limit close​

{
"isClose": true,
"closeCurrentPosition": true,
"useLimitClose": true,
"isLimit": true,
"price": 65500
}

Exit at limit price 65500 instead of market. Requires useLimitClose: true — see Limit Order Management → useLimitClose.

Cancel cascade​

Three flags cancel orders when the payload runs. A fourth, cancelAllDcaOrders, is not an immediate cancel — see the note below.

FlagWhat gets cancelledWhat survives
cancelAllOrdersEvery open order on the pair (entries, DCA legs, TP, SL)Nothing
cancelAllEvery open order on the pair, as a standalone payloadNothing
cancelAllDcaDCA mesh limits only, as a standalone payloadTP, SL, unrelated entry limits

cancelAllOrders is designed to combine with an entry in the same payload (cancel first, then trade). A plain close (isClose) cancels the pair's pending orders on its own. cancelAll and cancelAllDca are standalone "no-op except for the cancel" payloads: TVH runs no entry from the same payload.

cancelAllDcaOrders is not an immediate cancel

Despite the name, the cancelAllDcaOrders flag cancels nothing when the payload is processed. It is stored with the trade's trailing-stop record and tells TVH to cancel the pair's remaining pending orders later, at the moment the trailing stop closes the position. It only has an effect alongside a trailing stop. To clear a DCA mesh now, use cancelAllDca.

Cancel-then-trade​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"isBuy": true,
"isMarket": true,
"units": 0.05,
"cancelAllOrders": true,
"token": "<token>"
}

Cancel every pending order first (stale entries, leftover SLs, half-filled DCA), then open a fresh long. The cancel completes before the entry goes out. An SL/TP in the same payload is placed after the entry and stays. If the entry is rejected, the old orders are already cancelled. Useful as the first leg of a new setup when the pair has had previous activity.

Cancel-only payload​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"cancelAll": true,
"token": "<token>"
}

No orderType. No units. Just "clear the slate on this pair". TVH does nothing else.

Cancel just the DCA mesh​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"cancelAllDca": true,
"token": "<token>"
}

The DCA mesh from a previous payload is cancelled. TP and SL on the already-filled portion stay attached.

Detail per property​

closeCurrentPosition​

AttributeValue
Typebool
Requiredno
Defaultfalse

Close the open position on the pair before the entry of the same payload runs. Needs isBuy or isSell. Binance Futures, Bybit, OKX and Bitget close only a position opposite to the entry. KuCoin, Hyperliquid and Coinbase close the position in either direction. See One-way mode close. To close without an entry, use isClose: true.

closeLong​

AttributeValue
Typebool
Requiredno
Defaultfalse
Auto-mappedonly with strategyComment + strategyCloseValue: kept on a match with orderType="sell", otherwise reset to false

Close only a long position. If a short is open, nothing is closed. Needed in hedge mode. In one-way mode, a plain isClose: true is simpler.

closeShort​

AttributeValue
Typebool
Requiredno
Defaultfalse
Auto-mappedonly with strategyComment + strategyCloseValue: kept on a match with orderType="buy", otherwise reset to false

Close only a short position. If a long is open, nothing is closed. Needed in hedge mode. In one-way mode, a plain isClose: true is simpler.

cancelAllDcaOrders​

AttributeValue
Typebool
Requiredno
Defaultfalse

Not an immediate cancel. A companion flag stored with the trade's trailing-stop record. When the trailing stop later closes the position, TVH also cancels the pair's remaining pending orders. Only meaningful when a trailing stop is attached. For an immediate DCA-mesh cancel use cancelAllDca.

cancelAllOrders​

AttributeValue
Typebool
Requiredno
Defaultfalse

Cancel every open order on the pair (entries, DCA legs, TP, SL). Combine with an entry to clear the book before re-entering. The cancel completes before the entry. The new SL/TP of the same payload are placed after the entry and are not cancelled. If the entry is rejected, the old orders are already gone.

cancelAllDca​

AttributeValue
Typebool
Requiredno
Defaultfalse

Standalone payload that cancels the DCA mesh limits on the pair (TP and SL stay attached) and does nothing else. This is the field that actually clears a pending mesh now.

cancelAll​

AttributeValue
Typebool
Requiredno
Defaultfalse

Standalone variant of cancelAllOrders. Use as a maintenance payload that touches only pending orders.

Worked examples​

Reverse position (flip long to short)​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"isSell": true,
"closeCurrentPosition": true,
"isMarket": true,
"units": 0.05,
"stopLossType": "percent",
"stopLossPercent": 1.5,
"token": "<token>"
}

If long is open, it's closed first. Then a fresh 0.05 BTC short opens with a 1.5% SL. The Activity Log shows two fills for this payload (the close, then the entry).

Reset before a fresh setup​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"cancelAll": true,
"token": "<token>"
}

Then a separate payload to open the new entry. Two payloads is cleaner than one because the cancel and the entry happen at different cadences.

Hedge-mode flat the long, keep the short​

{
"exchange": "binance-futures",
"pair": "BTCUSDT",
"apiKey": "binance-futures-main",
"hedgeMode": true,
"isClose": true,
"closeLong": true,
"token": "<token>"
}

Long is closed at market. Short stays open with its own SL/TP intact.

Common mistakes​

  • closeCurrentPosition: true in hedge mode. On Binance Futures with hedgeMode: true, it closes the side opposite to the entry (isBuy closes the short, isSell closes the long), then the entry opens. The other side stays. To close one side without an entry, use isClose with closeLong / closeShort.
  • cancelAllOrders: true on an entry that the exchange rejects. The cancel runs first and completes before the entry. If the entry then fails (balance, min size, exchange error), the old TP/SL are already cancelled and nothing replaces them. The new TP/SL of the same payload are not at risk: TVH places them after the entry.
  • closeCurrentPosition: true with no position open. No close happens, and the entry of the payload still executes. Some exchanges write an info line to the Activity Log: "no position found" on OKX spot, "No position to close" on KuCoin, Hyperliquid and Coinbase, "has no position to close" (futures) or "has no holding to close" (spot) on Bitget. Binance Futures (USDT-M and COIN-M), Bybit and OKX swaps write no line for this case.
  • closeLong: true while a short is open (or closeShort with a long). Nothing is closed. In one-way mode use isClose: true.
  • cancelAll: true together with other actions. cancelAll is standalone: TVH cancels the pending orders and runs no entry and no closeCurrentPosition from the same payload.

Next​

Timing & Idempotency — alertTimestamp dedup, delay, retries.