Skip to main content
Scripts that trade an account through the fixed order types, armed in the tab or on 0xArchive’s server.

algo

An algo: a script that trades an account through the fixed order types (order.*). Must be the first statement, in place of indicator(). It runs as orders when every order.* call sits in algo.onArm: arming runs that function once and places the orders it makes, fixed numbers that the tab or 0xArchive’s server runs. An order call anywhere else is live logic (later).
void
(fn: () => void): void
Runs once when the trader arms the algo, after setup and history: the orders it makes are what arming places.
(fn: () => string): void
The sentence the algo’s settings lead with (“Chase buy $1,000, never past 61,290”).
(o?: { shots?: number; expires?: Duration; sides?: 'long' | 'short' | 'both'; cooldown?: Duration }): void
A strategy’s arm (lifetime: 'standing'): how many trades it may take, until when, on which sides, and the wait after each. From a button’s onPress, or at the top level to arm it from the start (full auto, shots: Infinity).
((o?: { owner?: 'trader' | 'code'; initial?: 'long' | 'short' | 'both' | 'off' }) => void) & { /** The script's bias, when it owns it. The trader's Off still wins. */ set(dir: 'long' | 'short' | 'both' | 'off'): void; }
Who sets the direction allowed: the trader (the strip’s Long, Short, Both, Off) or the script, with algo.bias.set. Top level.
(o: { dailyLossUsd: number; dailyProfitUsd?: number; maxTrades?: number }): void
The day’s limits, from the account’s real fills (manual trades count): a breach halts entries. Top level. Every strategy has one.
(list: readonly { lo: number; hi: number; side?: 'long' | 'short'; label?: string }[]): void
Where the strategy may engage: a trigger outside every zone for its side is journaled, not traded.
(o: { side: 'long' | 'short'; price: number; why: string; strength?: number }): boolean
The moment the strategy would trade. The tab trades it when armed, the bias allows its side, its price is in a zone (when there are zones), and the governor has room; otherwise it is journaled as “would have traded”. Live events only: whether it was sent.
(fn: (trigger: { side: 'long' | 'short'; price: number; why: string; strength: number | null }) => StrategyPlan): void
The trade a trigger makes, in trader terms. The stop goes in before the entry, the targets once it fills. Top level.

AlgoOptions

An algo’s display options are an indicator’s; it runs on a market, never in a panel.
'entry' | 'protect' | 'both'
What its orders do to risk: 'protect' may only reduce a position, 'entry' may add. Default 'entry'.
'once' | 'standing'
'once' (the default) ends when its orders have; 'standing' stays armed and runs as a script (later).
{ markets?: 'chart' | readonly string[]; maxPositionUsd?: number }
What it may trade, shown when it is armed: the chart’s market or a list, and a cap on the position.

Side

OrderSize

An order’s size. pctOfPosition sizes an exit; riskUsd is the size that loses that much if stop is hit.

Duration

Seconds, or text such as '30s', '5m', '4h', '2d'.

OrderRef

An order an algo made. In a plan it reads 'planned'. Armed, a call on a live event reads 'sent': a request the tab admits or refuses, whose answer and fills arrive on account().onOrder and onFill, by tag. In history, or before the algo is armed, it reads 'none': nothing was sent.
string
string | null
'none' | 'planned' | 'sent'
number
number

Leg

A resting order: an OCO’s leg, or a limit.
Side
OrderSize
number | null
The limit price. null (an empty price input) is refused at arm.
boolean
Post only: refused rather than taking.
Duration
How long a condition’s limit rests.
string

Trigger

A test of one of the execution service’s own prices, for order.when. Made by trigger.*.
'mark' | 'book' | 'trade' | 'funding' | 'oiUsd'
TriggerTest
number | null

TriggerTest

TriggerOptions

Duration
How long the test must hold before it fires.
string
Another market’s price; the algo’s own by default.

control

A strategy’s controls: how the trader drives it now. Declared at the top level, at most 16. A change is an event, never a re-run. In history a control reads its history value, and a button never fires.
(label: string, value: number, o?: { min?: number; max?: number; step?: number; unit?: 'usd' | 'bps'; history?: number }): { readonly value: number }
<T extends string>(label: string, value: T, choices: readonly T[], o?: { history?: T }): { readonly value: T }
(label: string, value: boolean, o?: { history?: boolean }): { readonly value: boolean }
(label: string, o?: { value?: number }): { readonly value: number | null }
A price the trader types or drags. Empty in history: a level set today gets no credit for last month.
(label: string): { onPress(fn: () => void): void }

StrategyPlan

