Zig-Zag Donchian indicator

Zig-Zag Donchian indicator

1. Introduction

The Zig-Zag Donchian indicator is a technical analysis tool that combines the logic of the Zig-Zag with Donchian channels to identify turning points in the price direction of an asset. This indicator is especially useful for traders looking to detect emerging trends, local highs and lows, as well as potential buy and sell signals.

The Zig-Zag Donchian is based on the concept of identifying the most significant price movements, filtering out market noise, and highlighting meaningful changes. Unlike the traditional Zig-Zag indicator, which focuses solely on price pivots, the Zig-Zag Donchian uses Donchian channels to establish upper and lower boundaries that help validate trend changes. This allows traders to gain a clearer view of market dynamics and make informed decisions based on the interaction of price with these bands.

This indicator adapts well to different financial assets, and its customization options allow it to be adjusted to the specific characteristics of the market in which it is being used, whether it’s a stock market, forex, commodities, or cryptocurrencies.

2. How the Zig-Zag Donchian Works

The Zig-Zag Donchian works by combining the calculation of Zig-Zag pivots with Donchian channels, which are constructed using the highest and lowest price values over a specified period. This combination allows the indicator to identify turning points in the price direction, providing a clearer view of the current trend and potential reversal points.

The indicator uses a set of customizable parameters that allow it to be tailored to different assets and market conditions:

  • Length: This parameter determines the number of bars used to calculate the upper and lower levels of the Donchian channels. A higher value will smooth the bands and generate fewer signals, while a lower value will make the indicator more sensitive to price changes.
  • Bounce Speed (bsp): The bounce speed is a factor that affects how quickly the Zig-Zag adjusts to changes in price. A higher value makes the Zig-Zag more responsive to directional changes in price.
  • Transparency (transp): This parameter allows you to adjust the transparency of the Donchian channel fill on the chart, improving the visualization of the channel in combination with other chart elements.
  • Gradient (gradient): This parameter activates the gradient color function for the Donchian channel, providing a visual representation that shows the position of the price within the range.
  • Show Signals (showsignals): This parameter enables or disables the visualization of buy and sell signals based on the Zig-Zag pivots.

In its functionality, the indicator identifies price crossings with the Donchian channels and, based on these crossings, generates signals indicating potential trend changes. The Zig-Zag pivots adjust according to changes in price direction, allowing the trader to observe how the price interacts with the upper and lower levels of the Donchian channel.

This process provides an effective visual tool for identifying dynamic support and resistance zones, as well as anticipating potential reversals in market trends.

3. Calculation of Donchian Channels

The Zig-Zag Donchian uses Donchian channels to identify the highest and lowest price levels within a defined period. These channels are constructed by taking the highest and lowest values of the price (by default, the closing price) over a specified number of bars. This helps establish the upper and lower boundaries within which the price will move.

In the code, the Donchian channels are calculated using the following commands:

  • upper: Defines the upper limit of the Donchian channel and is calculated by identifying the highest price reached during the period specified by the length parameter.
  • lower: Defines the lower limit of the Donchian channel and is obtained by finding the lowest price during the same period.

The length parameter determines the number of bars that will be used for this calculation. By default, a value of 20 is used, meaning that the indicator will consider the most recent 20 periods to determine the upper and lower levels.

These bands serve as dynamic references to identify the price range’s amplitude over a specific period. Using Donchian channels in combination with the Zig-Zag provides traders with information about zones where the price might find resistance (upper level) or support (lower level), helping to anticipate potential trend reversal points.

4. Calculation of the Zig-Zag

The Zig-Zag component of the indicator is responsible for identifying turning points in the price direction within the Donchian channels. The goal is to eliminate market noise and highlight only the most relevant movements, facilitating the identification of local highs and lows.

The calculation of the Zig-Zag is based on the following steps:

  1. Detection of crossings with Donchian channels: The Zig-Zag checks whether the price has crossed the upper or lower Donchian channels. The conditions are:

    Here, zz represents the current value of the Zig-Zag, and zz[1] is its value in the previous bar. If a crossing with the upper or lower band is detected, a signal indicating a change in direction is generated.

  2. Determination of the oscillator (osc): The osc oscillator indicates the direction of the price movement and is defined as:

    • When a crossing with the upper band (crossupper) occurs, the oscillator takes a value of -1, indicating a potential shift to a bearish trend.
    • When a crossing with the lower band (crosslower) occurs, the oscillator is set to 1, signaling a possible shift to a bullish trend.
  3. Zig-Zag update: If a change in the oscillator direction is detected, the difference between the upper and lower bands (val) is calculated to adjust the Zig-Zag value:

    Finally, the Zig-Zag value is updated using the formula:


    The final result is a Zig-Zag indicator that follows price movements within the limits set by the Donchian channels, providing a clear visual approach to identifying directional changes and market trends.

5. Visualization of the Donchian Channel

The Zig-Zag Donchian indicator not only uses Donchian channels to detect price reversal points but also displays them visually on the chart, providing a clear representation of the price range. To enhance the interpretation of price movements, the Donchian channel is filled with a color gradient indicating the price’s position within the range.

