简体   繁体   English

function 内循环的 Pine 脚本

[英]Pine-script for loop inside function

I'm trying to create a loop to go over the last bars and figure out what the average gain is when the hma is sloping up.我正在尝试在最后一个条形图上创建一个到 go 的循环,并找出当 hma 向上倾斜时的平均增益是多少。 But I'm getting an error I don't understand.但是我遇到了一个我不明白的错误。 Is it not possible to have a loop inside a function? function 内不可能有一个循环吗?

My code:我的代码:

// Get Average Gains on long streaks
getAverageGain(hmaValue) =>
    gainStart = 0.00
    gainAmount = 0.00
    gainCount = 0
    gaining = hmaValue[1] < hmaValue
    for i=0 to 2000
        if gaining[i] and not gaining[i+1]
            gainStart := hmaValue[i]
        if gaining[i+1] and not gaining[i] and gainStart != 0.00
            gainAmount += ((hmaValue[i+1] - gainStart) / gainStart) * 100
            gainCount ++
    gainAmount/gainCount

Problem was with the double + sign....not the for loop问题出在双 + 号....而不是 for 循环

gainCount ++增益计数++

Unfortunately Pine-script's error messages aren't always clear enough不幸的是,Pine-script 的错误信息并不总是足够清晰

There is no ++ operator in pinescript. pinescript 中没有++运算符。 Change it to gainCount:= gainCount + 1 .将其更改为gainCount:= gainCount + 1

You can see the list of operators in pinescript from here .您可以从此处查看pinescript 中的运算符列表。

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

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