Gives a label-typed na that a variable can start from before any label exists.
label(na) is a label-typed na. It is what var l = ... needs on its right side when no label should exist yet, because var l = na alone gives the compiler nothing to infer a type from. Passing an existing label returns that same label.
Where the type is written out, label l = na says the same thing in fewer words. The cast earns its place only when a declaration has no type keyword.
Syntax
label(x: series label) -> series labelArguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | series label | required | The value to turn into a label-typed result. Pass na for an empty handle, or a real label to get the same label back. |
Returns
series label: The argument, typed as a label.
Remarks
- On Sidechair: label(na) compiles and runs like any other label-typed value, and a later
label.new()assigned to the variable replaces the na.
Example
//@version=6
indicator("label cast: lazy label", overlay = true)
var l = label(na)
if na(l) and bar_index > 20
l := label.new(bar_index, low, "armed", style = label.style_label_up, color = color.gray)
plot(na(l) ? 0 : 1, "Label exists")See also
Runs on Sidechair