简体   繁体   English

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

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

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.函数不接受 function 结果作为默认值。

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

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.将来会有办法在 function 签名中分配int[] b = na After that you will be able to check if passed array is 'na', and then reassign it.之后,您将能够检查传递的数组是否为“na”,然后重新分配它。

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())

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

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