RicardoSantos

[RS]ZigZag PA

ZigZag Based on price oscilation.
  • Use Alt Timeframe: enables optional timeframes, use higher timeframes to reduce noise.
  • Timeframe: said Alt Timeframe.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study("[RS]ZigZag PA", overlay=true)
useAltTF = input(true, title='Use Alt Timeframe')
tf = input('15', title='Alt Timeframe')

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

sz = useAltTF ? (change(time(tf)) != 0 ? security(tickerid, tf, zigzag()) : na) : zigzag()

plot(sz, title='zigzag', color=black, linewidth=2)