A trade in trader terms. r targets count from the entry to the stop.
{ how?: 'cross' | 'chase'; worstBps?: number }
{ riskUsd: number } | { notionalUsd: number } | { equityPct: number }
{ bps: number } | { price: number } | { beyondZone: true; padBps?: number }
{ r: number; pct: number }[]
Duration

order

The order types an algo places. Each call is one order of that type, checked against its ranges at arm.
(o: { side: Side; size: OrderSize; limitPx?: number | null; peg?: 'touch' | 'inside'; maxReprices?: number; maxTime?: Duration; onEnd?: 'cancel' | 'cross'; reduceOnly?: boolean; tag?: string }): OrderRef
Rest at the best price and follow it until filled, never past limitPx. maxTime gives up; onEnd: 'cross' takes the rest.
(o: { px: number | null; source?: 'mark' | 'book' | 'trade'; size?: OrderSize; confirm?: Duration; bandPct?: number; attempts?: number; tag?: string }): OrderRef
Close the position held at arm (or size of it) when the price reaches px: the mark, the best bid or ask ('book'), or the last trade. Watched by the runner, not resting on the venue. Exits in reduce-only rounds within bandPct of the mark, at most attempts times.
(o: { after?: Duration; at?: number; size?: OrderSize; bandPct?: number; attempts?: number; tag?: string }): OrderRef
Close the position held at arm (or size of it) after a hold, or at a time.
(a: Leg, b: Leg, o?: { tag?: string }): OrderRef
Two resting orders: the first to fill cancels the other.
(trigger: Trigger, then: () => OrderRef, o?: { tag?: string }): OrderRef
When the trigger’s test holds, make the one order then makes: order.reduce, order.close, order.limit or order.market.
(size: OrderSize, o?: { bandPct?: number; tag?: string }): OrderRef
A reduce-only order at market within the band, as a condition’s action.
(o?: { bandPct?: number; tag?: string }): OrderRef
Close the whole position at market within the band, as a condition’s action.
(o: Leg & { reduceOnly?: boolean }): OrderRef
A resting limit, as a condition’s action.
(o: { side: Side; size: OrderSize; bandPct?: number; reduceOnly?: boolean; tag?: string }): OrderRef
An order at market within the band, as a condition’s action.
(target: OrderRef | string): void
Live logic: cancel the working orders made with this tag (or this ref’s tag). Not in algo.onArm.
(o: { bidPx: number | null; askPx: number | null; size: { usd: number } | { coins: number }; tag?: string }): OrderRef
Live logic: quote both sides. A post-only bid at bidPx and ask at askPx, each of size, rest in the account; each call moves them (a moved quote goes to the back of its new level), and null pulls that side. The host keeps the position inside algo({ trades: { maxPositionUsd } }): the side that would pass it is pulled. Quoting runs on the Paper account.
(o: { entry: Leg; stop: number; takeProfit?: number; tag?: string }): OrderRef
Not available: use the ticket’s TP/SL, or order.fastStop with order.when.
(o: { distance: { pct: number } | { price: number }; size?: OrderSize; tag?: string }): OrderRef
Not available.

trigger

The prices order.when can test, as the execution service reads them. A null value (an empty price input) is refused at arm.
(test: TriggerTest, value: number | null, options?: TriggerOptions): Trigger
(test: TriggerTest, value: number | null, options?: TriggerOptions): Trigger
The book’s mid.
(test: TriggerTest, value: number | null, options?: TriggerOptions): Trigger
The last trade.
(test: TriggerTest, value: number | null, options?: TriggerOptions): Trigger
The funding rate per hour, as a fraction.
(test: TriggerTest, value: number | null, options?: TriggerOptions): Trigger
Open interest in USD.

account()

The account the algo trades. Declared at the top level, once.

OrderEvent

What became of one of an algo’s orders: the tab’s answer to it, or a change in what it placed.
string | null
'working' | 'filled' | 'ended' | 'refused'
'refused' with code (needs_stop, shots_used, entry_rate_limited, …) and words when the tab did not place it.
string | null
string | null
number
Filled so far, in coins, and its average price (NaN with nothing filled).
number

AlgoAccount

The account the algo trades. In algo.onArm, as it stands at the arm. Armed, as the tab last read it, for live logic. Otherwise it reads flat.
{ readonly side: 'long' | 'short' | 'flat'; readonly size: number; readonly entryPrice: number; readonly notionalUsd: number }
The position in the algo’s market: size in coins, entryPrice the average entry.
number
The account’s equity in USD.
number
The market’s mark price.
(fn: (order: OrderEvent) => void): void
Each answer and change to the algo’s orders, on live events only, never in history. Registered at the top level.
(fn: (order: OrderEvent) => void): void
When one of the algo’s orders fills more. Registered at the top level.

Next step

Continue with Inputs.
Last modified on November 13, 2026