Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Using Tables in TradingView Pinescript – Tutorial

9 min read

A Pine Script table is a grid of cells that stays pinned to one of nine fixed positions on your TradingView chart, so you can show indicator values, trade details or a signal dashboard without drawing labels all over the price bars. You create it once with table.new(), fill it with table.cell(), and update it on the last bar. This tutorial covers five practical uses, a complete indicator dashboard example, and an updated Pine Script v6 version.

Tables in TradingView Pine Script provide an effective way to organize and display data directly on the chart interface. This is especially useful for traders who need to see multiple indicators or calculations at a glance without cluttering the main chart area.

Key Takeaways

  • table.new() creates the table (position, columns, rows, borders); table.cell() writes text and colours into one cell.
  • Declare the table with var so it is created only once, and update cells inside if barstate.islast, because only the final state on the last bar is visible.
  • A script can show at most nine tables at once, one per position (corners, edge midpoints and centre).
  • Pine Script v6 is the current version; the v5 example below still works, and an updated v6 version with two bug fixes is included.
  • Common uses: indicator dashboards, trade management panels, multi-timeframe scanners, option premium dashboards and backtest summaries.

Five Practical Uses of a Pine Script Table

Tables in TradingView Pine Script offer versatile applications for enhancing trading strategies and visual aids on charts. Here are five practical applications of a Pine Script table that can be created using tables in Pine Script:

Pine Script V6 AI Masterclass

TRADINGVIEW

Pine Script V6 AI Masterclass

Write, debug and backtest TradingView indicators and strategies faster with AI as your coding partner.

  • Pine Script V6 from the ground up
  • Indicators, strategies and alerts
  • AI-assisted coding workflow
  1. Indicator Dashboard: A table can be used to create an indicator dashboard that summarizes key trading indicators like moving averages, RSI, MACD, and Bollinger Bands. This dashboard provides a quick overview of various indicator values at a glance, helping traders make informed decisions without having to switch between different chart setups.
  2. Trade Management Panel: Implement a trade management panel that displays real-time information about current trades, such as entry price, current price, stop loss levels, and potential profit or loss. This helps traders manage their open positions more effectively and adjust their strategies on the fly.
  3. Multi-Timeframe Trend Scanner: Show the trend state (above or below a moving average, Supertrend direction, RSI zone) for 5 min, 15 min, 60 min and daily in one grid, using request.security() for each timeframe. You see alignment across timeframes without flipping charts.
  4. Options Straddle or Premium Dashboard: Display ATM strike, call and put premium, combined straddle price and its change for the day. This is how the simple option straddle dashboard in Pine Script is built.
  5. Strategy Performance Summary: In a strategy script, print net profit, win rate, profit factor and maximum drawdown from the strategy.* variables into a corner table, so the key backtest numbers stay visible while you scroll the chart.

Pine Script Table Basics: table.new() and table.cell()

A table in Pine Script is created using table.new() function where you can specify its position, number of columns, rows, and various style attributes like border color and width. Once created, you can add or modify data in the table using table.cell() to set or update cell values.

These are the table functions you will use most often, as described in the official TradingView Pine Script tables documentation:

FunctionWhat it does
table.new()Creates the table and returns its ID. Sets position, number of columns and rows, background, border and frame. Nothing is shown until cells are filled.
table.cell()Defines one cell: text, text colour, size, alignment, background, tooltip. Each call overwrites all properties of that cell.
table.cell_set_text() and other table.cell_set_*()Changes a single property of an existing cell and leaves the rest untouched.
table.merge_cells()Merges a rectangular range of cells, useful for a title row that spans the full width.
table.clear()Removes the content of a range of cells.
table.delete()Deletes the table object.
Pine Script table functions

A Pine Script table can be anchored to position.top_left, top_center, top_right, middle_left, middle_center, middle_right, bottom_left, bottom_center or bottom_right. Tables do not move when you scroll or zoom the chart, which is exactly why they work well for dashboards.

Example: Indicator Dashboard Table (Pine Script v5)

The script below builds a 4 column by 6 row table showing open, close, change percent, RSI, ATR and volume, along with the 50, 100 and 200 period SMA and EMA values.

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © algostudio

//@version=5
indicator("Table with Indicators", overlay=true)

// Input Variables for Table and Table Display Settings

textColor = input.color(defval = color.black, title = "Text Color")
showTable = input.bool(true, "Show Desktop Table?")
tablePosition = input.string(defval = "Top Right", title = "Table Position", 
  options=["Top Right", "Bottom Right", "Middle Right", "Bottom Center", "Middle Left"])
tableSize = input.string(defval = "Small", title = "Table Size", options = ["Small", "Large", "Medium"])


// Function to Get Table Position
gettablePos(pos) =>
    switch pos
        "Top Right" => position.top_right
        "Bottom Right" => position.bottom_right
        "Middle Right" => position.middle_right
        "Bottom Center" => position.bottom_center
        "Middle Left" => position.bottom_left

// Function to get the Table Size
gettableSize(size) =>
    switch size
        "Small" => size.small
        "Large" => size.large
        "Medium" => size.normal

// Creating Tables
var table myTable = table.new(gettablePos(tablePosition), 4, 6, border_width=4, 
  border_color=color.gray, frame_color=color.gray, frame_width=4)


// Variables for SMA and EMA
sma1 = math.round(ta.sma(close, 50),2)
sma2 = math.round(ta.sma(close, 100),2)
sma3 = math.round(ta.sma(close, 200),2)
ema1 = math.round(ta.ema(close, 50),2)
ema2 = math.round(ta.ema(close, 100),2)
ema3 = math.round(ta.ema(close, 200),2)

rsi = math.round(ta.rsi(close,14),2)
atr = math.round(ta.atr(14),2)
roc = math.round(ta.roc(close,1),2)


// Function to Plot Table
plotTable(tbl, tblSize) =>
    // Define table content
    openPrice = str.tostring(open)
    closePrice = str.tostring(close)
    changePercent = str.tostring(roc) + " %"
    volumeData = str.tostring(volume)
    rsiData = str.tostring(rsi)
    atrData = str.tostring(atr)

    // Set table cells
    table.cell(tbl, 0, 0, bgcolor=color.black, text_color=color.white, text="Open Price", text_size = tblSize)
    table.cell(tbl, 0, 1, bgcolor=color.black, text_color=color.white, text="Close Price", text_size = tblSize)
    table.cell(tbl, 0, 2, bgcolor=color.black, text_color=color.white, text="Change Percent", text_size = tblSize)
    table.cell(tbl, 0, 3, bgcolor=color.black, text_color=color.white, text="RSI", text_size = tblSize)
    table.cell(tbl, 0, 4, bgcolor=color.black, text_color=color.white, text="ATR", text_size = tblSize)
    table.cell(tbl, 0, 5, bgcolor=color.black, text_color=color.white, text="Volume", text_size = tblSize)

    // Set values in table cells
    table.cell(tbl, 1, 0, bgcolor=color.black, text_color=color.white, text=openPrice, text_size = tblSize)
    table.cell(tbl, 1, 1, bgcolor=color.black, text_color=color.white, text=closePrice, text_size = tblSize)
    table.cell(tbl, 1, 2, bgcolor=color.black, text_color=color.white, text=changePercent, text_size = tblSize)
    table.cell(tbl, 1, 3, bgcolor=color.lime, text_color=color.white, text=rsiData, text_size = tblSize)
    table.cell(tbl, 1, 4, bgcolor=color.black, text_color=color.white, text=atrData, text_size = tblSize)
    table.cell(tbl, 1, 5, bgcolor=color.black, text_color=color.white, text=volumeData, text_size = tblSize)

    // Additional rows for SMA and EMA values
    table.cell(tbl, 2, 0, bgcolor=color.gray, text_color=color.white, text="SMA 50", text_size = tblSize)
    table.cell(tbl, 2, 1, bgcolor=color.gray, text_color=color.white, text="SMA 100", text_size = tblSize)
    table.cell(tbl, 2, 2, bgcolor=color.gray, text_color=color.white, text="SMA 200", text_size = tblSize)
    table.cell(tbl, 2, 3, bgcolor=color.gray, text_color=color.white, text="EMA 50", text_size = tblSize)
    table.cell(tbl, 2, 4, bgcolor=color.gray, text_color=color.white, text="EMA 100", text_size = tblSize)
    table.cell(tbl, 2, 5, bgcolor=color.gray, text_color=color.white, text="EMA 200", text_size = tblSize)

    // Display SMA and EMA values
    table.cell(tbl, 3, 0, bgcolor=color.black, text_color=color.white, text=str.tostring(sma1), text_size = tblSize)
    table.cell(tbl, 3, 1, bgcolor=color.black, text_color=color.white, text=str.tostring(sma2), text_size = tblSize)
    table.cell(tbl, 3, 2, bgcolor=color.black, text_color=color.white, text=str.tostring(sma3), text_size = tblSize)
    table.cell(tbl, 3, 3, bgcolor=color.black, text_color=color.white, text=str.tostring(ema1), text_size = tblSize)
    table.cell(tbl, 3, 4, bgcolor=color.black, text_color=color.white, text=str.tostring(ema2), text_size = tblSize)
    table.cell(tbl, 3, 5, bgcolor=color.black, text_color=color.white, text=str.tostring(ema3), text_size = tblSize)

// Call the plotting function at the last bar
//if barstate.islast
if showTable
    plotTable(myTable, gettableSize(tableSize))
    

How the Pine Script Table Code Works

Here’s a simplified explanation of the provided Pine Script code that utilizes tables:

  • Initialization: The script starts with basic settings such as the script name and version. The table settings are taken as inputs, allowing the user to customize text color, whether to show the table, its position, and size.
  • Position and Size Functions: Functions gettablePos() and gettableSize() are used to determine the position and size of the table based on user inputs.
  • Creating the Table: A table named myTable is initialized with specified position, columns, rows, and style settings like border and frame colors.
  • Indicator Calculations: Several key trading indicators like simple moving averages (SMA), exponential moving averages (EMA), Relative Strength Index (RSI), Average True Range (ATR), and rate of change (ROC) are calculated.
  • Filling the Table: The plotTable() function is designed to fill the table with calculated data:
    • Labels: The first row contains labels such as “Open Price”, “Close Price”, etc.
    • Data: The subsequent rows display corresponding values like open, close, change percentage, volume, etc.
    • Indicator Values: Additional rows are used to display values of SMAs and EMAs.
  • Display Control: The table is only plotted if the showTable input is true, allowing users to toggle the display of the table.

Updated Version (2026): Pine Script Table in v6

Pine Script v6 is now the default version in the TradingView editor. The v5 code above still runs, but while refreshing this tutorial I made a few changes worth knowing:

  • Bug fix: the “Middle Left” input was mapped to position.bottom_left. It now maps to position.middle_left.
  • Last-bar updates: the cells are filled only when barstate.islast is true. The original script rewrote all 24 cells on every historical bar, which wastes resources since only the last update is visible.
  • Text colour input used: the textColor input was declared but never applied. It is now passed to every cell.
  • Cleaner formatting: prices use format.mintick and volume uses format.volume instead of rounding manually.
  • Loop instead of 24 lines: labels and values are stored in arrays and written with a for loop, which makes it easy to add rows.
//@version=6
indicator("Table with Indicators", overlay = true)

// Inputs
textColor     = input.color(color.white, "Text Color")
showTable     = input.bool(true, "Show Desktop Table?")
tablePosition = input.string("Top Right", "Table Position",
     options = ["Top Right", "Bottom Right", "Middle Right", "Bottom Center", "Middle Left"])
tableSize     = input.string("Small", "Table Size", options = ["Small", "Large", "Medium"])

// Map the input strings to Pine constants (Middle Left now maps to position.middle_left)
gettablePos(pos) =>
    switch pos
        "Top Right"     => position.top_right
        "Bottom Right"  => position.bottom_right
        "Middle Right"  => position.middle_right
        "Bottom Center" => position.bottom_center
        "Middle Left"   => position.middle_left
        => position.top_right

gettableSize(sz) =>
    switch sz
        "Small"  => size.small
        "Large"  => size.large
        "Medium" => size.normal
        => size.small

