【问题标题】:Pine script loop on bar index条形索引上的 Pine 脚本循环
【发布时间】:2021-01-30 20:57:34
【问题描述】:

我想检查过去n 酒吧的条件。

因此,如果我想针对特定数字执行此操作,我将使用类似这样的方法,用于最后 5 个小节:

cond = close > open
conditions = cond and cond[1] and cond[2] and cond[3] and cond[4] and cond[5]

但我需要在函数内部使用此方法(用于自定义条形索引号返回)

我的意思是这样的:

check(condition,length)=>
    for i = 1 to length
        condition[bar_index] and condition[bar_index+i]

所以我可以像这样使用它: check(close>open,5) 我希望答案是对还是错。

我尝试了更多循环,但我无法获得所需的循环。 请告诉我如何在带有for 循环的函数中使用它。

【问题讨论】:

    标签: pine-script


    【解决方案1】:
    //@version=4
    study("Help (check)")
    
    check(_condition,_length) =>
        _check = true
        for i = 0 to _length
            _check := _check and _condition[i]
    
    
    cond = close > open
    conditions = cond and cond[1] and cond[2] and cond[3] and cond[4] and cond[5]
    
    //bgcolor(conditions ? color.black : na)
    bgcolor(check(cond,5) ? color.blue : na)
    

    【讨论】:

    • 谢谢兄弟,还有一个问题,如果我想使用or 而不是and 我应该怎么做? (我将 and 改为 or 但效果不佳)
    • 简单地将and替换为or是无法替换的。有必要了解一般必须满足的条件。
    • 你说得对,再次感谢,你能告诉我如果我想从 condition = cond[5] and cond[6] + ...... 这样的偏移量开始循环(不是从 [0] 开始)我应该如何改变我的循环? tnx.
    • for i = _offset to _length+_offset
    【解决方案2】:

    没有记录,内联示例:

    close[ta.barssince(time < timestamp("2021-11-07T14:30:00"))]
    

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2023-03-27
      • 2016-08-17
      • 2022-01-12
      • 2022-01-15
      • 2023-03-13
      相关资源
      最近更新 更多