Skip to content

polyline ​

How do you draw a shape through many points at once? Put chart.points in an array and pass it to polyline.new: it joins them in order with straight lines, or a smooth curve with curved = true, and closed = true joins the last point back to the first. A point with an na bar or price is left out of the line.

pine
//@version=6
indicator("Last 20 closes", overlay = true)
if barstate.islast
    array<chart.point> pts = array.new<chart.point>()
    for i = 19 to 0
        pts.push(chart.point.from_index(bar_index - i, close[i]))
    // One drawing through all 20 points, smoothed.
    polyline.new(pts, curved = true, line_color = color.orange, line_width = 2)

A polyline keeps the points it was made with: changing the array afterwards doesn't move it, and nothing can. To change one, delete it and make another. A deleted polyline leaves the chart and polyline.all and keeps no points. Past max_polylines_count + 5 polylines on the chart, the oldest go until max_polylines_count are left, 50 by default. A drawing placed at a bar before the one that made it, such as bar_index - 5, runs with a leak warning: on the chart it looks known earlier than it was.

polyline.new ​

pine
polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width, force_overlay) → series polyline

Makes a polyline through the points in order, and returns its handle.

Left out, xloc follows the first point: one made by chart.point.from_time places by time, any other by bar index.

ParameterDefaultDescription
points
array<chart.point>
An array<chart.point>, in the order to join them.
curved
series bool
falsetrue draws a smooth curve through the points instead of straight lines.
closed
series bool
falsetrue joins the last point back to the first.
xloc
series string
xloc.bar_indexWhether the points place by bar index or by time.
line_color
series color
color.blueThe line's colour.
fill_color
series color
naThe fill inside the shape. An open polyline fills as if its ends were joined.
line_style
series string
line.style_solidline.style_solid, line.style_dashed or line.style_dotted. An arrow style draws a solid line with no arrowheads here, where TradingView draws them.
line_width
series int
1The line's width in pixels.
force_overlay
const bool
falsetrue draws on the price pane even from a script with a pane of its own.

polyline.delete ​

pine
polyline.delete(id) → void

Also a method: id.delete().

Takes the polyline off the chart and out of polyline.all.

ParameterDescription
id
series polyline
The polyline.

polyline.all ​

pine
array<polyline> polyline.all

An array of every polyline the script has on the chart, oldest first. A deleted polyline, or one the count took, isn't in it.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.