Skip to content

line ​

How do you draw a line from one bar to another? Call line.new with two bars and two prices, or two chart.points, and keep the handle to move it later. A line drawn from the last pivot to the next one is the usual case: make it when the pivot comes, then move its second end on each bar.

pine
//@version=6
indicator("Since the last high", overlay = true)
var line ray = na
ph = ta.pivothigh(high, 5, 5)
if not na(ph)
    // A new pivot: a new line from it, which the bars after it move.
    ray := line.new(bar_index - 5, ph, bar_index, close, color = color.orange)
line.set_xy2(ray, bar_index, close)

A deleted line leaves the chart and line.all at once, and so does any linefill on it. Its getters read na and its setters do nothing. Past max_lines_count + 5 lines on the chart, the oldest go until max_lines_count are left, 50 by default, as with labels. A drawing placed at a bar before the one that made it, such as bar_index - 5, runs with a leak warning: on the chart it looks known earlier than it was.

line.new ​

pine
line.new(x1, y1, x2, y2, xloc, extend, color, style, width, force_overlay) → series line
line.new(x1, y1, x2, y2, xloc, extend, color, style, width, force_overlay, first_point, second_point) → series line

Makes a line between two points, and returns its handle.

In the second form, two chart.points stand in for the four coordinates. Left out there, xloc follows the first point: one made by chart.point.from_time places by time, any other by bar index.

ParameterDefaultDescription
x1
series int
The first end's bar, as a bar index, or a time in milliseconds under xloc.bar_time.
y1
series int/float
The first end's price.
x2
series int
The second end's bar.
y2
series int/float
The second end's price.
xloc
series string
xloc.bar_indexWhether the x values are bar indexes or times.
extend
series string
extend.noneextend.left, extend.right or extend.both carry the line on past its ends to the chart's edge.
color
series color
color.blueThe line's colour.
style
series string
line.style_solidSee line.style_*.
width
series int
1The width in pixels.
force_overlay
const bool
falsetrue draws on the price pane even from a script with a pane of its own.
first_point
chart.point
A chart.point for the first end.
second_point
chart.point
A chart.point for the second end.

line.copy ​

pine
line.copy(id) → series line

Also a method: id.copy().

A new line with every value of id. A deleted line copies too, and the copy is on the chart.

ParameterDescription
id
series line
The line to copy.

line.delete ​

pine
line.delete(id) → void

Also a method: id.delete().

Takes the line off the chart and out of line.all, with any linefill on it.

ParameterDescription
id
series line
The line.

line.all ​

pine
array<line> line.all

An array of every line the script has on the chart, oldest first. A deleted line, or one the count took, isn't in it.

line.get_x1 ​

pine
line.get_x1(id) → series int

Also a method: id.get_x1().

The first end's bar index, or its time under xloc.bar_time.

ParameterDescription
id
series line
The line.

line.get_x2 ​

pine
line.get_x2(id) → series int

Also a method: id.get_x2().

The second end's bar index, or its time under xloc.bar_time.

ParameterDescription
id
series line
The line.

line.get_y1 ​

pine
line.get_y1(id) → series float

Also a method: id.get_y1().

The first end's price.

ParameterDescription
id
series line
The line.

line.get_y2 ​

pine
line.get_y2(id) → series float

Also a method: id.get_y2().

The second end's price.

ParameterDescription
id
series line
The line.

line.get_price ​

pine
line.get_price(id, x) → series float

Also a method: id.get_price(x).

The line's price at bar index x.

It reads the straight line through both ends, so an x past either end gives the price the line would reach there, whatever its extend. A line whose ends share a bar reads y1.

ParameterDescription
id
series line
The line.
x
series int
The bar index.

line.set_x1 ​

pine
line.set_x1(id, x) → void

Also a method: id.set_x1(x).

Moves the first end to another bar.

ParameterDescription
id
series line
The line.
x
series int
The bar index, or the time under xloc.bar_time.

line.set_x2 ​

pine
line.set_x2(id, x) → void

Also a method: id.set_x2(x).

Moves the second end to another bar.

ParameterDescription
id
series line
The line.
x
series int
The bar index, or the time under xloc.bar_time.

line.set_y1 ​

pine
line.set_y1(id, y) → void

Also a method: id.set_y1(y).

Moves the first end to another price.

ParameterDescription
id
series line
The line.
y
series int/float
The price.

line.set_y2 ​

pine
line.set_y2(id, y) → void

Also a method: id.set_y2(y).

Moves the second end to another price.

ParameterDescription
id
series line
The line.
y
series int/float
The price.

line.set_xy1 ​

pine
line.set_xy1(id, x, y) → void

Also a method: id.set_xy1(x, y).

Moves the first end to another bar and price.

ParameterDescription
id
series line
The line.
x
series int
The bar index, or the time under xloc.bar_time.
y
series int/float
The price.

line.set_xy2 ​

pine
line.set_xy2(id, x, y) → void

Also a method: id.set_xy2(x, y).

Moves the second end to another bar and price.

ParameterDescription
id
series line
The line.
x
series int
The bar index, or the time under xloc.bar_time.
y
series int/float
The price.

line.set_first_point ​

pine
line.set_first_point(id, point) → void

Also a method: id.set_first_point(point).

Moves the first end to a point, read by the line's own xloc.

ParameterDescription
id
series line
The line.
point
chart.point
The chart.point.

line.set_second_point ​

pine
line.set_second_point(id, point) → void

Also a method: id.set_second_point(point).

Moves the second end to a point, read by the line's own xloc.

ParameterDescription
id
series line
The line.
point
chart.point
The chart.point.

line.set_xloc ​

pine
line.set_xloc(id, x1, x2, xloc) → void

Also a method: id.set_xloc(x1, x2, xloc).

Sets both ends' bars and whether they're bar indexes or times, together.

ParameterDescription
id
series line
The line.
x1
series int
The first end's bar index or time.
x2
series int
The second end's bar index or time.
xloc
series string
xloc.bar_index or xloc.bar_time.

line.set_extend ​

pine
line.set_extend(id, extend) → void

Also a method: id.set_extend(extend).

Sets whether the line carries on past its ends.

ParameterDescription
id
series line
The line.
extend
series string
extend.none, extend.left, extend.right or extend.both.

line.set_color ​

pine
line.set_color(id, color) → void

Also a method: id.set_color(color).

Sets the line's colour.

ParameterDescription
id
series line
The line.
color
series color
The colour.

line.set_style ​

pine
line.set_style(id, style) → void

Also a method: id.set_style(style).

Sets the line's style.

ParameterDescription
id
series line
The line.
style
series string
A line.style_* value.

line.set_width ​

pine
line.set_width(id, width) → void

Also a method: id.set_width(width).

Sets the line's width.

ParameterDescription
id
series line
The line.
width
series int
The width in pixels.

line.style_* ​

Values for a line's style.

Each is a const string.

NameWhat it means
line.style_arrow_bothA solid line with an arrowhead at each end.
line.style_arrow_leftA solid line with an arrowhead at the first end.
line.style_arrow_rightA solid line with an arrowhead at the second end.
line.style_dashedA dashed line.
line.style_dottedA dotted line.
line.style_solidAn unbroken line.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.