table namespace
Overview
Section titled “Overview”The table namespace draws grid-based dashboards in Pine scripts. Tables are perfect for scorecards, last-trade stats, performance summaries, or watchlist-style panels rendered directly on the chart canvas.
Charts allow a limited number of tables (default 10). Create the table once with var and reuse it—otherwise you’ll hit the “too many tables” runtime error.
Common helpers
Section titled “Common helpers”| Function | Purpose |
|---|---|
table.new(position, columns, rows, bgcolor, frame_color, frame_width) | Create a table handle at the desired chart position. |
table.cell(table_id, column, row, text, text_color, bgcolor) | Populate a single cell. |
table.cell_set_text(table_id, column, row, text) | Update text without touching other styling. |
table.cell_set_bgcolor(table_id, column, row, color) | Recolor a cell dynamically. |
table.merge_cells(table_id, column, row, columns, rows) | Span content across multiple cells. |
table.clear(table_id) | Reset the table contents. |
Remarks
Section titled “Remarks”- Coordinates use zero-based indexing: column 0 is the leftmost cell, row 0 is the top.
- Tables remain static unless you update them. Wrap updates inside
if barstate.islastwhen you only need to refresh on the newest bar. - Combine with
str.format()andsyminfo.*metadata to present human-readable metrics.
Example
Section titled “Example”//@version=5indicator("Strategy dashboard", overlay=true, max_labels_count=0)
var table dash = table.new(position.top_right, columns=2, rows=4, bgcolor=color.new(color.black, 70), frame_color=color.new(color.white, 10))
winRate = input.float(55.0, "Win rate", step=0.1)avgWin = input.float(1.8, "Avg win (R)", step=0.1)avgLoss = input.float(1.0, "Avg loss (R)", step=0.1)lastTrade = input.string("Long", "Last trade side")
expectancy = winRate / 100 * avgWin - (1 - winRate / 100) * avgLoss
if barstate.islast table.cell(dash, 0, 0, "Symbol", text_color=color.white) table.cell(dash, 1, 0, syminfo.ticker, text_color=color.white)
table.cell(dash, 0, 1, "Win rate", text_color=color.new(color.white, 0)) table.cell(dash, 1, 1, str.tostring(winRate, "#.0") + "%", text_color=color.new(color.white, 0))
table.cell(dash, 0, 2, "Expectancy", text_color=color.new(color.white, 0)) table.cell(dash, 1, 2, str.tostring(expectancy, "#.00"), text_color = expectancy >= 0 ? color.green : color.red)
table.cell(dash, 0, 3, "Last trade", text_color=color.white) table.cell(dash, 1, 3, lastTrade, text_color = lastTrade == "Long" ? color.green : color.red)