Gradient Color Calculation

The indicator calculates the current position of the price within the Donchian channels using the following formula:

  • source: Represents the normalization of the price position (src) within the channels. It takes a value between 0 and 1, where 0 indicates the price is at the lower band and 1 indicates it’s at the upper band.
  • norm: Calculates an average of source over the length period to smooth variations.

This normalized value is used to determine the color of the Donchian channel, applying different shades based on the price’s position within the range.

When norm is low, the channel is shown in red tones, indicating that the price is close to the lower level. As norm increases, the color gradually changes from orange to yellow, green, and finally to bright green when the price nears the upper level.

This gradient helps visualize price movement within the channel, providing additional information about the current trend’s strength.

Filling the Donchian Channel

The indicator uses the colorbetween() function to fill the channel between the upper and lower levels with the calculated colors, applying the transparency defined by the transp parameter:

6. Buy and Sell Signals

The Zig-Zag Donchian generates buy and sell signals based on the pivots detected by the Zig-Zag component. These signals help traders identify entry and exit points in the market, making it a comprehensive tool for technical analysis.

  • Sell Signal (Red Arrow): Generated when a local high is detected, i.e., when the current value (zz) is lower than the previous value (zz[1]) and the value two periods ago (zz[2]). This indicates a possible downward reversal, and a red arrow is drawn on the chart.
  • Buy Signal (Green Arrow): Produced when a local low is detected, meaning the current value (zz) is higher than the previous (zz[1]) and the one two periods ago (zz[2]). This indicates a potential upward reversal, and a green arrow is displayed on the chart.

7. Customizable Parameters

The Zig-Zag Donchian is a flexible indicator that allows you to adjust several parameters to adapt it to different financial assets and market conditions.

  • length: The number of bars used to calculate the Donchian channels.
  • bsp: Bounce speed multiplier affecting how quickly the Zig-Zag responds.
  • transp: Transparency level for the Donchian channel fill.
  • gradient: Controls the gradient colors for the channel.
  • showsignals: Enables or disables buy and sell signals.

8. Zig-Zag Donchian Indicator Code

9. Conclusion

The Zig-Zag Donchian is a versatile and powerful tool that combines Zig-Zag pivots with Donchian channels to offer a clear visual representation of trends and turning points. With its customizable parameters, this indicator can be tailored to suit various trading strategies, making it an invaluable resource for traders aiming to enhance their accuracy in identifying trading opportunities.

Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. roccafragius • 167 days ago #

    Hello Ivan, another great Indicator, very useful to trace the trend ( blue line) and the possible Breakout ( price over/under the blue line)!! Thank you!

avatar
Register or

Likes

avatar avatar avatar avatar avatar
Related users ' posts
rama I want to use this indicator in trading system, it says zig zag is obsolete and not supported
Nicolas Right, due to its repainting behavior, the zigzag is not allowed in automated trading with r...
rama I noticed it changes as time progress, I am 7 as the average, how many period it wont chang...
ak5hay2 Works like crazy on bitcoin. Use different timeframes. Thanks a lot Doc!!!
richyowen Hi, great code thanks. Very new to this forum. Is there a way to add a 100point target on an...
lisamitch50 Morning all, Just backtested on quite a few instruments, worked well on backtesting, but tel...
bazilou pouvez expliquer donchian bias merci
rb-72 Thank you, area of twist by dilatacion of the price, missing part of the code that is not pu...
Thomas007 after reading your blog now I understand why there is only a part of your code here. I'm try...
Juanjo Hola¡¡ la estrategia se podria aplicar sobre acciones con marco temporal diario?? gracias.
Marcel If you are interested in my way of trading, please follow me on Twitter @MvvTrading
Genotik Excellent, merci !
diegofe_2000 Excelente indicador, felicitaciones, muy bueno
TempusFugit Masala, thanks for your contribution. I don´t like the offmarket spreads neither ;) I unders...
Uveus Tempus, me da un error al validar el codigo, sobre la variable N. Al crear el indicador me ...
TempusFugit Hi Uveus, I am guessing you inserted the code of the indicator into the system code, is ...
JR1976 Dear Mike , your screener seem interest and simple... Do you try to envelope an automat...
Player Hi Mike, What is the name of the indicator just under the MMA ? Thanks Regards Marc
Igor Hi Mike, What is the name of the indicator just under the MMA ? Thanks Regards
wtangsiri Bonjour J'ai importé le fichier ITF en question, mais cela me donne, en bas de l'écran, un...
Nicolas Il faut ajouter l'indicateur sur le graphique du prix.
skuggan89 This is a great indicator, works very well!! Is there any algo based on this indicator that ...
Nicolas
9 years ago
Nicolas add it on price chart, change the cp parameter according to the period you want to observe f...
Robert22 hola buenos días: yo estoy buscando una cosa parecida para realizar con ello un indicador de...
Nicolas https://www.prorealcode.com/prorealtime-indicators/rsi-classical-hidden-divergences-indicator/

Top