Documentation

Documentation

1. Authoring Overview

Created
Jun 5, 2026
Updated
Jun 16, 2026

Deprecated. This section documents the legacy TypeScript/JavaScript authoring engine. Pine Script v6 is now the default language for both indicators and strategies. See Pine Script for current documentation. Existing TypeScript indicators and strategies continue to work and can still be selected from the language picker.

One engine, two surfaces

  • Custom indicators are written in the custom-indicator editor and plot values on the chart. See Writing Custom Indicators.
  • Strategies are written in the Strategy Tester's Compose tab and place trades during a backtest. See Writing Strategies.

Under the hood both compile through one authoring engine: your code is transpiled with TypeScript types stripped (never type-checked), wrapped in strict mode, and run with browser globals hidden.

The per-bar model

Authored code is a module you export default, with two lifecycle hooks:

export default {
  name: "My Study",
  init(ctx) {
    // optional — runs once before the bars. Read config, set up state on `this`.
  },
  next(ctx) {
    // runs once per bar, oldest → newest. Emit values / submit orders here.
  }
};

next(ctx) runs once per bar in order, and state you keep on this (or via ctx.var/ctx.series) persists across bars — so each bar's work is O(1) rather than recomputing the whole history. A bare top-level return { … } is also accepted.

What's in this section

Next steps

Start with the language both surfaces share.

Next: Authoring Language & Syntax