Sidechair

line.new()

Browse the reference

Draws a straight segment, ray or full line between two points and returns the line object.

Try it in the editor

line.new(bar_index - 10, low, bar_index, high) joins the low ten bars ago to the current high. By default x1 and x2 are bar indexes; with xloc = xloc.bar_time they are millisecond timestamps such as time or time + 86400000.

extend continues the segment along its own slope: extend.right past the second point, extend.left before the first, extend.both in both directions. style picks solid, dashed, dotted or an arrow head, and width sets the stroke in pixels.

A line created on every bar leaves a line per bar. Create it once with var and move it with line.set_xy1() and line.set_xy2(), or delete the old one with line.delete().

Syntax

Pine Script
line.new(x1: series int, y1: series int/float, x2: series int, y2: series int/float, xloc: series string (optional), extend: series string (optional), color: series color (optional), style: series string (optional), width: series int (optional), force_overlay: const bool (optional)) -> series line
line.new(first_point: chart.point, second_point: chart.point, xloc: series string (optional), extend: series string (optional), color: series color (optional), style: series string (optional), width: series int (optional), force_overlay: const bool (optional)) -> series line

Arguments

NameTypeDefaultDescription
x1series intrequiredBar index of the first point, or a millisecond timestamp when xloc is xloc.bar_time. A na value leaves nothing to draw.
y1series int/floatrequiredPrice of the first point on the chart's price scale. A na price leaves nothing to draw.
x2series intrequiredBar index of the second point, or a millisecond timestamp when xloc is xloc.bar_time. It may be left of x1.
y2series int/floatrequiredPrice of the second point on the chart's price scale. Equal to y1 gives a horizontal line.
xlocseries stringxloc.bar_indexPicks the coordinate kind: xloc.bar_index (default) reads bar indexes, xloc.bar_time reads millisecond timestamps.
extendseries stringextend.noneextend.none (default) stops at the two points; extend.left, extend.right and extend.both continue the line along its slope.
colorseries colorcolor.blueColor of the line, blue by default. color.new() makes it translucent; na keeps the line but draws nothing.
styleseries stringline.style_solidline.style_solid (default), line.style_dashed, line.style_dotted, line.style_arrow_left, line.style_arrow_right or line.style_arrow_both.
widthseries int1Thickness in pixels, 1 by default. Use whole numbers from 1 upward; bigger values draw a heavier stroke.
force_overlayconst boolfalseWhen true the line is drawn on the main price pane even if the script runs in its own pane. Defaults to false.
first_pointchart.pointrequiredA chart.point holding the index or time and the price of the first end of the line.
second_pointchart.pointrequiredA chart.point holding the index or time and the price of the second end of the line.

Returns

series line: The new line, which later calls can edit or delete.

Remarks

  • Past max_lines_count the oldest line is removed, 50 by default.
  • On Sidechair: max_lines_count above 500 is lowered to 500, and a width below 1 is drawn at 1.

Examples

Pine ScriptSegment between consecutive pivot highsOpen in editor
//@version=6
indicator("line.new: pivot trendline", overlay = true)
ph = ta.pivothigh(high, 5, 5)
var int x0 = na
var float y0 = na
if not na(ph)
    if not na(x0)
        line.new(x0, y0, bar_index - 5, ph, color = color.red, width = 2)
    x0 := bar_index - 5
    y0 := ph
Pine ScriptDashed ray from each session openOpen in editor
//@version=6
indicator("line.new: open ray", overlay = true)
if timeframe.change("D")
    line.new(bar_index, open, bar_index + 1, open, extend = extend.right, style = line.style_dashed, color = color.gray)

See also

Runs on Sidechair