Charts
API reference

Script

The fields of defineScript, the entry point of every script.

A script module's default export is defineScript({ … }). Write the fields in the order below: inputs and subscribe type everything after them.

import { defineScript, input } from "@tradingthings/tt-create";

export default defineScript({ name, surface, inputs, subscribe, state, on, draw, widgets, legend, onHover /* … */ });

ScriptDefinition

Prop

Type

Surface

/**
 * Where a script draws. The same script code runs on each, only the
 * {@link Frame} differs.
 *
 * - `ChartOverlay`: on the price pane, in the chart's time and price.
 * - `ChartPane`: its own pane below the price pane, with its own price scale.
 *   Shares the time axis and crosshair.
 * - `Canvas`: a free pixel surface without scales.
 * - `ChartSeries`: the chart's main series, chosen as the chart type. The
 *   chart draws no candles: the script draws the bars on the price pane.
 *   Autoscale and the magnet use its `g.priceValue`s.
 */
export type Surface =
  | {
      readonly kind: "ChartOverlay";
      /** Paint layer relative to the candles. `"normal"` when omitted. */
      readonly layer?: ZOrder;
    }
  | {
      readonly kind: "ChartPane";
      /** Initial pane height relative to the price pane's 1. The user can resize it. */
      readonly weight?: number;
    }
  | { readonly kind: "ChartSeries" }
  | {
      readonly kind: "Canvas";
      /** Initial pane height relative to the price pane's 1. The user can resize it. */
      readonly weight?: number;
    };

See Surfaces.

On this page