> ## 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.

# Opens and closes footprint

> Four lanes at each price: new shorts, longs closing, shorts closing and new longs, from why each taker traded.

<Frame caption="BTC on 1-minute bars in the 0xArchive Terminal, 2026-10-17.">
  <img src="https://mintcdn.com/0xarchive-e895b8e7/l09H5bMMUN4iGB-K/images/terminal/examples/opens-closes-footprint.webp?fit=max&auto=format&n=l09H5bMMUN4iGB-K&q=85&s=c604692b5d85cfc51fc4c82a8a6559fb" alt="Opens and closes footprint on a BTC footprint chart" width="1038" height="664" data-path="images/terminal/examples/opens-closes-footprint.webp" />
</Frame>

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

Who opened and who closed, at each price. Taker selling sits on the left, split into **longs closing** (nearest the candle) and **new shorts**; taker buying sits on the right, split into **shorts closing** and **new longs**. A move that starts with longs opening and finishes by squeezing shorts shows both in one bar.

New shorts and new longs are **opposed**: where one is three times the other at a price, the footprint marks it as an imbalance, and three in a row run right as a band. The other lanes mark none.

## How it works

Each fill's [`takerWhy`](/terminal/guides/order-flow#why-each-side-traded) puts it in one lane. A flip (`flip_ls`, `flip_sl`) opens the other way, so it counts as an open. The closing lanes take hues of their own, orange and teal, so they are never mistaken for the opening ones at small sizes. The statistics rows under each bar are the four lanes summed.

## Try changing

* Drop the opposed pair to turn the imbalance marks off.
* Split the closes into stops and profit taking with `stop_long` and `tp_long`, in place of the opens.

## The script

```ts opens-closes-footprint.ts theme={"theme":"github-dark"}
// Who opened and who closed at each price: four lanes from each fill's `takerWhy`. Taker selling on the
// left (longs closing nearest the candle, new shorts outside), taker buying on the right (shorts
// closing, then new longs). A flip opens the other way, so it counts as an open. New shorts and new
// longs are opposed: where one is three times the other at a price, the footprint marks it.
indicator('Opens and closes footprint', { overlay: true, shortName: 'Opens and closes' });

const tape = trades();
const fp = plot.footprint('Opens and closes', {
  lanes: [
    { id: 'longsClosing', label: 'Longs closing', side: 'left', color: '#e48b66' },
    { id: 'newShorts', label: 'New shorts', side: 'left', color: color.down },
    { id: 'shortsClosing', label: 'Shorts closing', side: 'right', color: '#39b2b6' },
    { id: 'newLongs', label: 'New longs', side: 'right', color: color.up },
  ],
  opposed: [{ a: 'newShorts', b: 'newLongs' }],
  stats: ['newShorts', 'longsClosing', 'shortsClosing', 'newLongs'],
});

tape.onTrade((t) => {
  const why = t.takerWhy;
  if (why === 'open_short' || why === 'flip_ls') fp.add('newShorts', t.price, t.size);
  else if (why === 'tp_long' || why === 'stop_long') fp.add('longsClosing', t.price, t.size);
  else if (why === 'tp_short' || why === 'stop_short') fp.add('shortsClosing', t.price, t.size);
  else if (why === 'open_long' || why === 'flip_sl') fp.add('newLongs', t.price, t.size);
});
```

## Next step

See the next example, [Open interest footprint](/terminal/examples/open-interest-footprint).


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