Functions

Styling

Size tiers, tooltips, alignment vocabulary, z-order, color palettes, and the value-driven styling pattern (per-element gradients, opacity, and glow).

Intermediate 8 min read

Size tiers

Anywhere a text size is accepted (plotText.size, plotLabel.size, plotPriceLabel.size, plotTable.fontSize), you can pass a named tier or a number:

Tierpx
"tiny"8
"small"10
"normal"12
"large"16
"huge"24

Numbers keep the existing clamped-pixel behavior. Unknown tier strings raise a line/column error (never a silent fallback).

Tooltips

Every output that renders something accepts a tooltip string: the plot family (plotLine, plotBar, plotCandle, plotShape, plotText, plotLabel), table cells, and every drawing object (via set_tooltip). Compose them with format:

plotShape(high, shape="diamond", location="aboveBar",
  tooltip=format("delta {0} @ {1}", tostring(delta, "0.0"), tostring(close)))

Alignment

One vocabulary everywhere:

  • Horizontal parameters accept left, center, right.
  • Vertical parameters accept top, middle, bottom.
  • Full anchors (table positions, price-label anchors) use the nine combinations: top_left ... bottom_right.

Passing a vertical word to a horizontal slot is a line/column error: the axis matters, not just the word. Legacy uppercase aliases from older scripts remain accepted.

Z-order

Plots and drawing objects accept zOrder (drawings: set_zorder(z)). Lower values render first (further back); equal values keep declaration order. Use it to pin context bands behind signals:

plotLine(slow, color="#94a3b8", zOrder=0)     // background
plotLine(fast, color="#0ea5e9", zOrder=10)    // foreground

Palettes

palette(name) returns a fresh, mutable array of color strings:

var colors = palette("viridis")
var c = colors[3]

Built-in palettes: default, viridis, heat, delta, cool. Unknown names raise a line/column error. Each call returns a fresh copy, so mutating the result never corrupts the registry, and the array composes with everything in Collections.

Value-driven styling

The pattern that replaces a dozen Pine workarounds: compute the style from the data, per element. Normalize a driving value, map it to a color, pass it in:

// candles shaded by delta intensity
timeseries delta = fp.cells.map((c) => c[2] - c[3]).reduce((s, x) => s + x, 0)
var shade = colorGradient(delta, [-500, 500], palette("delta"))
plotCandle(colorIndex=shade)

// labels whose glow tracks conviction
plotPriceLabel(close, opacity=math.min(1, math.abs(delta) / 500), glow=2)


`colorGradient(value, [min, max], palette)` and `blend(colorA, colorB, amount)` are the two mapping helpers. Because color, opacity, and glow are per-element values rather than series-wide constants, a single plot statement can encode a whole extra dimension of data. Per-element glow, opacity, and value-gradients on individual outputs are not expressible in Pine's styling model.

Where the rules live

Every styling parameter is validated (compile-time for literals, runtime otherwise) with line/column errors, and the whole surface is covered by the engine's differential harness, so dynamic styles stream correctly on live charts. For the full reference tables, see the downloadable language reference.