簡體   English   中英

條件的PineScript公式?

[英]PineScript formulation of condition?

假設我有 3 個條件,如果滿足其中 2 個條件,我想執行一些操作。 有幾個組合,比如 3,解決方案可能是這樣的:

c1=...
c2=...
c3=...

if (c1==true and c2==true) then
elseif (c1==true and c3==true) then
elseif (c2==true and c3==true) then

這不是很實用,例如,100 個條件,其中 90 個應該被滿足。 在 PineScript 中是否有更緊湊的方法來實現這一點?

如果您將您的條件的 boolean true/false表示為1/0整數,您可以計算它們以查看有多少是真的。

我能想到的最短方法是將它們放入一個數組中,然后計算該數組的總和。

//@version=5
indicator("My Script")

var int c0 = 1
var int c1 = 0
var int c2 = 1
var int c3 = 1
var int c4 = 1
var int c5 = 0
var int c6 = 0
var int c7 = 1
var int c8 = 1
var int c9 = 1

var int[] a = array.from(c0,c1,c2,c3,c4,c5,c6,c7,c8,c9)

mySum = array.sum(a)

plot(mySum)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM