将松树脚本版本2更改为4时出现错误
第17行:未声明的标识符“ _direction”;
第18行:在范围“ anonym_function_0”中找不到变量“ _direction”,无法进行注册
代码在下面
//@version=4
study(title='ZigZag PA Strategy V4 ALERT')
useHA = input(false, title='Use Heikken Ashi Candles')
useAltTF = input(true, title='Use Alt Timeframe')
tf = input('30', title='Alt Timeframe')
showPatterns = input(true, title='Show Patterns')
showFib0000 = input(title='Display Fibonacci 0.000:',defval=true)
showFib0236 = input(title='Display Fibonacci 0.236:',defval=true)
showFib0382 = input(title='Display Fibonacci 0.382:',defval=true)
showFib0500 = input(title='Display Fibonacci 0.500:', defval=true)
showFib0618 = input(title='Display Fibonacci 0.618:', defval=true)
showFib0764 = input(title='Display Fibonacci 0.764:', defval=true)
showFib1000 = input(title='Display Fibonacci 1.000:', defval=true)
zigzag() =>
_isUp = close >= open
_isDown = close <= open
_direction = _isUp[1] and _isDown ? -1 : _isDown[1] and _isUp ? 1 : nz(_direction[1])
_zigzag = _isUp[1] and _isDown and _direction[1] != -1 ? highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? lowest(2) : na
_ticker = useHA ? heikinashi(syminfo.tickerid) : syminfo.tickerid
sz = useAltTF ? (change(time(tf)) != 0 ? security(_ticker, tf, zigzag()) : na) : zigzag()
我该如何解决?
请帮助我。
答案 0 :(得分:0)
在v4中,变量需要先声明,然后再在赋值的右侧引用它们。在使用之前,请仔细比较v2的结果:
zigzag() =>
_isUp = close >= open
_isDown = close <= open
_direction = 0
_direction := _isUp[1] and _isDown ? -1 : _isDown[1] and _isUp ? 1 : nz(_direction[1])
_zigzag = _isUp[1] and _isDown and _direction[1] != -1 ? highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? lowest(2) : na