Skip to main content
Colours, formatting, time, logging, randomness

color

Color
The theme’s up and down colours, and a neutral text colour.
Color
Color
Color
The chart’s own background, for a table or label that should sit on the theme’s surface.
Color
A colour that draws nothing: a transparent line segment, bar or shade.
(i: number): Color
The theme’s study palette, i from 0 to 15.
(r: number, g: number, b: number, alpha?: number): Color
A colour from red, green and blue, 0 to 255, and alpha from 0 to 1.
(c: Color, alpha: number): Color
The same colour with alpha from 0 (transparent) to 1: #rrggbbaa for a hex colour, theme:[email protected] for a token.
(a: Color, b: Color, t: number): Color
A colour between two hex colours, t from 0 to 1. A theme token cannot be mixed: a comes back.

fmt

(value: number): string
A price in the market’s own precision.
(value: number, decimals?: number): string
A number with a comma every three digits and decimals places, as the terminal writes numbers whatever the reader’s locale.
(value: number): string
$1.2M, $350k.
(value: number, decimals?: number): string
A fraction as a percent: pct(0.0123) is 1.23%.
(value: number): string
A number shortened with a suffix, 1.2M or 350k, as the axes of a script’s own pane print.

clock

(time: Time, timeZone?: string): TimeParts
Calendar fields of time in timeZone (IANA name), UTC by default.
(time: Time, unit: 'day' | 'week' | 'month' | 'quarter' | 'year', timeZone?: string): Time
The start of the day, week (Monday), month, quarter or year that contains time.

TimeParts

number
number
number
number
number
number
number
0 Sunday to 6 Saturday.

log

Lines in the script’s console, each with the time of the bar it was written on; 1,000 at most, oldest dropped.
(...values: unknown[]): void
(...values: unknown[]): void
(...values: unknown[]): void

random()

A seeded random number generator: the same seed gives the same numbers everywhere.

Next step

See what each code means in diagnostics.
Last modified on October 16, 2026