Labels, lines and boxes
These draw objects at a bar and a price, rather than a value on every bar.
//@version=5
indicator("Range box", overlay = true)
var bx = box.new(bar_index, high, bar_index + 20, low, border_color = color.teal, bgcolor = color.new(color.teal, 85))
if barstate.islast
label.new(bar_index, high, "last", style = label.style_label_down, color = color.red)
line.new(bar_index - 20, close, bar_index, close, extend = extend.right, style = line.style_dashed)
Signatures
label.new(x, y, text, xloc, yloc, color, style, textcolor, size, ...)line.new(x1, y1, x2, y2, xloc, extend, color, style, width)box.new(left, top, right, bottom, border_color, border_width, border_style, extend, xloc, bgcolor, text, ...)linefill.new(line1, line2, color)shades the area between two lines. It disappears when either line is deleted.linefill.deleteandset_colorare available.polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width)draws through an array of points. See below.
Each has set_* and get_* functions (label.set_xy, line.set_xy2, box.set_rightbottom, line.get_price, ...) and delete.
Positions
xis a bar index by default. Withxloc.bar_timeit is a time in milliseconds. It may be in the future (bar_index + 10).yloc.abovebarandyloc.belowbarput a label just above the bar's high or below its low, ignoringy.- Label styles:
label_up/down/left/right/center, the four corner styles,none, and the shape styles (triangleup,circle, ...).
Polylines
A polyline connects many points with one line, and can fill the shape. Make the points with chart.point.
//@version=5
indicator("Triangle", overlay = true)
if barstate.islast
pts = array.new<chart.point>()
pts.push(chart.point.from_index(bar_index - 20, low))
pts.push(chart.point.from_index(bar_index - 10, high))
pts.push(chart.point.from_index(bar_index, low))
polyline.new(pts, closed = true, line_color = color.orange, fill_color = color.new(color.orange, 85))
chart.point.from_index(index, price),chart.point.from_time(time, price),chart.point.new(time, index, price)andchart.point.now(price). A point has.index,.timeand.price.curved = truebends the line smoothly through the points.closed = truejoins the last point to the first.fill_colorshades the inside.- With
xloc = xloc.bar_timethe points are placed by theirtime, not their index. - The points are fixed when the polyline is made.
polyline.delete(id)removes it. - At most 50 polylines by default. Raise it up to 100 with
max_polylines_count.
Keeping the count down
A plain l = line.new(...) makes a new line on every bar. To keep one and move it, declare it with var. To keep only the latest, call line.delete(l) on the old one first.
Past the limit, the oldest is deleted, as in Pine. The limit is 50 of each kind by default. Raise it up to 500 with max_lines_count, max_labels_count or max_boxes_count in indicator(...).
Things to know
- Calling a setter or
deleteonnadoes nothing. On anything that is not that kind of object, it is an error. - Objects are drawn on the chart in pixels and do not affect the price scale, so one far outside the visible prices is simply off screen.
- A label's
tooltipshows when you hover the label.