SuperCharting
Sign in Get started Account Open charts

Learn / Guides

"Pine Script polyline.new: draw shapes, zigzags and curves"

How polyline.new works in Pine Script v6 with chart.point, closed and filled shapes, curved lines, and a working zigzag example.

polyline.new(points) draws one line through a list of points. Where line.new() joins two points, a polyline joins as many as you like, so a whole zigzag, a triangle or a smooth curve is a single drawing. It can be closed into a shape and filled. SuperCharting supports polyline.new in Pine Script v6.

The points: chart.point

A polyline takes an array<chart.point>. Each point is a bar and a price:

FunctionPoint at
chart.point.from_index(bar_index, price)a bar number (default xloc.bar_index)
chart.point.from_time(time, price)a bar time (use xloc = xloc.bar_time on the polyline)
chart.point.now(price)the current bar

A working example: a filled triangle

//@version=6
indicator("Triangle", overlay = true)
hi = ta.highest(high, 30)
lo = ta.lowest(low, 30)
if barstate.islast
    pts = array.new<chart.point>()
    pts.push(chart.point.from_index(bar_index - 28, lo))
    pts.push(chart.point.from_index(bar_index - 20, hi))
    pts.push(chart.point.from_index(bar_index - 12, lo))
    polyline.new(pts, closed = true, line_color = color.purple,
         fill_color = color.new(color.purple, 80), line_width = 2)

closed = true joins the last point back to the first, and fill_color colours the inside.

A zigzag through pivots

//@version=6
indicator("Pivot zigzag", overlay = true, max_polylines_count = 1)
len = input.int(5, "Pivot length")
var pts = array.new<chart.point>()
ph = ta.pivothigh(high, len, len)
pl = ta.pivotlow(low, len, len)
if not na(ph)
    pts.push(chart.point.from_index(bar_index - len, ph))
if not na(pl)
    pts.push(chart.point.from_index(bar_index - len, pl))
if pts.size() > 50
    pts.shift()
var polyline zz = na
if barstate.islast and pts.size() > 1
    polyline.delete(zz)
    zz := polyline.new(pts, line_color = color.orange, line_width = 2)

The script collects pivot highs and lows as they are confirmed and draws one polyline through the last 50 of them on the newest bar.

The arguments

ArgumentWhat it does
curvedtrue draws a smooth curve through the points instead of straight segments
closedtrue joins the last point to the first
fill_colorcolours the inside of a closed shape
line_color, line_width, line_stylethe outline (line.style_solid, _dashed, _dotted)
xlocxloc.bar_index (default) or xloc.bar_time, matching how the points were made
force_overlaydraws on the price chart from a pane indicator, see the force_overlay guide

How it behaves

How to try it

Open the Pine Editor at the bottom of a chart, paste an example and click Add to chart. The free Pine Script checker checks a script without an account.

Frequently asked questions

What is the difference between polyline and line in Pine Script?

line.new() joins two points and can be moved with setters. polyline.new() joins any number of points, can be curved, closed and filled, and is redrawn instead of edited.

Why is my polyline not filled?

The fill needs closed = true and a fill_color. An open polyline has no inside to fill.

Try it on a live chart

SuperCharting is an AI-enabled charting and coding platform in your browser: charts, Pine-compatible scripts with AI Auto-fix, the Strategy Tester, alerts and the screener.

Create a free account More guides