---
title: "What is wrun"
description: "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…"
order: 1
section: "getting-started"
---

<!-- source: docs/indicators/getting-started/introduction.md; generated by packages/cli/scripts/gen-indicator-docs.ts, do not edit -->

# 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

![How wrun works: market data the chart serves (candles, trades, the order book, options and more) goes into your indicator, one file in TypeScript syntax that runs on every bar, and your chart draws what it writes: lines, boxes, labels and alerts](/wrun/images/diagrams/intro-overview.svg)

1. **Market data.** The file reads the data the chart serves, for the market on
   screen or another one ([What you can read](../core-concepts/what-you-can-read.md)).
2. **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.
3. **Your chart.** The chart draws whatever the file writes
   ([What the chart shows](../presentation/overview.md)). 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

![The file beside what it makes: param adds the Period setting and output adds the sma line; a variable outside a function holds state between bars; onStart() runs once, and onBar() runs on every bar and writes the value the chart draws](/wrun/images/diagrams/intro-anatomy.svg)

1. **Declarations** come first. `param` adds a setting, here the
   **Period** field; `output` adds something to draw, here the `sma` line
   and its legend entry.
2. **State** is any variable outside a function. It keeps its value from
   one bar to the next.
3. **`onStart()`** runs once, before the first bar. Here it sizes the
   average from the Period setting.
4. **`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:

```typescript sample=gs-intro-sma
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.** `Sma` comes 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](../reference/quick-reference.md)).
- **The language.** TypeScript syntax over typed numbers (`f64`, `i32`);
  the dialect is AssemblyScript, so there is no `any` and 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

![Bar by bar, on graph paper: onBar() has run once for every bar, oldest first, and each run added one point to the average under the candles; the circled forming bar at the right runs again as new data arrives](/wrun/images/diagrams/intro-bar-by-bar.svg)

1. **`onStart()` runs once**, before any bar.
2. **`onBar()` runs once per bar**, oldest first, over every bar the chart
   has loaded.
3. **State carries forward.** Each call sees only its own bar. To use an
   earlier bar, keep it in a variable.
4. **Each call writes one value**, and the chart joins the values into the
   line. A bar where nothing is written stays blank.
5. **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

![Where an indicator runs: Run draws a draft in your browser; published with Compiled or Open source code, it runs in each reader's browser, and a padlock marks both as sandboxed; published as Protected, it runs on OpenMarket's servers; alerts on a published indicator run in OpenMarket's cloud](/wrun/images/diagrams/intro-where-it-runs.svg)

1. **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.
2. **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.
3. **Publish** as **Protected** runs it on OpenMarket's servers. The code
   never leaves them; the chart shows the result.
4. **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](../sharing/overview.md)).

## Next

- **New here?** [Your first indicator](primer-first-indicator.md): from the
  Moving Average starter to a published indicator with an alert.
- **Coming from Pine?** [wrun vs Pine](wrun-vs-pine.md): what wrun
  reads and draws that Pine can't, in one table.
- **Writing with an AI?** [Write it with AI](write-with-ai.md): Copy for
  LLM gives any assistant the rules, the kit's API and your code in one
  paste.
- **Want the tour?** [The editor](the-editor.md) lists every starter and
  every control.
