Labels, lines, boxes and tables
Draw objects you can keep, move and delete, and build a dashboard.
Besides per-bar plots, scripts can create objects: label(), line(), box(), polyline() and table(). Each returns a handle. Keep it with var, change it with update(), remove it with delete(). x positions are bar numbers: bar_index - 10 is ten bars back, bar_index + 5 five bars into the future.
indicator("Fair value gaps", overlay = true)
var gaps = array()
if low > high[2]
gaps.push(box(bar_index - 2, low, bar_index + 10, high[2], bg = fade(teal, 15), border = na, text = "FVG", size = tiny))
if gaps.size() > 6
delete(gaps[0])
gaps.shift()indicator("Day high line", overlay = true)
var dayHigh = line(bar_index, high, bar_index + 1, high, color = amber, extend = right)
if new_session or high > get(dayHigh, "y1")
dayHigh.update(x1 = bar_index, y1 = high, x2 = bar_index + 1, y2 = high)A table() pins a grid to a corner of the chart. Create it once with var and fill it on the last bar with cell().
indicator("Stats", overlay = true)
r = rsi(close, 14)
range = atr(14)
var board = table("top_right", 2, 2)
if last_bar
cell(board, 0, 0, "RSI 14", color = gray)
cell(board, 1, 0, str(r, 1))
cell(board, 0, 1, "ATR 14", color = gray)
cell(board, 1, 1, str(range, 2))Key takeaways
- Drawings return handles: keep, update, delete.
- x is a bar number; y is a price.
- Tables are dashboards pinned to a corner.