Appearance
table
How do you show a few values in a fixed place on the screen? Make a table once, with var, at one of nine positions in the pane, then write its cells with table.cell. A table doesn't sit on bars or prices, so it stays put while the chart scrolls. Filling it on the last bar alone is enough, since only the last bar's table shows.
pine
//@version=6
indicator("Close in a table", overlay = true)
var table t = table.new(position.top_right, 2, 1, border_width = 1)
if barstate.isfirst
table.cell(t, 0, 0, "Close", bgcolor = color.gray)
if barstate.islast
// table.cell on 0, 0 again would reset its grey: change the text alone.
table.cell_set_text(t, 0, 0, "Last close")
txt = str.tostring(close, format.mintick)
table.cell(t, 1, 0, txt, bgcolor = color.blue, text_color = color.white)A table made at a position where a live table already sits replaces it, as table.delete would. A deleted table has no cells, and writes to it do nothing. Tables let the pointer through to the chart, except for showing a cell's tooltip.
table.cell sets the whole cell
Each table.cell call sets every option of its cell: an option it leaves out goes back to its default, even if an earlier call set it. Only a merge stays. To change one option, use the table.cell_set_* function for it.
table.new
pine
table.new(position, columns, rows, bgcolor, frame_color, frame_width, border_color, border_width, force_overlay) → series tableMakes a table of columns by rows empty cells at a position in the pane, and returns its handle.
| Parameter | Default | Description |
|---|---|---|
positionseries string | One of position.top_left, position.top_center, position.top_right, position.middle_left, position.middle_center, position.middle_right, position.bottom_left, position.bottom_center and position.bottom_right. | |
columnsseries int | How many columns, at least 1. | |
rowsseries int | How many rows, at least 1. | |
bgcolorseries color | The table's fill behind its cells. Left out, none. | |
frame_colorseries color | The colour of the line round the table. Left out, none. | |
frame_widthseries int | 0 | That line's width in pixels. |
border_colorseries color | The colour of the lines between cells. Left out, none. | |
border_widthseries int | 0 | Those lines' width in pixels. |
force_overlayconst bool | false | true draws on the price pane even from a script with a pane of its own. |
table.cell
pine
table.cell(table_id, column, row, text, width, height, text_color, text_halign, text_valign, text_size, bgcolor, tooltip, text_font_family, text_formatting) → voidAlso a method: table_id.cell(column, row, text, width, height, text_color, text_halign, text_valign, text_size, bgcolor, tooltip, text_font_family, text_formatting).
Sets a cell's text and every one of its options.
Left out, a cell's text is "", its text colour color.black, its text centred both ways at size.auto, which draws as size.normal, with no fill, no tooltip, and its width and height fitted to its text. A cell outside the table does nothing.
Cells draw at TradingView's text sizes in pixels, size.tiny at 8, whatever the rest of the page uses. text_formatting changes nothing here yet.
| Parameter | Default | Description |
|---|---|---|
table_idseries table | The table. | |
columnseries int | The cell's column, from 0. | |
rowseries int | The cell's row, from 0. | |
textseries string | "" | The words. \n starts a new line. |
widthseries int/float | 0 | The cell's width as a percent of the pane's width. 0 fits it to its text. |
heightseries int/float | 0 | The cell's height as a percent of the pane's height. 0 fits it to its text. |
text_colorseries color | color.black | The text's colour. |
text_halignseries string | text.align_center | text.align_left, text.align_center or text.align_right. |
text_valignseries string | text.align_center | text.align_top, text.align_center or text.align_bottom. |
text_sizeseries string | size.auto | size.tiny, size.small, size.normal, size.large, size.huge or size.auto. |
bgcolorseries color | na | The cell's fill. |
tooltipseries string | "" | Words shown while the pointer is over the cell. |
text_font_familyseries string | font.family_default | font.family_default or font.family_monospace. |
text_formattingNo effect hereconst string | text.format_none | Bold or italic text on TradingView. It changes nothing here yet. |
table.cell_set_*
Each changes one option of one cell and leaves the cell's others as they are, where table.cell sets them all. A cell outside the table, or a deleted table, does nothing.
Each gives a void.
| Name | Takes | What it means |
|---|---|---|
table. | table_id: series table, column: series int, row: series int, bgcolor: series color | Sets the cell's fill. |
table. | table_id: series table, column: series int, row: series int, height: series int | Sets the cell's height. |
table. | table_id: series table, column: series int, row: series int, text: series string | Replaces the cell's text. |
table. | table_id: series table, column: series int, row: series int, text_color: series color | Sets the text's colour. |
table. | table_id: series table, column: series int, row: series int, text_font_family: series string | Sets the text's font. |
table.No effect here | table_id: series table, column: series int, row: series int, text_formatting: const string | Sets the text to bold or italic on TradingView. It changes nothing here yet. |
table. | table_id: series table, column: series int, row: series int, text_halign: series string | Sets the text's place across the cell. |
table. | table_id: series table, column: series int, row: series int, text_size: series string | Sets the text's size. |
table. | table_id: series table, column: series int, row: series int, text_valign: series string | Sets the text's place up and down the cell. |
table. | table_id: series table, column: series int, row: series int, tooltip: series string | Sets the words shown while the pointer is over the cell. |
table. | table_id: series table, column: series int, row: series int, width: series int | Sets the cell's width. |
| Parameter | Description |
|---|---|
table_idseries table | The table. |
columnseries int | The cell's column, from 0. |
rowseries int | The cell's row, from 0. |
bgcolorseries color | The colour. |
heightseries int | A percent of the pane's height. 0 fits it to its text. |
textseries string | The words. \n starts a new line. |
text_colorseries color | The colour. |
text_font_familyseries string | font.family_default or font.family_monospace. |
text_formattingconst string | text.format_none, text.format_bold, text.format_italic, or both added together. |
text_halignseries string | text.align_left, text.align_center or text.align_right. |
text_sizeseries string | size.tiny, size.small, size.normal, size.large, size.huge or size.auto. |
text_valignseries string | text.align_top, text.align_center or text.align_bottom. |
tooltipseries string | The words. |
widthseries int | A percent of the pane's width. 0 fits it to its text. |
table.merge_cells
pine
table.merge_cells(table_id, start_column, start_row, end_column, end_row) → voidAlso a method: table_id.merge_cells(start_column, start_row, end_column, end_row).
Merges a rectangle of cells into its top-left cell, which then spans them all and shows its own text. A later table.cell on that cell keeps the merge.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
start_columnseries int | The rectangle's first column. |
start_rowseries int | The rectangle's first row. |
end_columnseries int | Its last column. |
end_rowseries int | Its last row. |
table.clear
pine
table.clear(table_id, start_column, start_row, end_column, end_row) → voidAlso a method: table_id.clear(start_column, start_row, end_column, end_row).
Empties cells' text and fill.
It clears the whole table here
This engine empties the text and fill of every cell in the table, whatever range you give, and leaves the cells' other options. TradingView clears only the cells in the range, and the whole of each. To clear part of a table, write "" into those cells with table.cell.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
start_columnseries int | The range's first column. |
start_rowseries int | The range's first row. |
end_columnseries int | Its last column. |
end_rowseries int | Its last row. |
table.delete
pine
table.delete(table_id) → voidAlso a method: table_id.delete().
Takes the table off the chart. Its cells go with it, and writes to it do nothing.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
table.all
pine
array<table> table.allAn array of every table the script has on the chart, oldest first. A deleted or replaced table isn't in it.
table.set_position
pine
table.set_position(table_id, position) → voidAlso a method: table_id.set_position(position).
Moves the table to another of the nine positions.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
positionseries string | A position.* value, as in table.new. |
table.set_bgcolor
pine
table.set_bgcolor(table_id, bgcolor) → voidAlso a method: table_id.set_bgcolor(bgcolor).
Sets the table's fill behind its cells.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
bgcolorseries color | The colour. |
table.set_frame_color
pine
table.set_frame_color(table_id, frame_color) → voidAlso a method: table_id.set_frame_color(frame_color).
Sets the colour of the line round the table.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
frame_colorseries color | The colour. |
table.set_frame_width
pine
table.set_frame_width(table_id, frame_width) → voidAlso a method: table_id.set_frame_width(frame_width).
Sets the width of the line round the table.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
frame_widthseries int | The width in pixels. |
table.set_border_color
pine
table.set_border_color(table_id, border_color) → voidAlso a method: table_id.set_border_color(border_color).
Sets the colour of the lines between cells.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
border_colorseries color | The colour. |
table.set_border_width
pine
table.set_border_width(table_id, border_width) → voidAlso a method: table_id.set_border_width(border_width).
Sets the width of the lines between cells.
| Parameter | Description |
|---|---|
table_idseries table | The table. |
border_widthseries int | The width in pixels. |