Casts a value to the box type, mainly to give a variable a typed na before its first rectangle exists.
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
box(x: series box) -> series boxArguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | series box | required | The 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
//@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