> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Opening sweeps

> Large taker orders that walked the book, split by whether they opened positions or closed them.

<Frame caption="BTC on 5-minute bars in the 0xArchive Terminal, 2026-10-16.">
  <img src="https://mintcdn.com/0xarchive-e895b8e7/LMJhlFFDmPRlcfDT/images/terminal/examples/opening-sweeps.webp?fit=max&auto=format&n=LMJhlFFDmPRlcfDT&q=85&s=e4230f6c71bf7ae73c9166a1d667866b" alt="Opening sweeps on a BTC chart" width="1038" height="664" data-path="images/terminal/examples/opening-sweeps.webp" />
</Frame>

<Card title="Open on a chart" icon="chart-candlestick" href="https://terminal.0xarchive.io/?symbol=BTC&interval=5m&scripts=example%3Aopening-sweeps" horizontal>
  Load it on BTC 5m in the terminal, then change its settings or open it in the script editor.
</Card>

A sweep is one market order big enough to eat through several prices of the book. On a chart of trades it is a burst of separate prints; joined back into its order, it is one decision by one taker. This script keeps the orders of \$250k or more that filled at three prices or more and asks what each did to open interest, from the sum of its fills' `oiDelta`:

| Sweep | What happened |
| - | - |
| Buy, open interest up | Bought into new positions |
| Buy, open interest down | Bought out of positions: shorts covering |
| Sell, open interest up | Sold into new positions |
| Sell, open interest down | Sold out of positions: longs exiting |

The bars are **opening sweeps**: buys less sells, in USD. The line is **closing sweeps**. Aggression that opens is a taker committing to a side; aggression that closes is a taker leaving one.

## How it works

[`takerOrders()`](/terminal/guides/order-flow#taker-orders) joins the fills into orders and calls `onOrder` once per order, once all its fills are in, so a forming bar never sees half a sweep. `minNotional` counts the whole order, and `levels` is how many prices it filled at. Two [tallies](/terminal/guides/state#tallies) collect the bar's sweeps, one for each kind. An order whose fills moved no open interest on net counts in neither, and neither does one with a fill the venue did not report.

## Try changing

* Raise **Prices walked** to keep only the orders that moved the price the furthest.
* Lower **Smallest order** on a smaller market: \$250k sweeps are common on BTC and rare on most others.

## The script

```ts opening-sweeps.ts theme={"theme":"github-dark"}
// Large taker orders that walked the book, split by what they did to open interest. A sweep that
// raised open interest opened positions; one that lowered it closed them. Opening sweeps are the
// bars, buys up and sells down; closing sweeps are the line, in USD per bar. Each order is joined
// from its fills, and its change in open interest is the sum of theirs, which 0xArchive records on
// every print.
indicator('Opening sweeps', { shortName: 'Sweeps' });

const minUsd = input.float('Smallest order ($)', 250_000, { min: 0 });
const minLevels = input.int('Prices walked, at least', 3, { min: 1, max: 100 });

const chart = bars();
const orders = takerOrders({ minNotional: minUsd });
const opening = tally();
const closing = tally();

const openingBars = plot.histogram('Opening sweeps $');
const closingLine = plot.line('Closing sweeps $', { color: color.study(12), width: 1 });

orders.onOrder((o) => {
  // na: some fill's change in open interest is unknown. 0: what opened on one side closed on the other.
  if (o.levels < minLevels || isNa(o.oiDelta) || o.oiDelta === 0) return;
  const usd = o.side === 'buy' ? o.notional : -o.notional;
  (o.oiDelta > 0 ? opening : closing).add(usd);
});

chart.onBar(() => {
  // Trades reach back to the chart's first bar, at most 7 UTC days; older bars stay empty.
  if (!orders.available) return;
  openingBars.set(opening.value, color.withAlpha(opening.value >= 0 ? color.up : color.down, 0.75));
  closingLine.set(closing.value);
});
```

## Next step

See the next example, [Liquidations](/terminal/examples/liquidations).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.