简体   繁体   中英

Issues on calling highest() on a zigzag plot

I'm on my very first steps on pine and I'm getting a compilation alert of inconsistency by using the function Highest() within my strategy:

line 20: The function 'highest' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope.

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

Can you guys give me an insight on how to properly write this?

//@version=4
study("test", "test", true)

zigzag() =>
    _hi = highest(2)
    _lo = lowest(2)
    _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 ? _hi : _isDown[1] and _isUp and _direction[1] != 1 ? _lo : na

plot(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM