polyline.new() - Pine Script Function
polyline.new()
Section titled “polyline.new()”Overview
Section titled “Overview”Creates a new polyline instance and displays it on the chart, sequentially connecting all of the points in the points array with line segments. The segments in the drawing can be straight or curved depending on the curved parameter.
Syntax
Section titled “Syntax”polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width, force_overlay) → series polylineParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| points | array<chart.point> | An array of chart.point objects for the drawing to sequentially connect. |
Returns
Section titled “Returns”The ID of a new polyline object that a script can use in other polyline.*() functions.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("Polylines example", overlay = true)//@variable If `true`, connects all points in the polyline with curved line segments.bool curvedInput = input.bool(false, "Curve Polyline")//@variable If `true`, connects the first point in the polyline to the last point.bool closedInput = input.bool(true, "Close Polyline")//@variable The color of the space filled by the polyline.color fillcolor = input.color(color.new(color.blue, 90), "Fill Color")// Time and price inputsfor the polyline's points.p1x =input.time(0, "p1", confirm = true, inline = "p1")p1y = input.price(0, " ", confirm = true, inline = "p1")p2x = input.time(0, "p2", confirm = true, inline = "p2")p2y = input.price(0, " ", confirm = true, inline = "p2")p3x = input.time(0, "p3", confirm = true, inline = "p3")p3y = input.price(0, " ", confirm = true, inline = "p3")p4x = input.time(0, "p4", confirm = true, inline = "p4")p4y = input.price(0, " ", confirm = true, inline = "p4")p5x = input.time(0, "p5", confirm = true, inline = "p5")p5y = input.price(0, " ", confirm = true, inline = "p5")if barstate.islastconfirmedhistory //@variable An array of `chart.point` objectsfor the new polyline.var points = array.new<chart.point>() // Push new `chart.point` instances into the `points` array. points.push(chart.point.from_time(p1x, p1y))points.push(chart.point.from_time(p2x, p2y))points.push(chart.point.from_time(p3x, p3y))points.push(chart.point.from_time(p4x, p4y))points.push(chart.point.from_time(p5x, p5y)) // Add labelsfor each `chart.point` in `points`. l1p1 =label.new(points.get(0), text = "p1", xloc = xloc.bar_time, color = na)l1p2 = label.new(points.get(1), text = "p2", xloc = xloc.bar_time, color = na)l2p1 = label.new(points.get(2), text = "p3", xloc = xloc.bar_time, color = na)l2p2 = label.new(points.get(3), text = "p4", xloc = xloc.bar_time, color = na) // Create a new polyline that connects each `chart.point` in the `points` array, starting from the first. poly line.new(points, curved = curvedInput, closed = closedInput, fill_color = fillcolor, xloc = xloc.bar_time)