假設我有 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 中是否有更緊湊的方法來實作這一點?
uj5u.com熱心網友回復:
如果您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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408137.html
標籤:
