Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study("Ziggidy-Zaggedy", overlay = true)
- zig1 = "Zig-Zag #1"
- zig2 = "Zig-Zag #2"
- zig3 = "Zig-Zag #3"
- zig0 = input(zig1, "Zig-Zag Type", options = [zig1, zig2, zig3])
- len0 = input(1, "Length")
- zigzag(_len) =>
- _isUp = close >= open
- _isDown = close <= open
- _direction = 0.0
- _direction := _isUp[_len] and _isDown ? -1 : _isDown[_len] and _isUp ? 1 : nz(_direction[_len])
- _zigzag = _isUp[_len] and _isDown and _direction[_len] != -1 ? highest(2) : _isDown[_len] and _isUp and _direction[_len] != 1 ? lowest(2) : na
- zzigzag(_len) =>
- _isUp = close >= open
- _isDown = close <= open
- _direction = 0.0
- _direction := _isUp[_len] and _isDown ? -_len : _isDown[_len] and _isUp ? _len : nz(_direction[_len])
- _zigzag = _isUp[_len] and _isDown and _direction[_len] != -_len ? highest(2) : _isDown[_len] and _isUp and _direction[_len] != _len ? lowest(2) : na
- zzzigzag(_len) =>
- _isUp = close >= open
- _isDown = close <= open
- _direction = 0.0
- _direction := _isUp[_len] and _isDown ? -_len : _isDown[_len] and _isUp ? _len : nz(_direction[_len])
- _zigzag = _isUp[_len] and _isDown and _direction[_len] != -_len ? highest(_len * 2) : _isDown[_len] and _isUp and _direction[_len] != _len ? lowest(_len * 2) : na
- plot(zig0 == zig1 ? zigzag(len0) : na, "Zig-Zag #1", blue)
- plot(zig0 == zig2 ? zzigzag(len0) : na, "Zig-Zag #2", red)
- plot(zig0 == zig3 ? zzzigzag(len0) : na, "Zig-Zag #3", green)
Advertisement
Add Comment
Please, Sign In to add comment