【问题标题】:How can we find the bar_index of the lowest and RED bar within last 5 bars我们如何找到最近 5 根柱中最低和红色柱的 bar_index
【发布时间】:2023-01-10 06:34:53
【问题描述】:

我想找到最近 5 个柱内最低红色(收盘 < 开盘)柱的 bar_index,不包括当前柱。

我使用了以下代码,但在某些情况下似乎无法正常工作:

Check(no) =>
    minValue = lowest(5)[1]
    int find = na
    for i = 1 to no
    if (low[i] <= minValue) and (close[i] < open[i])
        find := i
    find

请帮我。

【问题讨论】:

    标签: pine-script pine-script-v5 pine-script-v4


    【解决方案1】:

    你应该使用(Pinescript v5):

    Check(no) =>
        Lowest_red_value = ta.highest(no) // Init to high value
        Bar_index_Lowest_red_bar = 0
        // Search for Red bar
        for i = 1 to no
            if close[i] < open[i]
                if close[i] < Lowest_red_value
                    Lowest_red_value := close[i]
                    Bar_index_Lowest_red_bar := bar_index - i
        Bar_index_Lowest_red_bar
    

    请注意,如果您之前的“否”栏中没有红色栏,则此函数将返回 0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 2023-02-17
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      相关资源
      最近更新 更多