如何在 pine-script 函数中使用数组参数的默认值?

发布于 2025-01-18 21:35:21 字数 371 浏览 1 评论 0原文

松木;

  • 库不能在导出功能中使用全局变量,因此我不能将全局数组用作默认值。
  • 功能不接受函数结果为默认值。

有没有办法提供默认数组值?

例如:

// @version=5

library("mylibrary", overlay = true)

// This is OK
export calc(int a = 10, int[] b) => ...

// This is NOT OK
export calc(int a = 10, int[] b = array.from(1,2)) => ...

Pine-script;

  • Libraries cannot use global variables in exported functions, so I cannot use a global array as a default value.
  • Functions do not accept function results as default values.

Is there a way to provide default array value?

For example:

// @version=5

library("mylibrary", overlay = true)

// This is OK
export calc(int a = 10, int[] b) => ...

// This is NOT OK
export calc(int a = 10, int[] b = array.from(1,2)) => ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云雾 2025-01-25 21:35:21

您不能以数组形式提供默认值。并且数组参数不能省略。

将来将会有办法在函数签名中赋值int[] b = na。之后,您将能够检查传递的数组是否为“na”,然后重新分配它。

可以做这样的事情:

// @version=5
library("mylibrary", overlay = true)

export calc(int[] b = na)  => 
    arr = na(b) ? array.from(1,2) : b
    array.size(b)
    
plot(calc())

You cannot provide default value as an array. And array argument cannot be omitted.

In the future there will be way to assign int[] b = na in the function signature. After that you will be able to check if passed array is 'na', and then reassign it.

It will be possible to do something like this:

// @version=5
library("mylibrary", overlay = true)

export calc(int[] b = na)  => 
    arr = na(b) ? array.from(1,2) : b
    array.size(b)
    
plot(calc())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文