Sidechair

line()

Browse the reference

Casts a value to the line type, mainly so that na can be given a line type.

Try it in the editor

line(na) is a line-typed na, the starting value a variable needs before it holds a real line. An existing line passes through unchanged.

The shorter declaration line ln = na does the same in most scripts.

Syntax

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

Arguments

NameTypeDefaultDescription
xseries linerequiredThe value to convert to a line. Passing na gives a line-typed na; an existing line comes back unchanged.

Returns

series line: The argument, typed as a line.

Example

Pine ScriptTyped na before the first lineOpen in editor
//@version=6
indicator("line cast: typed na", overlay = true)
var l = line(na)
if bar_index % 40 == 0
    l := line.new(bar_index, high, bar_index + 10, high)
plot(na(l) ? 0 : 1, "Line exists")

See also

Runs on Sidechair