New TradingView Feature: Pine Script Tables

To display any textual information on the chart I used labels. And it doesn’t look very good. Here is an example of the code with label:

//@version=4
study("Pine Tables", overlay = true)

rsi = rsi(close, 14)
cci = cci(close, 14)
[diplus, diminus, adx] = dmi(17, 14)

label_text = "RSI: " + tostring(round(rsi, 2)) + "\n" + 
             "CCI: " + tostring(round(cci, 2)) + "\n" + 
             "DMI: " + tostring(round(adx, 2))`
   
if (barstate.islast)          
    label.new(bar_index, high, text = label_text)

So in this code I just compute 3 indicators and display their values for the last labels. This solution isn’t very nice. It’s pretty tricky to style your label when you have quite a lot of information and still it won’t look very good:

Just few days ago TradingView anounced new Pine Script feature: Tables. Using tables it will be much easier displaying information on your chart. It’s an object and it works similar to other objects in Pine Script. You have to define it with table.new function and after that you can use table.cell functions to fill all the cells in your table.

Here is a very sinple example of how you can present the same data but in a table format:

//@version=4
study("Pine Tables", overlay = true)

rsi = rsi(close, 14)
cci = cci(close, 14)
[diplus, diminus, adx] = dmi(17, 14)

var table t = table.new(position.top_right, 2, 3, border_width = 1)

if (barstate.islast)          
    
    table.cell(t, 0, 0, "RSI", width = 5, bgcolor = #aaaaaa)
    table.cell(t, 0, 1, "CCI", width = 5, bgcolor = #aaaaaa)
    table.cell(t, 0, 2, "DMI", width = 5, bgcolor = #aaaaaa)
    
    table.cell(t, 1, 0, tostring(round(rsi, 2)), width = 5, bgcolor = rsi > 40 ? color.red : color.green)
    table.cell(t, 1, 1, tostring(round(cci, 2)), width = 5, bgcolor = color.green)
    table.cell(t, 1, 2, tostring(round(adx, 2)), width = 5, bgcolor = color.green)

As a result a table will be created and you’ll see in in the top right corner of your screen:

1 thought on “New TradingView Feature: Pine Script Tables”

Leave a Reply

Your email address will not be published. Required fields are marked *