What is wrun
wrun is OpenMarket's engine for your own market logic. Write an indicator in TypeScript syntax, and wrun runs it on every bar of the real market, compiled to WebAssembly, right in your browser.
- Compiled, not interpreted. A 20-bar average over 10,000 bars computes in under a millisecond.
- Live without the lag. A live update re-runs one bar, never your whole history.
- Nothing new to learn. TypeScript syntax your AI already writes, checked by a real compiler before anything runs.
- The whole market. The order book, trade tape, liquidations and options chains, plus 78 built-in indicators and stats to build on.
How it works
- Market data. The file reads the data the chart serves, for the market on screen or another one (What you can read).
- Your indicator. One file, written in the chart's editor. There is
nothing to install: Run compiles it in your browser, and its
onBar()runs once per bar. - Your chart. The chart draws whatever the file writes (What the chart shows). Once published, anything it draws can trigger an alert. A strategy also places simulated orders in the Strategy Tester; wrun never places real ones.
What a file looks like
- Declarations come first.
paramadds a setting, here the Period field;outputadds something to draw, here thesmaline and its legend entry. - State is any variable outside a function. It keeps its value from one bar to the next.
onStart()runs once, before the first bar. Here it sizes the average from the Period setting.onBar()runs once per bar. Here it feeds the close into the average and writes the result.
The whole file, ready to paste into the editor:
wrun
param("period", 20, { min: 1, max: 200 });
output("sma", line, overlay, { color: "#2563eb", width: 2, description: "20-period simple moving average" });
let sma = new Sma(20);
function onStart(): void { sma = new Sma(i32(p_period())); }
function onBar(): void { out_sma(sma.update(bar.close())); }- The kit.
Smacomes from the kit, the library of ready-made pieces every file can use by name with nothing to import:Rsi,Cvd, levels, market structure and more (Quick reference). - The language. TypeScript syntax over typed numbers (
f64,i32); the dialect is AssemblyScript, so there is noanyand no npm. If you can follow this file, you can write one: the Moving Average starter is this file with a comment on every line.
Bar by bar
onStart()runs once, before any bar.onBar()runs once per bar, oldest first, over every bar the chart has loaded.- State carries forward. Each call sees only its own bar. To use an earlier bar, keep it in a variable.
- Each call writes one value, and the chart joins the values into the line. A bar where nothing is written stays blank.
- The forming bar re-runs as new data arrives. Each run starts from the state of the last closed bar, so nothing counts twice.
Where it runs
- Run draws a draft on your chart for this session. It runs in a sandbox in your browser: no internet, no files, no access to your account.
- Publish with Compiled or Open source code gives the
indicator a name (
@yourname/name) and a version, and it runs in the same sandbox in each reader's browser, so adding someone else's indicator is safe. Compiled keeps the code to you: readers get a compiled module, never the source. - Publish as Protected runs it on OpenMarket's servers. The code never leaves them; the chart shows the result.
- Alerts on a published indicator run in OpenMarket's cloud, wherever the indicator runs.
A published version never changes, and you choose who can use it: Everyone, Invite only, or Just me (Sharing).
Next
New here?
Your first indicator: from the Moving Average starter to a published indicator with an alert.
Coming from Pine?
Wrun vs Pine: what wrun reads and draws that Pine can't, in one table.
Writing with an AI?
Write it with AI: Copy for LLM gives any assistant the rules, the kit's API and your code in one paste.
Want the tour?
The editor lists every starter and every control.