Sidechair

polyline.new()

Browse the reference

Draws one path through an array of chart points, with optional curves, closing and fill.

Try it in the editor

polyline.new(points) draws straight segments between the points in array order. curved = true smooths the path into curves, and closed = true joins the last point back to the first.

line_color, line_style and line_width style the stroke, while fill_color shades the enclosed area, which suits closed shapes best. Points carry an index and a time, and xloc says which one the polyline reads.

The array is read when the polyline is created, so later pushes to it do not alter the drawing.

Syntax

Pine Script
polyline.new(points: array<chart.point>, curved: series bool (optional), closed: series bool (optional), xloc: series string (optional), line_color: series color (optional), fill_color: series color (optional), line_style: series string (optional), line_width: series int (optional), force_overlay: const bool (optional)) -> series polyline

Arguments

NameTypeDefaultDescription
pointsarray<chart.point>requiredAn array<chart.point> naming the vertices in the order the path visits them. It is read once, when the polyline is created.
curvedseries boolfalsetrue draws a smooth curve through the points; false, the default, joins them with straight segments.
closedseries boolfalsetrue adds a segment from the last point back to the first so the shape encloses an area. Defaults to false.
xlocseries stringxloc.bar_indexxloc.bar_index, the default, reads each point's bar index; xloc.bar_time reads the point's time field.
line_colorseries colorcolor.blueColor of the stroke along the path, blue by default. color.new() makes it translucent.
fill_colorseries colornaColor that fills the enclosed area. na, the default, leaves the shape unfilled.
line_styleseries stringline.style_solidline.style_solid, the default, line.style_dashed or line.style_dotted for the stroke of the path.
line_widthseries int1Thickness of the stroke in pixels, 1 by default. Use whole numbers from 1 upward.
force_overlayconst boolfalseWhen true the polyline is drawn on the main price pane even if the script runs in its own pane. Defaults to false.

Returns

series polyline: The new polyline.

Remarks

  • A polyline holds at most 10,000 points. Past max_polylines_count, set in indicator(), the oldest polyline is removed.

Example

Pine ScriptClosed shape around the last 4 closesOpen in editor
//@version=6
indicator("polyline.new: closed shape", overlay = true)
if barstate.islast
    pts = array.from(chart.point.from_index(bar_index - 3, close[3]), chart.point.from_index(bar_index - 2, close[2]), chart.point.from_index(bar_index - 1, close[1]), chart.point.from_index(bar_index, close))
    polyline.new(pts, closed = true, fill_color = color.new(color.blue, 85))

See also

Runs on Sidechair