Sidechair

array.new_table()

Browse the reference

Builds an array to hold references to tables, so a script can reach each dashboard by index.

Try it in the editor

Tables anchor to one of nine screen positions, so an array indexed by position or by purpose is a tidy way to reach a dashboard from anywhere in the script.

Slots are na until a table is stored in them, and the array holds references only. table.delete() takes a table off the chart, while shrinking the array does not.

Syntax

Pine Script
array.new_table(size: series int (optional), initial_value: series table (optional)) -> array<table>

Arguments

NameTypeDefaultDescription
sizeseries int0How many table slots to start with: 0 or more, up to 100,000. A small fixed size such as 2 fits a script with two dashboards.
initial_valueseries tablenaA table stored in every starting slot. Leave it out and each slot is na until a table is set into it.

Returns

array<table>: A new array that holds table references, with the requested number of slots, each one na unless initial_value was given.

Example

Pine ScriptLook up a dashboard by indexOpen in editor
//@version=6
indicator("array.new_table: dashboard by index", overlay = true)
var boards = array.new_table(2)
if barstate.isfirst
    array.set(boards, 0, table.new(position.top_right, 1, 2))
    array.set(boards, 1, table.new(position.bottom_left, 1, 1))
if barstate.islast
    trend = array.get(boards, 0)
    table.cell(trend, 0, 0, "Trend")
    table.cell(trend, 0, 1, close > open ? "Up" : "Down")
    table.cell(array.get(boards, 1), 0, 0, "Bars: " + str.tostring(bar_index + 1))
plot(close)

See also

Runs on Sidechair