繁体   English   中英

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

[英]How to use default values for array parameters in pine-script functions?

松脚本;

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

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

例如:

// @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)) => ...

您不能提供默认值作为数组。 并且数组参数不能省略。

将来会有办法在 function 签名中分配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())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM