Appearance
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 polylineMakes 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.
| Parameter | Default | Description |
|---|---|---|
pointsarray<chart.point> | An array<chart.point>, in the order to join them. | |
curvedseries bool | false | true draws a smooth curve through the points instead of straight lines. |
closedseries bool | false | true joins the last point back to the first. |
xlocseries string | xloc.bar_index | Whether the points place by bar index or by time. |
line_colorseries color | color.blue | The line's colour. |
fill_colorseries color | na | The fill inside the shape. An open polyline fills as if its ends were joined. |
line_styleseries string | line.style_solid | line.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_widthseries int | 1 | The line's width in pixels. |
force_overlayconst bool | false | true draws on the price pane even from a script with a pane of its own. |
polyline.delete
pine
polyline.delete(id) → voidAlso a method: id.delete().
Takes the polyline off the chart and out of polyline.all.
| Parameter | Description |
|---|---|
idseries polyline | The polyline. |
polyline.all
pine
array<polyline> polyline.allAn 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
- chart.point
- line, for a single segment
- array, for arrays of drawings
- Drawings