Pine Script 计数序列

Pine Script count sequenze on for

我需要一个 for 循环内的计数器来确定我是在 1st 2nd 还是 3rd (i) 可以这么说 一种奇数和偶数,但在这种情况下我也有第三个数字 所以我应该检查数字序列 1-4-7 或 2-5-8 或 3-6-9 .... 等等 .... 然后设置我的变量。谢谢

count=0 
MyVariable=0
for h = 0 to 10
    if count = 0
        count:=1
        MyVariable := 5
    else if count = 1
        count:=2
        MyVariable := 10            
    else if (count = 3)
        count:=0
        MyVariable := 18    

我已经尝试这样做,但是一旦我从 array.push 中删除 rems,我就会收到以下错误消息“Return type of one of the 'if' blocks is not兼容 return 类型的其他块(void;series[integer];series[integer])”

array.sort(PDelta)
plot(array.size(PDelta))    
_valore=""
Count=1
Ptest=array.new_string()
//Scorro i Delta
for j = 0 to (i_size)-1
    _value = array.get(PDelta,j)
    //Scorro tutti
    for h = 0 to (i_size)-1
        //controllo Delta
        if (Count==1)
            Count:=2
            //array.push(Ptest,"Test")
        else if (Count == 2)
            Count:=3
            //array.push(Ptest,"Test")
        else if (Count == 3)
            Count:=1
            //array.push(Ptest,"Test")   

 

您的 if 语句中必须有另一个分支返回另一种类型的值。 Pine中的if语句可以用来给变量赋值,如:

v = if ...

因此,编译器会强制执行 if 块中返回值的类型。您可以使用以下解决方法:

if (Count==1)
    Count:=2
    array.push(Ptest,"Test")
    int(na)
else if (Count == 2)
    Count:=3
    array.push(Ptest,"Test")
    int(na)
else if (Count == 3)
    Count:=1
    array.push(Ptest,"Test")
    int(na)
else
    Count:=4
    int(na)