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.
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:
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.
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 = highest[length](src)
lower = lowest[length](src)
length parameter.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.
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:
crossupper = zz[1] crosses over upper or zz[1] crosses under upper
crosslower = zz[1] crosses over lower or zz[1] crosses under lower
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.
osc): The osc oscillator indicates the direction of the price movement and is defined as:
if crossupper then
osc = -1
elsif crosslower then
osc = 1
else
osc = osc
endif
crossupper) occurs, the oscillator takes a value of -1, indicating a potential shift to a bearish trend.crosslower) occurs, the oscillator is set to 1, signaling a possible shift to a bullish trend.val) is calculated to adjust the Zig-Zag value:
if osc <> osc[1] then
val = upper - lower
endif
Finally, the Zig-Zag value is updated using the formula:
if barindex > 2 * length then
zz = zz[1] + osc * val * bsp / length
endif
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.
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.
The indicator calculates the current position of the price within the Donchian channels using the following formula:
source = max(min((src - lower) / (upper - lower), 1), 0)
norm = average[length](source)
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.
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:
colorbetween(upper, lower, r, g, b, transp)
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.
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.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.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.
//-----------------------------------------------------------------//
//PRC_Donchian Zigzag
//version = 0
//13.08.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//-----------------------------------------------------------------//
//-----Inputs------------------------------------------------------//
//-----------------------------------------------------------------//
src=close
length=20
bsp=1 //Bounce speed
transp=120
gradient=1
showsignals=1
//-----------------------------------------------------------------//
//-----Donchian Upper and Lower------------------------------------//
//-----------------------------------------------------------------//
upper=highest[length](src)
lower=lowest[length](src)
//-----------------------------------------------------------------//
//-----Zig-Zag-----------------------------------------------------//
//-----------------------------------------------------------------//
once zz=src
crossupper=zz[1] crosses over upper or zz[1] crosses under upper
crosslower=zz[1] crosses over lower or zz[1] crosses under lower
if crossupper then
osc=-1
elsif crosslower then
osc=1
else
osc=osc
endif
if osc<>osc[1] then
val=upper-lower
endif
if barindex > 2*length then
zz = zz[1]+osc*val*bsp/length
endif
//-----------------------------------------------------------------//
//-----Fill Donchian channel---------------------------------------//
//-----------------------------------------------------------------//
source=max(min((src-lower)/(upper-lower),1),0)
norm=average[length](source)
if gradient then
if norm < 0.2 then
r=255
g=0
b=0
elsif norm>=0.20 and norm<0.40 then
r=255
g=168
b=0
elsif norm>=0.40 and norm<0.60 then
r=214
g=188
b=26
elsif norm>=0.60 and norm<0.80 then
r=172
g=204
b=52
elsif norm>=0.80 then
r=48
g=255
b=83
endif
else
r=120
g=120
b=120
endif
colorbetween(upper,lower,r,g,b,transp)
//-----------------------------------------------------------------//
//-----Signals-----------------------------------------------------//
//-----------------------------------------------------------------//
if showsignals then
if zz<zz[1] and zz[1]>zz[2] then
drawarrowdown(barindex[1],zz[1]+tr) coloured("red")
elsif zz>zz[1] and zz[1]<zz[2] then
drawarrowup(barindex[1],zz[1]-tr) coloured("green")
endif
endif
//-----------------------------------------------------------------//
return upper as "Lmax" , lower as "Lmin", zz as "ZigZag" coloured("blue")style(line,2)
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.