Skip to content

polyline namespace

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.

FunctionPurpose
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.
  • Points are chart.point objects created with helpers like chart.point.from_time() or chart.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-transparent fill_color to shade the enclosed area.
  • Updating polylines every bar is expensive; limit recalculations to if barstate.islast when possible.
//@version=5
indicator("Session value area polyline", overlay=true, max_polylines_count=1)
sessionInput = input.session("0900-1600", "Session hours")
var polyline valueArea = na
var 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 + band
lower = 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)