Creating a table
table.new(position, columns, rows, bgcolor?, frame_color?, frame_width?,
border_color?, border_width?, force_overlay?)
positionis aposition.*constant:.top_left,.top_center,.top_right,.middle_left,.middle_center,.middle_right,.bottom_left,.bottom_center,.bottom_right.columns×rowsfixes the grid at creation; it cannot change later.- Both are capped at 20: a request for more rows or columns is clamped to 20, and
table.cellcalls outside the grid are ignored. For a longer list, lay the data out as several key/value column pairs (4 or 6 columns) instead of one tall table. force_overlay = truerenders the table on the price pane even inside an oscillator script.
var table t = table.new(position.top_right, 2, 4,
bgcolor=color.new(color.black, 20),
border_color=color.gray, border_width=1)
Table creation is usually guarded by var so the same table is reused across bars.
Writing cells
table.cell(table_id, column, row, text,
text_color?, bgcolor?, text_size?, text_halign?, text_valign?,
tooltip?, text_font_family?, text_formatting?)
table.cell(t, 0, 0, "Price", text_color=color.gray, text_halign=text.align_left)
table.cell(t, 1, 0, str.tostring(close, "#.##"),
text_color=color.white, text_halign=text.align_right)
Updating a single cell field without rewriting the whole row:
table.cell_set_text(t, 1, 0, str.tostring(close, "#.##"))
table.cell_set_bgcolor(t, 1, 0, close > open ? color.new(color.lime, 85) : color.new(color.red, 85))
table.cell_set_text_color(t, 1, 0, color.white)
Alignment and sizing
- Horizontal:
text.align_left,text.align_center,text.align_right. - Vertical:
text.align_top,text.align_center,text.align_bottom. - Size:
size.auto(default),size.tiny,size.small,size.normal,size.large,size.huge.
Text wrapping is controlled per-cell:
table.cell(t, 0, 0, "A long block of commentary that wraps nicely",
text_wrap=text.wrap_auto)
Styling
bgcolorontable.new()tints the whole table.bgcolorontable.cell()tints the cell only.text_formattingacceptstext.format_bold,text.format_italic,text.format_bold | text.format_italic.
Spans
Merge adjacent cells into one wider or taller cell:
table.merge_cells(t, 0, 0, 1, 0) // merge columns 0..1 of row 0 (header)
Only rectangular merges are supported. Writing to a merged cell writes to the top-left of the merged region.
Hiding and deleting
table.clear(t, 0, 0, 1, 3) // clear a sub-rectangle
table.delete(t) // remove the whole table
Setting a cell's text to "" renders a blank cell but keeps the slot allocated.
Idiomatic pattern — once per bar on the last bar
Tables are usually populated only on the last bar to avoid rewriting values that will immediately be overwritten:
var table t = table.new(position.top_right, 2, 3, bgcolor=color.new(color.black, 10))
if barstate.islast
table.cell(t, 0, 0, "Close", text_color=color.gray, text_halign=text.align_left)
table.cell(t, 1, 0, str.tostring(close, "#.##"),
text_color=color.white, text_halign=text.align_right)
table.cell(t, 0, 1, "RSI 14",
text_color=color.gray, text_halign=text.align_left)
table.cell(t, 1, 1, str.tostring(ta.rsi(close, 14), "0.0"),
text_color=color.white, text_halign=text.align_right)
See also
- Text and shapes —
label.newfor in-pane annotations - Colors