簡體   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