FAQ – How to plot a table in PineScript?

Just recently TradingView added a possibility to plot nice tables on your chart from Pine Script. It’s a really nice way to present information for your indicators and strategies. In this article, I will show you a very simple example of how you can plot a table from PineScript.

To create a table you can use the following command:

var tbl = table.new(position.top_right, 2, 3)

This code will create a table on your chart in the top right corner of your screen, with 2 columns and 3 rows. Besides that, in parameters, you can set some styling for the table like borders, frames, and background color.

If you’ll execute only these commands you won’t see anything on your screen. You have to fill your table first. You can do that with table.cell function, foe example:

table.cell(tbl, 0, 0, "Some Text")

This will fill cell in table “tbl” with row = 0 and column = 0 with “Some Text” value. In addition to that, you can adjust the weight and height of every column, background color, change color size and color.

Here is an example of the code that will fill the entire table:

if (barstate.islast)
    table.cell(tbl, 0, 0, "Open",  bgcolor = #aaaaaa, width = 7, height = 4)
    table.cell(tbl, 1, 0, "Close", bgcolor = #aaaaaa, width = 7, height = 4)
    
    table.cell(tbl, 0, 1, tostring(open),  bgcolor = color.green, width = 7, height = 4)
    table.cell(tbl, 1, 1, tostring(close), bgcolor = color.red,   width = 7, height = 4)
    
    table.cell(tbl, 0, 2, tostring(open[1]),  bgcolor = color.green, width = 7, height = 4)
    table.cell(tbl, 1, 2, tostring(close[1]), bgcolor = color.red,   width = 7, height = 4)

With this code, I filled 2×3 tables with Header, current and previous values of open and close. My table will look like that:

As you can see it’s a pretty simple way to plot tables. You can create pretty complicated tables with this approach and use loops to fill them for example.


Follow me on TradingView and YouTube.