Sidechair

table.new()

Browse the reference

Creates an empty grid of columns by rows at one of nine screen positions and returns it as a table.

Try it in the editor

table.new(position.top_right, 3, 5) builds a grid of three columns and five rows in the top-right corner. Its size cannot change afterwards; to get a different grid, create another table. bgcolor, frame_color, frame_width, border_color and border_width style the table as a whole, and each cell can still override the fill.

Nothing is visible until cells are filled with table.cell(). Declare the table with var so it is created on the first bar only, and write the contents under barstate.islast, the one bar whose result stays on screen.

Syntax

Pine Script
table.new(position: series string, columns: series int, rows: series int, bgcolor: series color (optional), frame_color: series color (optional), frame_width: series int (optional), border_color: series color (optional), border_width: series int (optional), force_overlay: const bool (optional)) -> series table

Arguments

NameTypeDefaultDescription
positionseries stringrequiredScreen slot that anchors the table: a position.* constant such as position.top_right or position.bottom_center. Nine slots exist.
columnsseries intrequiredHow many columns the grid has, fixed at creation. Cell column numbers run from 0 to columns minus 1.
rowsseries intrequiredHow many rows the grid has, fixed at creation. Cell row numbers run from 0 to rows minus 1.
bgcolorseries colornaFill behind the whole table. na leaves it transparent, and a cell's own bgcolor paints over it.
frame_colorseries colornaColor of the outline around the whole table. It only shows once frame_width is above 0.
frame_widthseries int0Thickness in pixels of the outline around the whole table. The default 0 draws no outline.
border_colorseries colornaColor of the grid lines between cells. It only shows once border_width is above 0.
border_widthseries int0Thickness in pixels of the grid lines between cells. The default 0 draws no inner lines.
force_overlayconst boolfalseA compile-time bool. true draws the table on the main chart pane even when the script has its own pane.

Returns

series table: The table just created, empty until cells are filled.

Remarks

  • Without var the call runs on every bar and builds a new table each time, work that a single creation would have done.
  • frame_width and border_width both default to 0, so a table has neither outline nor grid lines until a width above 0 is given.
  • On Sidechair: a new table takes the place of the table already at that position.

Example

Pine ScriptA price ladder with a frameOpen in editor
//@version=6
indicator("table.new: price ladder", overlay = true)
var t = table.new(position.middle_right, 2, 4, bgcolor = color.new(color.black, 60), frame_color = color.gray, frame_width = 1)
names = array.from("High", "Close", "Low")
levels = array.from(high, close, low)
if barstate.islast
    table.cell(t, 0, 0, "Level", text_color = color.white)
    table.cell(t, 1, 0, "Price", text_color = color.white)
    for i = 0 to 2
        table.cell(t, 0, i + 1, names.get(i), text_color = color.silver)
        table.cell(t, 1, i + 1, str.tostring(levels.get(i), "#.##"), text_color = color.white)

See also

Runs on Sidechair