Early Access Discount

Types and nan

TypeValuesNotes
floatany number, including nanPrices, volumes, timestamps and most results.
inta finite whole numbernan is not a valid int. Counts, lengths, bar indices.
booltrue or falseNever produced by coercion.
stringtext up to 1,024 charactersCompared with == and !=. Joined with str.concat.
colora "#RRGGBB" or "#RRGGBBAA" stringSix digits is fully opaque; the last pair is the opacity, 00 transparent to FF opaque. No CSS names are accepted, but the color.* constants and the color.rgb, color.new and color.from_gradient builders give you one.
side"BUY", "SELL" or "UNDEFINED"What the tape, order and marker side accessors return. Compare it with == "BUY".
voidno valueOnly as the return type of a user function.

Type annotations on a declaration are optional. When you write one it is enforced on every bar, which is the single most common reason a script that parses still stops. Annotate with float unless you are certain the value is a finite whole number.

The int trap
// Stops the run: "n requires int, received nan"
let n: int = tape.vwap()

// Safe
let n: float = tape.vwap()
let rounded: int = math.round(nz(tape.vwap(), close))

nan is the absent value

  • History before the first bar returns nan for every series, including a bool series and a string series. Annotating that read stops the run, so guard it: bar_index > 0 && flag[1] short circuits and stays a bool. The globals is_forming and last_bar answer false instead of nan.
  • A moving average returns nan until its window is complete.
  • -1 is the none index everywhere. Every accessor that takes a row index (tape, ladder, book, order, order event, strike, marker and zone) answers -1 or an out of range index with nan, a side accessor with UNDEFINED and a string accessor with an empty string. Builtins that find a row, such as tape.largest_index, cell.index_at, mbo.largest_index and effort_zones.at, answer -1 when there is none, so their answer can be passed straight on. An index below -1 or a fraction stops the run.
  • A string accessor with nothing to report returns an empty string.
  • nz(value) replaces a non finite value with 0, and nz(value, replacement) with your own.
  • is_nan(value) is the only reliable equality test against nan.
  • na is another name for nan and na(value) is is_nan(value), so Pine style code reads the same.

Every layer of the market, Orderflow to optionflow, on one chart.

Institutional grade Orderflow data with backtesting and journaling built in. Start your subscription today.

Get Access