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

# Terminal scripting

> Write indicators for the 0xArchive Terminal in TypeScript, or paste Pine Script, on Hyperliquid and Lighter data no other platform gives a script.

Scripts run in the [0xArchive Terminal](https://terminal.0xarchive.io), on every market it charts. Beside the chart's bars, a script reads everything 0xArchive records: every trade with its change in open interest, liquidations with the wallet liquidated, where open positions would be liquidated, the full-depth order book, funding, open interest and market breadth.

```ts theme={"theme":"github-dark"}
indicator('Opening flow');

const chart = bars();
const tape = trades();
const opened = tally();
const flow = plot.histogram('New longs less new shorts $');

tape.onTrade((t) => {
  if (t.oiDelta > 0) opened.add(t.side === 'buy' ? t.notional : -t.notional);
});

chart.onBar(() => {
  flow.set(opened.value, opened.value >= 0 ? color.up : color.down);
});
```

This script splits out the trades that opened positions, using each trade's own change in open interest, and plots new longs less new shorts in USD on every bar.

## What a script is

A script is one TypeScript file with no imports. The top level runs once and declares everything: the script's name, its settings, the data it reads, its plots and its state. Handlers then run on every bar of history, oldest first, and on every live update, with the values of that moment. There is no lookahead: history only sees what was known at the time, so a script draws the same values live as it does on history.

Scripts run in the browser, in a worker of their own with no network access, and give the same result on every machine.

## Where scripts live

The scripts you write are kept in your browser, under the names you give them, and any chart can add them from the Indicators dialog. A script runs on whatever market and interval its chart shows, so one script works on BTC, a HIP-3 stock or a Lighter market alike. Its alerts fire in the browser while the chart is open. The terminal's own studies, from RSI to Supertrend, are scripts too, and so is every example on these pages: open one, copy it into the editor, and change it.

## Start here

* [Your first script](/terminal/guides/first-script) writes one step by step and puts it on a chart.
* [How a script runs](/terminal/guides/how-scripts-run) gives the rules every script follows.
* [Examples](/terminal/examples) shows complete scripts with their chart output, each a click away from a chart.
* [Reference](/terminal/reference) lists every function and field.

## Next step

Write [your first script](/terminal/guides/first-script).


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