OPEN-SOURCE SCRIPT
Zigzag Simple [SCL]

🟩 OVERVIEW
Draws zigzag lines from pivot Highs to pivot Lows. You can choose between three different ways of calculating pivots:
• True Highs and Lows
• Williams pivots
• Oscillator pivots
🟩 HOW TO USE
This indicator can be used to understand market structure, which is arguably the primary thing you need to be aware of when trading. The zigzag by itself does not display a market structure bias, nor any information about prices of pivots, HH and HL labels, or anything like that. Nevertheless, a simple zigzag is perhaps the easiest and most intuitive way to understand what price is doing.
Choose a pivot style that you like, customise the colours and line style, and enjoy!
🟩 PIVOT TYPES EXPLAINED
True Highs and Lows
This is not an invention of mine (all credit to my humble mentor), but I haven't seen anyone else code them up. A true High is a close below the low of the candle with the highest high. A true Low is a close above the high of a candle with the lowest low. These are solid, price action-based pivots that can sometimes confirm quickly.
Williams pivots
This is how most people calculate pivots. They're simply the highest high for x bars back and x bars forwards. They're the vanilla of pivots IMO: serviceable but not very interesting. They're very convenient to code because there are built-in Pine functions for them: ta.pivothigh and ta.pivotlow. They confirm a predictable number of bars after they happen, which is great for coding but also makes the trader wait for confirmation.
Oscillator pivots
This is a completely different concept, which uses momentum in order to define pivots. For example, when you get a rise in momentum and momentum then drops a configurable amount, it confirms a pivot high, and vice versa for a pivot low. I don't know if anyone else does it –- although some indicators do mark pivots in momentum itself, and plenty do divergences, I wasn't able to find one that specifically marked *pivots in price* because of pivots in momentum 🤷♂️
Anyway, while this approach needs a whole investigation on its own, here we simply plot some pivots in a smoothed RSI. This indicator doesn't plot the actual momentum values -- for a more visual understanding of how this works, refer to the examples in the OscillatorPivots library.
🟩 UNIQUE ADVANTAGES
In contrast to other zigzag indicators available, this one lets you choose between the standard and some more unique methods of generating the zigzags. Additionally, because it's based on libraries, it is relatively easy for programmers to use as a basis for experimentation.
🟩 GEEK STUFF
Although there is considerable practical use for pivot-based zigzags in trading, this script is primarily a demonstration in coding -- specifically the power of libraries!
Most of the script consists of setup, especially defining inputs. The final section sacrifices some readability for conciseness, simply to emphasise how little code you need when the heavy lifting is done by libraries.
The actual calculations and drawing are achieved in just 8 lines.
The equivalent code in the libraries is ~250 lines long.
All libraries used are my own, public and open-source:
• MarketStructure
• DrawZigZag
• OscillatorPivots
Draws zigzag lines from pivot Highs to pivot Lows. You can choose between three different ways of calculating pivots:
• True Highs and Lows
• Williams pivots
• Oscillator pivots
🟩 HOW TO USE
This indicator can be used to understand market structure, which is arguably the primary thing you need to be aware of when trading. The zigzag by itself does not display a market structure bias, nor any information about prices of pivots, HH and HL labels, or anything like that. Nevertheless, a simple zigzag is perhaps the easiest and most intuitive way to understand what price is doing.
Choose a pivot style that you like, customise the colours and line style, and enjoy!
🟩 PIVOT TYPES EXPLAINED
True Highs and Lows
This is not an invention of mine (all credit to my humble mentor), but I haven't seen anyone else code them up. A true High is a close below the low of the candle with the highest high. A true Low is a close above the high of a candle with the lowest low. These are solid, price action-based pivots that can sometimes confirm quickly.
Williams pivots
This is how most people calculate pivots. They're simply the highest high for x bars back and x bars forwards. They're the vanilla of pivots IMO: serviceable but not very interesting. They're very convenient to code because there are built-in Pine functions for them: ta.pivothigh and ta.pivotlow. They confirm a predictable number of bars after they happen, which is great for coding but also makes the trader wait for confirmation.
Oscillator pivots
This is a completely different concept, which uses momentum in order to define pivots. For example, when you get a rise in momentum and momentum then drops a configurable amount, it confirms a pivot high, and vice versa for a pivot low. I don't know if anyone else does it –- although some indicators do mark pivots in momentum itself, and plenty do divergences, I wasn't able to find one that specifically marked *pivots in price* because of pivots in momentum 🤷♂️
Anyway, while this approach needs a whole investigation on its own, here we simply plot some pivots in a smoothed RSI. This indicator doesn't plot the actual momentum values -- for a more visual understanding of how this works, refer to the examples in the OscillatorPivots library.
🟩 UNIQUE ADVANTAGES
In contrast to other zigzag indicators available, this one lets you choose between the standard and some more unique methods of generating the zigzags. Additionally, because it's based on libraries, it is relatively easy for programmers to use as a basis for experimentation.
🟩 GEEK STUFF
Although there is considerable practical use for pivot-based zigzags in trading, this script is primarily a demonstration in coding -- specifically the power of libraries!
Most of the script consists of setup, especially defining inputs. The final section sacrifices some readability for conciseness, simply to emphasise how little code you need when the heavy lifting is done by libraries.
The actual calculations and drawing are achieved in just 8 lines.
The equivalent code in the libraries is ~250 lines long.
All libraries used are my own, public and open-source:
• MarketStructure
• DrawZigZag
• OscillatorPivots
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
🆓 All my free scripts: simplecrypto.life/free-scripts/
💰 Trade with me: simplecrypto.life/trade-with-me/
🙋 Free help with Pinescript: simplecrypto.life/get-help-with-pinescript/
💰 Trade with me: simplecrypto.life/trade-with-me/
🙋 Free help with Pinescript: simplecrypto.life/get-help-with-pinescript/
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
🆓 All my free scripts: simplecrypto.life/free-scripts/
💰 Trade with me: simplecrypto.life/trade-with-me/
🙋 Free help with Pinescript: simplecrypto.life/get-help-with-pinescript/
💰 Trade with me: simplecrypto.life/trade-with-me/
🙋 Free help with Pinescript: simplecrypto.life/get-help-with-pinescript/
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.