polyline

The polyline namespace provides functions to create multi-segment line drawings on the chart. Each polyline connects an array of points sequentially, optionally with curved segments and fill color. Polylines are useful for drawing trend channels, patterns, or custom technical structures.

Quick Example

  from pynecore.lib import (
    polyline, chart, close, high, low, bar_index,
    color, script
)

@script.indicator(title="Polyline Pattern", overlay=True)
def main():
    # Create a simple trend channel using two points
    if bar_index == 50:
        point1: chart.point = chart.point(50, low[0])
        point2: chart.point = chart.point(100, high[0])
        points: list[chart.point] = [point1, point2]
        
        # Draw a curved, closed polyline with blue line and light fill
        pl: polyline = polyline.new(
            points=points,
            curved=True,
            closed=False,
            line_color=color.blue,
            fill_color=color.new(color.blue, 80),
            line_width=2
        )
  

Functions

polyline.new()

Creates a new polyline by connecting points sequentially with line segments.

ParameterTypeDescription
pointslist[chart.point]Array of points to connect
curvedboolUse curved line segments instead of straight (default: False)
closedboolConnect the last point back to the first (default: False)
xlocxlocUse xloc.bar_index (default) or xloc.bar_time for x-coordinate
line_colorcolorLine segment color (default: color.blue)
fill_colorcolor | NoneFill color inside closed polylines; None for no fill (default: None)
line_styleline_styleLine style: polyline.style_solid, style_dashed, etc. (default: solid)
line_widthintLine width in pixels (default: 1)
force_overlayboolDraw on main chart even if indicator is in separate pane (default: False)

Returns: polyline object, or na if points array is empty or contains na values.

Example:

  pt1: chart.point = chart.point(0, 100.0)
pt2: chart.point = chart.point(10, 105.0)
pl: polyline = polyline.new([pt1, pt2], line_color=color.green, line_width=2)
  

polyline.delete()

Removes a polyline from the chart. Has no effect if the polyline ID does not exist.

ParameterTypeDescription
idpolylinePolyline object to delete

Returns: None

Example:

  polyline.delete(pl)  # Removes the polyline
  

Variables

polyline.all

Returns an array of all polyline objects currently drawn by the script.

Type: list[polyline]

Example:

  all_polylines: list[polyline] = polyline.all
for pl in all_polylines:
    polyline.delete(pl)  # Delete all polylines
  

Constants

Line style constants for the line_style parameter:

ConstantUsage
polyline.style_solidSolid line (default)
polyline.style_dashedDashed pattern
polyline.style_dottedDotted pattern
polyline.style_arrow_leftArrow pointing left
polyline.style_arrow_rightArrow pointing right
polyline.style_arrow_bothArrows at both ends

Compatibility

All polyline functions are fully implemented. Polylines support curved and closed modes, custom line styles, and optional fill colors. Note that xloc.bar_time requires valid bar timestamps in the chart.point objects.