Sidechair

box()

Browse the reference

Casts a value to the box type, mainly to give a variable a typed na before its first rectangle exists.

Try it in the editor

box(na) returns a box-typed na. That is what a var declaration needs when the type cannot be read from a bare na, as in var z = box(na).

A box passed in comes back unchanged, so the call never copies or redraws anything.

Syntax

Pine Script
box(x: series box) -> series box

Arguments

NameTypeDefaultDescription
xseries boxrequiredThe value to convert: na to get a box-typed na, or an existing box that is returned unchanged.

Returns

series box: The same box, or a box-typed na when the argument is na.

Remarks

  • The form box z = na states the same type in the declaration itself; the cast earns its place when the type has to come from an expression.

Example

Pine ScriptTyped na until the first zoneOpen in editor
//@version=6
indicator("box cast: typed na", overlay = true)
var z = box(na)
if bar_index % 40 == 0
    z := box.new(bar_index, high, bar_index + 10, low)
plot(na(z) ? 0 : 1, "Box exists")

See also

Runs on Sidechair