polyline namespace
polyline
Section titled “polyline”Overview
Section titled “Overview”The polyline namespace lets you render custom drawings composed of multiple points. Provide an array of chart.point entries and Pine links them in order, creating trend cones, channels, or free-form regions. You can control curvature, closing behaviour, stroke style, and fill color.
Increase max_polylines_count in indicator() or strategy() when you plan to keep multiple polylines alive. Forgetting to reuse handles leads to the “too many polylines” runtime error.
Common helpers
Section titled “Common helpers”| Function | Purpose |
|---|---|
polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width, force_overlay) | Create a polyline and return its handle. |
polyline.delete(id) | Remove the drawing. |
polyline.all() | Return an array containing the IDs of every polyline currently drawn by the script. |
Remarks
Section titled “Remarks”- Points are
chart.pointobjects created with helpers likechart.point.from_time()orchart.point.new(bar_index, price). Mixing x-locations (bar index vs bar time) is not allowed. - When
closed=true, the first and last vertices connect automatically. Provide a semi-transparentfill_colorto shade the enclosed area. - Updating polylines every bar is expensive; limit recalculations to
if barstate.islastwhen possible.
Example
Section titled “Example”//@version=5indicator("Session value area polyline", overlay=true, max_polylines_count=1)
sessionInput = input.session("0900-1600", "Session hours")
var polyline valueArea = navar points = array.new<chart.point>()
if ta.change(time(timeframe.period, sessionInput)) != 0 array.clear(points)
// Track high-volume node approximation with VWAP bands.vwap = ta.vwap(close)band = ta.stdev(close, 50)
upper = vwap + bandlower = vwap - band
if barstate.islast // Build a four-point loop (lower-left → lower-right → upper-right → upper-left). array.clear(points) array.push(points, chart.point.from_index(bar_index - 50, lower)) array.push(points, chart.point.from_index(bar_index, lower)) array.push(points, chart.point.from_index(bar_index, upper)) array.push(points, chart.point.from_index(bar_index - 50, upper))
if not na(valueArea) polyline.delete(valueArea)
valueArea := polyline.new(points, curved=false, closed=true, line_color=color.new(color.blue, 0), fill_color=color.new(color.blue, 85), line_width=2, force_overlay=true)