line

Chart lines — create and modify line drawings. The line namespace provides functions to draw lines on a chart with customizable colors, styles, and extending behavior.

Quick Example

  from pynecore.lib import close, bar_index, line, color, script

@script.indicator(title="Support Lines", overlay=True)
def main():
    # Draw a line connecting two price points
    support = line.new(
        x1=bar_index - 20,
        y1=close[20],
        x2=bar_index,
        y2=close,
        color=color.red,
        width=2,
        style=line.style_dashed
    )
    
    # Modify the line's appearance
    line.set_color(support, color.blue)
    line.set_width(support, 3)
  

Creation and Management

line.new()

Creates a new line object on the chart.

Overload 1: Using coordinates

ParameterTypeDescription
x1intBar index or UNIX time of the first point
y1floatPrice of the first point
x2intBar index or UNIX time of the second point
y2floatPrice of the second point
xlocxlocReference type: xloc.bar_index (default) or xloc.bar_time
extendextendExtending behavior (default: extend.none)
colorcolorLine color (default: color.blue)
styleline.LineEnumLine style (default: line.style_solid)
widthintLine width in pixels (default: 1)
force_overlayboolForce display on main chart pane (default: False)

Returns: line.Line

Overload 2: Using chart.point objects

ParameterTypeDescription
first_pointchart.pointStarting point of the line
second_pointchart.pointEnding point of the line
xlocxlocReference type (default: xloc.bar_index)
extendextendExtending behavior (default: extend.none)
colorcolorLine color (default: color.blue)
styleline.LineEnumLine style (default: line.style_solid)
widthintLine width in pixels (default: 1)
force_overlayboolForce display on main chart pane (default: False)

Returns: line.Line

line.copy()

Clones an existing line object.

ParameterTypeDescription
idline.LineLine object to copy

Returns: line.Line

  duplicate: line.Line = line.copy(original)
  

line.delete()

Deletes a line object from the chart. Does nothing if already deleted.

ParameterTypeDescription
idline.LineLine object to delete

Returns: None

Getters

line.get_x1()

Returns the bar index or UNIX time of the line’s first point.

ParameterTypeDescription
idline.LineLine object

Returns: int

  x: int = line.get_x1(my_line)
  

line.get_x2()

Returns the bar index or UNIX time of the line’s second point.

ParameterTypeDescription
idline.LineLine object

Returns: int

line.get_y1()

Returns the price of the line’s first point.

ParameterTypeDescription
idline.LineLine object

Returns: float

line.get_y2()

Returns the price of the line’s second point.

ParameterTypeDescription
idline.LineLine object

Returns: float

line.get_price()

Returns the interpolated price level of a line at a specified bar index.

ParameterTypeDescription
idline.LineLine object
xintBar index

Returns: float

  price: float = line.get_price(my_line, bar_index - 5)
  

Coordinate and Point Setters

line.set_x1()

Sets the bar index or UNIX time of the line’s first point.

ParameterTypeDescription
idline.LineLine object
xintNew bar index or UNIX time

Returns: None

line.set_x2()

Sets the bar index or UNIX time of the line’s second point.

ParameterTypeDescription
idline.LineLine object
xintNew bar index or UNIX time

Returns: None

line.set_y1()

Sets the price of the line’s first point.

ParameterTypeDescription
idline.LineLine object
yfloatNew price

Returns: None

line.set_y2()

Sets the price of the line’s second point.

ParameterTypeDescription
idline.LineLine object
yfloatNew price

Returns: None

line.set_xy1()

Sets both the bar index/time and price of the line’s first point.

ParameterTypeDescription
idline.LineLine object
xintNew bar index or UNIX time
yfloatNew price

Returns: None

line.set_xy2()

Sets both the bar index/time and price of the line’s second point.

ParameterTypeDescription
idline.LineLine object
xintNew bar index or UNIX time
yfloatNew price

Returns: None

line.set_xloc()

Sets the x-location mode and updates both x-coordinates of the line.

ParameterTypeDescription
idline.LineLine object
x1intNew first x-coordinate
x2intNew second x-coordinate
xlocxlocReference mode: xloc.bar_index or xloc.bar_time

Returns: None

line.set_first_point()

Sets the first point of the line using a chart.point object.

ParameterTypeDescription
idline.LineLine object
pointchart.pointNew first point

Returns: None

line.set_second_point()

Sets the second point of the line using a chart.point object.

ParameterTypeDescription
idline.LineLine object
pointchart.pointNew second point

Returns: None

Appearance Setters

line.set_color()

Sets the color of the line.

ParameterTypeDescription
idline.LineLine object
colorcolorNew line color

Returns: None

  line.set_color(my_line, color.red)
  

line.set_style()

Sets the line style (solid, dotted, dashed, or arrow variants).

ParameterTypeDescription
idline.LineLine object
styleline.LineEnumNew line style

Returns: None

  line.set_style(my_line, line.style_dashed)
  

line.set_width()

Sets the line width in pixels.

ParameterTypeDescription
idline.LineLine object
widthintNew width in pixels

Returns: None

  line.set_width(my_line, 3)
  

line.set_extend()

Sets the extending behavior of the line.

ParameterTypeDescription
idline.LineLine object
extendextendExtending type: extend.none, extend.left, extend.right, or extend.both

Returns: None

  line.set_extend(my_line, extend.both)
  

Collections

line.all

Returns an array of all line objects currently on the chart.

Type: list[line.Line]

  all_lines: list[line.Line] = line.all
  

Style Constants

ConstantDescription
line.style_solidSolid line
line.style_dottedDotted line
line.style_dashedDashed line
line.style_arrow_leftSolid line with arrow at first point
line.style_arrow_rightSolid line with arrow at second point
line.style_arrow_bothSolid line with arrows at both points

Compatibility

All functions and constants in the line namespace are fully implemented. NA values are handled gracefully — operations on NA line objects return NA values or have no effect for setters.