合并和注释:Pine表格现在支持标题和工具提示

Mar 18, 2022

标题和单元格合并

现在可以合并表格中的多个单元格以创建精美的标题和分隔符。合并的单元格不一定是标题:您可以在任何方向合并单元格,只要生成的单元格不影响任何已合并的单元格,并且不会超出表格的范围。

要创建合并单元格,请使用新的 table.merge_cells() 函数。规则很简单。您需要传递要合并的第一个和最后一个单元格的坐标。它们之间的所有内容都将合并到一个单元格中。合并单元格的大小由其相邻行和列的尺寸自动确定。

在下面的示例脚本中,您可以看到三个合并的单元格:第一个合并第零行中的所有单元格并包含“SMA 表格”,下面的其他单元格创建子标题。

//@version=5
indicator("MA Ratings", overlay = true)

TRANSP = 80
TABLE_WIDTH = 6
var CELL_TOOLTIP = "Cell color depends on the SMA direction: green for rising SMAs, red for falling ones"

var smaLengths = array.from(10, 20, 50, 100, 200, 500)

smaValues = array.new_float()
for i = 0 to array.size(smaLengths) - 1
    array.push(smaValues, ta.sma(close, array.get(smaLengths, i)))

var maTable = table.new(position.top_right, TABLE_WIDTH, 4, border_width = 2)

if barstate.isfirst
    headerColor = color.new(color.blue, TRANSP)
    table.cell(maTable, 0, 0, text = "SMA Table", bgcolor = headerColor)
    table.cell(maTable, 0, 1, text = "Short-term", bgcolor = headerColor)
    table.cell(maTable, 2, 1, text = "Long-term", bgcolor = headerColor)
    table.merge_cells(maTable, 0, 0, 5, 0)
    table.merge_cells(maTable, 0, 1, 1, 1)
    table.merge_cells(maTable, 2, 1, 5, 1)

if barstate.islast
    for i = 0 to TABLE_WIDTH - 1
        cellTitle = str.format("SMA {0}", array.get(smaLengths, i))
        cellValue = array.get(smaValues, i)
        cellColor = color.new(array.get(smaValues, i) >= array.get(smaValues[1], i) ? color.green : color.red, TRANSP)
        table.cell(maTable, i, 2, bgcolor = cellColor, text = cellTitle, text_color = color.gray, tooltip = CELL_TOOLTIP)
        table.cell(maTable, i, 3, bgcolor = cellColor, text = str.tostring(cellValue,  format.mintick), tooltip = CELL_TOOLTIP)

工具提示

对表格的第二个改进是工具提示。工具提示是当您将鼠标悬停在表格的单元格上时出现的浮动文本标签。它们可以方便地提供有关单元格内容的信息,而不会让表格拥挤。

要创建带有工具提示的单元格,只需将字符串传递给 table.cell() 函数的新 tooltip 参数。 在我们的示例脚本中查看实际的工具提示,我们在最后两行的 table.cell() 调用中使用 tooltip = CELL_TOOLTIP。工具提示将如下所示:

要随时了解Pine的新功能,请留意我们的Pine用户手册的发行说明PineCoders帐户还从Telegram上的Squawk BoxTwitter帐户和TradingView上的Pine脚本公开聊天中广播更新。

我们希望大家发现这个高需求的功能很有用。请继续向我们发送您的反馈和改进建议。我们为您打造TradingView,总是渴望收到您的信息。


 

还没有关注我们的中文微信公众号?快来扫二维码吧!

Look first Then leap

TradingView专门为您而打造,请确保您充分利用我们出色的功能