Functions

Drawing

11 names in this group.
Each comes with its signature and an example.

plot

Draw a series; up to 40. style: line, step, area, circles, cross, histogram (bars from 0, rising / falling colors by default), columns. A function as color colors each bar: i => up[i] ? color.green : color.red. offset shifts it right by bars (negative: left)

signature
function plot(name: string, values: Source, o?: { color?: Color | PerBarColor; width?: number; style?: PlotStyle; lineStyle?: LineStyle; offset?: number }): void
example
plot('EMA', fast, { color: (i) => (fast[i] > fast[i - 1] ? color.green : color.red), width: 2 })

hline

Horizontal reference line (name, color, style); up to 20

signature
function hline(value: number, o?: { label?: string; color?: Color; style?: LineStyle; width?: number }): void
example
hline(70, { label: 'Overbought', color: color.red })

fill

Shade between two plots, by name, after them; up to 10. A color without alpha is shaded lightly. downColor: where the lower one is on top. A function as color colors each bar (null: not shaded)

signature
function fill(upper: string, lower: string, o?: { color?: Color | PerBarColor; downColor?: Color }): void
example
plot('Upper', bb.upper)
plot('Lower', bb.lower)
fill('Upper', 'Lower', { color: color.alpha(color.blue, 0.1) })

bgcolor

Shade the background (a condition and a color, or a function giving each bar a color); up to 10. Colors without alpha are shaded lightly

signature
function bgcolor(when: Bool | PerBarColor, o?: { color?: Color }): void
example
bgcolor(gt(close, ta.ema(close, 200)), { color: color.green })

barcolor

Recolor candles (indicators over the candles): a condition and a color, or a function giving each bar a color

signature
function barcolor(when: Bool | PerBarColor, o?: { color?: Color }): void
example
barcolor(ta.crossover(close, ta.sma(close, 20)), { color: color.yellow })

plotshape

A shape on every bar where the condition is true; up to 20. Up shapes sit under the bar, others over it

signature
function plotshape(when: Bool, o?: { shape?: Shape; location?: Place; price?: Source; color?: Color; textColor?: Color; text?: string; size?: Size }): void
example
plotshape(ta.crossover(fast, slow), { shape: 'triangleup', text: 'Buy' })

label

Text on the chart. bar: the index (-1 = the latest, bar.count + 3 = the empty space on the right). With price, at that price. style 'text' has no box; align 'right' starts at the point. The latest 500 stay

signature
function label(bar: number, text: string, o?: { location?: Place; price?: number; color?: Color; textColor?: Color; style?: 'box' | 'text'; align?: 'left' | 'center' | 'right'; size?: Size }): void
example
label(-1, 'RSI ' + last(rsi).toFixed(1))

line

A line between two points (bar index, price). extend 'right', 'left' or 'both' runs it to the edge. The latest 500 stay

signature
function line(x1: number, y1: number, x2: number, y2: number, o?: { color?: Color; width?: number; style?: LineStyle; extend?: Extend }): void
example
line(-50, last(high), -1, last(high), { color: color.orange, style: 'dashed', extend: 'right' })

box

A rectangle (bar indices, prices). color: the border, bg: the inside (lightly, without alpha). extend 'right' runs it to the edge. The latest 500 stay

signature
function box(left: number, top: number, right: number, bottom: number, o?: { color?: Color; bg?: Color; width?: number; style?: LineStyle; extend?: Extend; text?: string; textColor?: Color }): void
example
box(-30, last(high), -1, last(low), { color: color.red, bg: color.alpha(color.red, 0.15), extend: 'right', text: 'Range' })

table

A table in a corner of the chart (a dashboard). rows: a list of rows, each a list of cells. Up to 4, 60 rows × 10 cells

signature
function table(o: { position?: Position; rows: (string | number | null | { text: string; color?: Color; bg?: Color; align?: 'left' | 'center' | 'right' })[][]; bg?: Color; textColor?: Color; border?: Color; size?: Size }): void
example
table({ position: 'top-right', rows: [['RSI', last(rsi).toFixed(1)], ['EMA', last(fast).toFixed(2)]] })

color

Colors; color.up / color.down follow the viewer’s rising / falling colors. '#RRGGBB' and '#RRGGBBAA' work too. color.alpha(c, 0.2) sets opacity 0 (invisible)–1; color.new(c, 80) is Pine’s transparency 0–100

signature
const color: { up: Color; down: Color; red: Color; blue: Color; green: Color; orange: Color; yellow: Color; purple: Color; pink: Color; teal: Color; gray: Color; white: Color; black: Color; alpha(c: Color, opacity: number): Color; "new"(c: Color, transparency?: number): Color; rgb(r: number, g: number, b: number, opacity?: number): Color }
example
color.alpha(color.green, 0.2)

npm · GitHub