否则如果结构在 pinescript V5 中不起作用

问题描述 投票:0回答:1

我是 PineScript 新手,我对“else-if”结构有一个非常奇怪的问题。

此代码返回 true,即使 arePreviousBarsInUpTrend(index) 为 false。

isShootingStar(index) =>
    result = if (math.min(close[index], open[index]) <= low[index+1] and isCandleGreen(index))
        false
    else if (not arePreviousBarsInUpTrend(index))
        false
    else
        isLowerWickInsignificant(index) and isLongUpperWick(index)

    // Return the final result
    result

我单独尝试了 arePreviousBarsInUpTrend(index) ,效果很好。

一旦我引入“else-if”结构,方法调用显然会被忽略或覆盖。

我一定是错过了什么。

pine-script-v5
1个回答
0
投票

正如 this answer on a different Pine Script V5 Question 所指出的那样,您不能在变量声明中使用

if
语句。

正确的语法是

isShootingStar(index) =>
    bool result = na;
    if (math.min(close[index], open[index]) <= low[index+1] and isCandleGreen(index))
        result := false
    else if (not arePreviousBarsInUpTrend(index))
        result := false
    else
        result := isLowerWickInsignificant(index) and isLongUpperWick(index)

    // Return the final result
    result
© www.soinside.com 2019 - 2024. All rights reserved.