I am trying to convert an old script to V5 and get the error below.
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. ta:highest(2)? _isDown[1] and _isUp and _direction[1].= 1: ta.lowest(2) : na
Undeclared identifier '_direction'
Variable '_direction' is not found in scope 'zigzag', cannot register side effect
What is the problem here? Do you have any recommendations?
Self referencing is not allowed from v3
and above.
You should first define the variable and then use it.
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 ? ta.highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? ta.lowest(2) : na
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.