Draws one path through an array of chart points, with optional curves, closing and fill.
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
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 polylineArguments
| Name | Type | Default | Description |
|---|---|---|---|
| points | array<chart. | required | An array<chart.point> naming the vertices in the order the path visits them. It is read once, when the polyline is created. |
| curved | series bool | false | true draws a smooth curve through the points; false, the default, joins them with straight segments. |
| closed | series bool | false | true adds a segment from the last point back to the first so the shape encloses an area. Defaults to false. |
| xloc | series string | xloc. | xloc.bar_index, the default, reads each point's bar index; xloc.bar_time reads the point's time field. |
| line_color | series color | color. | Color of the stroke along the path, blue by default. color.new() makes it translucent. |
| fill_color | series color | na | Color that fills the enclosed area. na, the default, leaves the shape unfilled. |
| line_style | series string | line. | line.style_solid, the default, line.style_dashed or line.style_dotted for the stroke of the path. |
| line_width | series int | 1 | Thickness of the stroke in pixels, 1 by default. Use whole numbers from 1 upward. |
| force_overlay | const bool | false | When 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
//@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