我是 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”结构,方法调用显然会被忽略或覆盖。
我一定是错过了什么。
正如 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
bool
类型用于保存布尔值,如语法参考或本文= operator
:=
运算符