Skip to content

A table dashboard ​

How do you show a few current numbers in a corner of the chart? Make a table once with var, then fill its cells on the last bar.

pine
//@version=6
indicator("Dashboard", overlay = true)
// var: one table for the whole run, not a new one every bar
var table t = table.new(position.top_right, 2, 4, border_width = 1)
float change = (close / close[1] - 1) * 100
float rsi = ta.rsi(close, 14)
float ret = math.log(close / close[1])
float vol30 = ta.stdev(ret, 30) * math.sqrt(365) * 100

if barstate.islast
    table.cell(t, 0, 0, "Close")
    table.cell(t, 1, 0, str.tostring(close, format.mintick))
    table.cell(t, 0, 1, "Change")
    table.cell(t, 1, 1, str.tostring(change, "0.00") + "%",
      text_color = change >= 0 ? color.teal : color.red)
    table.cell(t, 0, 2, "RSI 14")
    table.cell(t, 1, 2, str.tostring(rsi, "0.0"))
    table.cell(t, 0, 3, "Vol 30d")
    table.cell(t, 1, 3, str.tostring(vol30, "0.0") + "%")

How it works ​

  • var table t = table.new(...) makes the table on the first bar and keeps it. Without var, each bar would make a new table.
  • table.new(position.top_right, 2, 4) is two columns by four rows, pinned to the chart's top right.
  • The values are computed on every bar, outside the if, so ta.rsi and ta.stdev see their whole history.
  • if barstate.islast fills the cells only on the last bar, since a table shows only its last state. On a live chart that bar runs again on every tick, so the cells follow the price.
  • str.tostring(close, format.mintick) writes the close to the symbol's tick size, and "0.00" writes two decimals.
  • vol30 is the standard deviation of 30 daily log returns, annualised over 365 days, which suits a coin. Use 252 for a share.

Traps ​

  • A table is drawn, not data. Nothing else in the terminal reads its cells. To hand values on, plot them or, in AmenoScript, write a report.
  • barstate.islast is fine here. It is a live-only name, and leak-safe AmenoScript allows it in a table because a table decides nothing. In a leak-safe run the last bar is the last closed one, so the same table would show the last close, not the live price.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.