// Create the table once
var table myTable = table.new(gettablePos(tablePosition), 4, 6, border_width = 4,
     border_color = color.gray, frame_color = color.gray, frame_width = 4)

// Indicator values are calculated on every bar
sma50  = ta.sma(close, 50)
sma100 = ta.sma(close, 100)
sma200 = ta.sma(close, 200)
ema50  = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)
rsi    = ta.rsi(close, 14)
atr    = ta.atr(14)
roc    = ta.roc(close, 1)

// Fill the table only on the last bar, where it is visible
if showTable and barstate.islast
    sz       = gettableSize(tableSize)
    labels   = array.from("Open Price", "Close Price", "Change Percent", "RSI", "ATR", "Volume")
    values   = array.from(str.tostring(open, format.mintick), str.tostring(close, format.mintick),
                 str.tostring(roc, "#.##") + " %", str.tostring(rsi, "#.##"),
                 str.tostring(atr, format.mintick), str.tostring(volume, format.volume))
    maLabels = array.from("SMA 50", "SMA 100", "SMA 200", "EMA 50", "EMA 100", "EMA 200")
    maValues = array.from(sma50, sma100, sma200, ema50, ema100, ema200)
    for i = 0 to 5
        table.cell(myTable, 0, i, array.get(labels, i), text_color = textColor, bgcolor = color.black, text_size = sz)
        table.cell(myTable, 1, i, array.get(values, i), text_color = textColor, bgcolor = i == 3 ? color.lime : color.black, text_size = sz)
        table.cell(myTable, 2, i, array.get(maLabels, i), text_color = textColor, bgcolor = color.gray, text_size = sz)
        table.cell(myTable, 3, i, str.tostring(array.get(maValues, i), format.mintick), text_color = textColor, bgcolor = color.black, text_size = sz)

If you are new to the language, the TradingView Pine Script masterclass covers variables, functions and plotting before you get to tables.

Common Mistakes with Pine Script Tables

  • Creating the table on every bar without var. Without var, a new table object is created on each bar. Always declare it with var table.
  • Calling ta.* functions inside the barstate.islast block. Indicator functions such as ta.sma() need to run on every bar to have correct history. Calculate them globally and only write the results inside the block.
  • Two tables at the same position. A new table at an occupied position replaces the old one. Give each table its own position.
  • Cell index out of range. Columns and rows are zero based. A 4 x 6 table has columns 0 to 3 and rows 0 to 5; writing to column 4 throws a runtime error.
  • Expecting tables to update intrabar in a strategy. In strategies, tables update on realtime ticks only when calc_on_every_tick = true is set.

Wrapping Up

This Pine Script uses tables to present a comprehensive view of various trading indicators, making it easier for traders to analyze data directly on the chart. By customizing table size, position, and whether it appears, users can adapt the script to their preferences and trading style. This script exemplifies how Pine Script can be used to enhance data visualization in TradingView charts.

A good next step is to combine a table with a signal indicator, for example showing the current trend, stop and entry of the Supertrend indicator in Pine Script in a corner dashboard.

Frequently Asked Questions

How do I create a table in Pine Script?

Declare it once with var table t = table.new(position.top_right, columns, rows), then fill cells with table.cell(t, column, row, text). Put the table.cell() calls inside if barstate.islast so the table is updated only where it is visible.

How do I change the text size of a Pine Script table cell?

Pass the text_size argument to table.cell() using constants such as size.tiny, size.small, size.normal, size.large or size.huge. To change it later without rewriting the cell, use table.cell_set_text_size().

How do I merge cells in a Pine Script table?

Use table.merge_cells(table_id, start_column, start_row, end_column, end_row). The merged cell takes the properties of the first cell in the range, which is handy for a heading row across the top of a dashboard.

How many tables can one Pine Script indicator show?

Up to nine at a time, one for each fixed position on the chart pane. Creating a second table at a position that is already used replaces the first one.

Why is my Pine Script table not showing?

The usual reasons are: no cell has been filled yet (empty tables are not drawn), the table was created at a position already used by another table, or the code that fills it never runs because of a condition such as a disabled input.

Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More