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
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
🆓 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/
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
🆓 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/
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。