Sidechair

line

Browse the reference

The type of a straight line drawn between two points on the chart, created with line.new().

Try it in the editor

A line variable holds a reference to one drawn line. Declare it as line trend = na, or take the type from line.new(): var trend = line.new(bar_index, low, bar_index + 10, high).

A line has two end points, each given by x (bar index or time) and y (price), plus a color, a style, a width and an extend mode. Each part has a line.set_* function and, for the end points, a line.get_* function.

Remarks

  • A script keeps up to 50 lines by default. max_lines_count in indicator() raises that to at most 500, and beyond the limit the oldest line is removed.
  • Reading line.all returns the lines still on the chart, oldest first, so a loop can reach lines whose variables were overwritten long ago.
  • On Sidechair: setting a line's color to na keeps the line in line.all but draws nothing, and a line whose x1 equals x2 is drawn vertical and ignores extend.

Example

Pine ScriptA line that follows the last barOpen in editor
//@version=6
indicator("line type: last-bar line", overlay = true)
var line ln = na
if barstate.islast
    if na(ln)
        ln := line.new(bar_index - 20, close, bar_index, close, extend = extend.right)
    else
        line.set_xy1(ln, bar_index - 20, close)
        line.set_xy2(ln, bar_index, close)

See also

Runs on Sidechair