Pine Script运行报错bullFib/bearFib不是函数的问题咨询
Pine Script 运行报错修复方案
报错原因
你编写的蜡烛形态判断语句中,两个并列生效的判断条件之间遗漏了逻辑与运算符and。Pine Script语法中,当变量名后直接跟随括号结构时,编译器会将该内容识别为函数调用语法,因此会抛出「bullFib不是函数」「bearFib不是函数」的报错。
原博主的代码可以正常运行,大概率是你手动抄写代码时漏写了两个条件中间的and符号。
修复代码
只需要修改hammerCandle和starCandle对应的两行代码,补充and运算符即可,修改后的完整代码如下:
//@version=4 study(title="Hammers and Shooting Stars", shorttitle="Pin Bars") plot(close) // Get user input fibLevel = input(title="Fib Level", type=input.float, defval=0.333) colorFilter = input(title="Color Must Match", type=input.bool, defval=false) // Calculate fibonacci level for current candle bullFib = (low - high) * fibLevel + high bearFib = (high - low) * fibLevel + low // Determine which price source closes or opens highest/lowest lowestBody = close < open ? close : open highestBody = close > open ? close : open // Determine if we have a valid hammer or shooting star hammerCandle = lowestBody >= bullFib and (not colorFilter or close > open) starCandle = highestBody <= bearFib and (not colorFilter or close < open)
注意事项
后续编写多条件判断逻辑时,多个需要同时满足的条件之间必须用and连接,多个满足任意一个即可的条件之间用or连接,避免出现类似语法报错。
内容的提问来源于stack exchange,提问作者Durahankara
相关产品推荐
相关产品推荐

