【问题标题】:Check if the past candles are the same type in PineScript检查过去的蜡烛是否在 PineScript 中是相同的类型
【发布时间】:2021-05-23 09:34:59
【问题描述】:

我正在尝试检查过去的 n 蜡烛是否属于同一类型。

例如,之前的五支蜡烛都是看涨的,还是都看跌的。

使用我的方法,我不断收到错误:

lines 30:37: Return type of one of the 'if' blocks is not compatible with return type of other block(s) (void; series[bool]; series[bool])

我在迭代中出了什么问题?

提前谢谢大家。

我也愿意尝试任何其他工作方法/想法。

// Determine if we have a valid setup
isBullish = true
isBearish = true

for i = (iterationCount - 1) to 0
    notSeries = not(isBullish or isBearish)

    if notSeries
        break
    else if close[i] > open[i] and isBullish
        isBearish := false
    else 
        isBullish := false

【问题讨论】:

    标签: pine-script candlestick-chart


    【解决方案1】:

    不知道为什么会抛出该错误,因为即使您将isBearish := false 放在break 之前,错误仍然存​​在,即使if 语句中的每个路径都返回bool

    我会这样写,因为您不需要break 来评估您的isBullishisBearish。您只需要 break 即可停止您的 for 循环。

    for i = (iterationCount - 1) to 0
        notSeries = not(isBullish or isBearish)
    
        if notSeries
            break
    
        if close[i] > open[i] and isBullish
            isBearish := false
        else 
            isBullish := false
    

    【讨论】:

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