Scripts explained
The three script kinds, the metadata + code model, drafts and versions, composition, and the Script Editor.
Scripts are the programmable half of StrategyTune. You write a small program — or let a connected AI write it for you — and the platform runs it over historical market data: drawing on the chart, marking the backtesting timeline, or trading in an automated backtest.
The three kinds
| Kind | Runs | Results appear |
|---|---|---|
| Custom indicator | In your browser, next to the chart — nothing leaves your machine at calculation time | As a study on the chart — its own pane or an overlay, updating live during replay |
| Filters & Signals | On StrategyTune's cloud | As timeline tracks — signal markers and shaded filter ranges over the backtesting timeline |
| Strategy script | On StrategyTune's cloud | As an automated backtest — trades, equity curve, and statistics in a Run report |
A signal is a moment something occurred; a filter is a time range where a condition holds. One script may declare both.
Filters, signals, and strategies run server-side because they compute over the platform's full historical tick data — precise results over data volumes a browser shouldn't download. Each run executes in an isolated sandbox: no network access, no access to your data or the outside world, strict CPU and memory limits, and a fresh sandbox per run that is destroyed afterwards.
Metadata + code = one program
Every script is two documents that form one program:
metadata.json— declarative settings: the script's name, its typed inputs (parameters), and its declared outputs — plots for indicators, signals and filters for Filters & Signals scripts, thestrategymarker for strategies.- Source code — the logic. One file.
They are coupled: the metadata defines the typed API your code is written
against. An input declared in metadata appears as ctx.inputs.<name> with the right type; a declared signal appears as ctx.signals.<name>.raise(). Declaring an output and never using it is
fine; using an undeclared one is a compile error.
The kind is derived from which metadata sections exist — there is no
separate "type" field. A plots section makes an indicator; a signals and/or filters section makes a Filters & Signals
script; a strategy section makes a Strategy script — always its own script, referencing signals and filters instead of declaring them (see Composition
below).
Languages
- Indicators: AssemblyScript — a strict, typed subset of TypeScript
that compiles to WebAssembly. You write the
calc(ctx)function. - Filters, signals, and strategies: full TypeScript — a class with
onInit/onUpdate/onFinishmethods, each optional — a script needsonUpdateor a timer subscribed inonInit. State lives in instance fields. No imports of external packages, and no network access — the code runs in the isolated sandbox described above.
Don't mix the two dialects. Indicator code is AssemblyScript
(f64/i32 types, no closures); server-script code is regular
TypeScript. Copying patterns from one into the other is the most common authoring
mistake.
Inputs (parameters)
Scripts declare typed inputs in metadata (the type reference is on Filters & Signals). Each input has a
default, and users — or a connected AI — override values per run: in the
indicator's settings on the chart, in the New backtesting run dialog, or via a dependency's setParams. Same script, different parameters, no code change.
Saving, drafts, and versions
Every save validates: indicator saves compile to WebAssembly; server-script saves type-check against the metadata-generated API — both return diagnostics in the editor.
Every script has a working draft (what the editor holds — it may be broken) and a current version (the last valid save — the version runs and dependency pins use). A failed save keeps your draft and its diagnostics while the last good version stays runnable. The version number advances on each valid save, and runs always use the stored current version — never unsaved editor content.
Composition — scripts referencing scripts
A strategy references building-block scripts instead of re-implementing them, and a Filters & Signals script can reference indicators the same way:
- Declare references in metadata under
dependencies: alias → script. Each alias is an independently configured instance — the same script under two aliases is two instances with their own parameters. - In code you consume them via
ctx.deps.<alias>— configure parameters, react to signals, read filter values and indicator plots. The full consumer API is on the Strategy scripts page. - Referenced versions freeze at save: saving a script embeds a copy of each referenced script. Later edits to a building block never silently change your script — a re-save with an outdated pin fails with a message telling you the current version; update the pin (the editor offers Update to vN) and save to adopt it. This keeps results reproducible.
The Script Editor
All three kinds are written in the Script Editor. Open it with the Editor button in the chart header, or create a script directly from the + New menu.
- Autocomplete driven by your metadata — the exact inputs and outputs
you have declared show up as typed members while you type; a read-only
types.d.tstab shows the complete generated API. - Problems panel — when a save fails, validation errors are listed under the code with line and column.
- Kind-specific action — a compiled indicator gets Add to chart; a strategy gets Run backtest, which opens the New backtesting run dialog prefilled with the script and its parameters.
Deleting and recovering
Deleting a script hides it from lists, runs, and dependency pickers, but it is recoverable for about 7 days before it is removed from normal access — a connected AI can list and restore recently deleted scripts for you.
Where AI fits
You don't have to write scripts by hand — a connected AI can create, edit, and fix scripts through the same save-and-validate pipeline the editor uses.
Something missing or wrong? Email support@strategytune.com.