Pine Script支持在表格内调用用户函数吗?

huangapple go评论55阅读模式
英文:

Does Pine Script support calling a user function inside a table?

问题

I have a table in Pine Script with several rows, and each row requires around 20+ lines of code. I made a user function to create the rows but I'm having trouble getting it to work.
在Pine Script中,我有一个包含多行的表格,每行需要大约20行以上的代码。我创建了一个用户函数来创建这些行,但是我遇到了问题。

Simple question - does Pine Script support calling a user function inside a table, ie to build the table rows?
简单的问题 - Pine Script是否支持在表格内调用用户函数,即用于构建表格行?

Couldn't find an answer in the documentation.
在文档中找不到答案。

Thanks.
谢谢。

Update: Found the bug in my row-building user function, so I have answered my own question - yes, Pine Script does support calling a user function to create the rows of a table.
更新:我在创建行的用户函数中找到了错误,所以我自己回答了我的问题 - 是的,Pine Script支持调用用户函数来创建表格的行。

英文:

I have a table in Pine Script with several rows, and each row requires around 20+ lines of code. I made a user function to create the rows but I'm having trouble getting it to work.
Simple question - does Pine Script support calling a user function inside a table, ie to build the table rows?
Couldn't find an answer in the documentation
Thanks.

Update: Found the bug in my row-building user function, so I have answered my own question - yes, Pine Script does support calling a user function to create the rows of a table.

答案1

得分: 0

是的,这个代码片段创建了一个简单的表格,其中使用一个函数来创建表格单元格,然后在该函数内部调用另一个函数来将收盘价格乘以2。

//@version=5
indicator("我的表格", overlay = true)

// 创建表格
var myTable = table.new(position.top_right, 2, 2, bgcolor = color.aqua, frame_color = color.black, frame_width = 2, border_color = color.black, border_width = 2)

createCell(_table, _column, _row, _text) =>
    table.cell(_table, _column, _row, _text, text_color = color.white)

multiplier(_close) => _close * 2

createCell(myTable, 0, 0, '标志')
createCell(myTable, 0, 1, str.tostring(syminfo.tickerid))
createCell(myTable, 1, 0, '收盘价格 * 2')
createCell(myTable, 1, 1, str.tostring(multiplier(close), format.mintick))

这段代码创建了一个表格,显示了交易标的的标志(Symbol)和收盘价格乘以2的结果(Closing Price * 2)。结果如下图所示:

Pine Script支持在表格内调用用户函数吗?

英文:

Yes it does. Here is a very simple script that uses a function to create the table cells and then also calls another function inside of that function to multiply the closing price by 2.

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

//create the table
var myTable = table.new(position.top_right, 2, 2, bgcolor = color.aqua, frame_color = color.black, frame_width = 2, border_color = color.black, border_width = 2)

createCell(_table, _column, _row, _text) =>
    table.cell(_table, _column, _row, _text, text_color = color.white)

multiplier(_close) => _close * 2 

createCell(myTable, 0, 0, 'Symbol')
createCell(myTable, 0, 1, str.tostring(syminfo.tickerid))
createCell(myTable, 1, 0, 'Closing Price * 2')
createCell(myTable, 1, 1, str.tostring(multiplier(close), format.mintick))

Picture of the result
Pine Script支持在表格内调用用户函数吗?

huangapple
  • 本文由 发表于 2023年5月22日 07:59:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76302373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定