【问题标题】:Pine-script for loop inside function函数内部循环的松树脚本
【发布时间】:2022-01-26 21:49:30
【问题描述】:

我正在尝试创建一个循环来遍历最后几根柱线,并找出当 hma 向上倾斜时的平均增益是多少。但是我遇到了一个我不明白的错误。函数内部不能有循环吗?

我的代码:

// 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

【问题讨论】:

    标签: function for-loop pine-script


    【解决方案1】:

    pinescript 中没有++ 运算符。将其更改为gainCount := gainCount + 1

    你可以从here看到pinescript中的操作符列表。

    【讨论】:

      【解决方案2】:

      问题在于双 + 号....而不是 for 循环

      增益计数 ++

      不幸的是,Pine-script 的错误信息并不总是足够清晰

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-28
        • 1970-01-01
        • 1970-01-01
        • 2020-12-12
        • 1970-01-01
        相关资源
        最近更新 更多