Algo orders (order scripts)
Algo orders are order types you program yourself. A small Lua script — the same language as custom indicators — describes how to work an order, and the ticket’s Algo mode runs it: the script declares the child orders it wants resting each tick, and the engine keeps the venue in sync. Nocterm ships a chaser, a TWAP, a scaled ladder, an iceberg, and a trailing stop as editable seed scripts, and anything you write appears in the ticket alongside them.
id: trading-algo-orders-ticketThe ticket's Algo mode: script picker, the script's own inputs, and the parent size
suggested 1280x720How an algo order runs
Section titled “How an algo order runs”You give the ticket a parent order — side, quantity, and a script. From then on the script runs on every engine tick (order-book updates plus a 4 Hz heartbeat) and declares the working orders it wants resting right now:
script("Chaser", "order")-- rest at the near touch and follow it until the parent fillsquote{ price = touch(), qty = remaining(), post_only = true }Declaring is the whole job. The engine diffs that intent against what’s actually on the venue — amending where the venue supports it, cancel-and-replacing where it doesn’t — so a re-priced quote keeps its queue identity where possible, and a script bug cannot orphan an order: anything the script stops declaring is cancelled, and stopping the algo cancels everything.
The script reads live context — bid(), ask(), mid(), touch(), last(), filled(),
remaining(), elapsed(), pos(), and entry() (your open position’s average entry, so
exits anchor to the real fill, not to when you attached the algo) — and ends with take()
(market the remainder), done(), or fail(msg). The engine finishes automatically once the
parent is filled.
Order scripts run on ticks, not bars, so the time global is the current tick’s time in
seconds since epoch — the wall clock when live, the replayed candle clock in the editor’s Sim
tab. Prefer elapsed() for pacing (“how long has this algo been working”); use time when
the schedule is anchored to the clock itself, like stopping at the top of the hour.
Running one
Section titled “Running one”- In the trade ticket, pick Algo (next to Market / Limit).
- Choose a script — the seeds, or anything you’ve saved with
script(name, "order"). - The script’s
input()parameters appear as fields; set them and your size, then submit.
Working algos show in the Blotter as a WORKING ALGOS strip — progress, elapsed, state, and a Cancel button — and on the chart, where each resting rung draws as a dashed line tagged with the script’s name (the top rung carries the fill progress). The lines aren’t draggable — the script owns its prices — but a right-click on one offers Cancel algo.
id: trading-algo-orders-chartA working scaled ladder: dashed rung lines on the chart and the WORKING ALGOS strip in the Blotter
suggested 1280x720The seed scripts
Section titled “The seed scripts”| Script | What it does |
|---|---|
chaser | Rests post-only at the touch and re-prices as the market moves; gives up and markets if price runs max_chase_pct away. |
twap | Slices the parent evenly across window_min minutes, working each slice at the touch. |
scaled_ladder | Spreads rungs weighted limit orders across range_pct from the touch. |
iceberg | Shows only show_pct of the size at a time; each fill posts a fresh tip. |
trailing_stop | Rests nothing — tracks your position’s favorable extreme from its entry and markets the remainder on a trail_pct retrace. activation_pct waits for that much profit before arming; hard_stop_pct (optional) protects the wait with a fixed stop. |
They’re plain .lua files — open them in the Editor, tweak, save under a new name, and
the ticket lists your version.
Dry-run in the Sim tab
Section titled “Dry-run in the Sim tab”Order scripts get their own preview in the editor: the Sim tab replays your unsaved
buffer against real recent candles or canned scenarios (trend up/down, chop, a gap), through
the same reconciliation logic the live engine uses. You get a tape chart with every fill,
reject, and placement marked, execution stats (average fill vs arrival and VWAP, maker/taker
split, operation counts), and a full event journal. Tick start filled to simulate an
exit — pos() and entry() behave as if the position already exists.
id: trading-algo-orders-simThe editor's Sim tab: scenario picker, execution stats, the annotated tape, and the event journal
suggested 1280x720Safety rails
Section titled “Safety rails”The engine owns the guardrails, not the script: prices snap to the venue tick, declared size is clamped to the parent’s remainder (no overfills), mutations are rate-limited and capped per hour, a reject loop halts the algo, and quitting the app, the kill switch, or a replay reset all cancel every child order. On live venues that can’t amend, replacements only go out after the cancel is acknowledged, so you’re never double-exposed.
Related
Section titled “Related”- The trade ticket — where Algo mode lives.
- Custom indicators (Lua) — the editor and the language.
- Trading bots — for strategies that decide what to trade; order scripts only execute.