PROTECTED SOURCE SCRIPT
Zigzag Market Type Oscillator

Zigzag Market Type Oscillator
This indicator is a powerful tool for analyzing market conditions by categorizing price action into one of four states: Up-Trending, Down-Trending, Consolidating, or Ranging. It uses a Zigzag pattern to identify swings and then calculates the average size of upward and downward price movements to determine the prevailing market type.
How It Works:
Swing Detection: The script first uses a Zigzag algorithm (based on the Zigzag Depth input) to find significant highs and lows in the market. These swings are considered the "legs" of price movement.
Average Leg Size: It keeps track of the percentage change of the most recent upward and downward legs. The Number of Legs for Average setting controls how many past legs are used to calculate the average size of up-moves and down-moves.
Disparity Calculation: The core of the indicator is the Disparity value, which measures the difference between the average size of up-legs and down-legs.
- A positive disparity means up-legs are, on average, larger than down-legs.
- A negative disparity means down-legs are, on average, larger than up-legs.
- A disparity near zero means up-legs and down-legs are roughly the same size.
Market Type Classification: The indicator then uses the Disparity and Average Size values to color-code the oscillator, providing a clear visual signal of the market type:
Green (Up-Trending): The disparity is positive and above your Disparity Threshold. This suggests a strong upward trend where buyers are consistently making larger moves than sellers.
Red (Down-Trending): The disparity is negative and below your -Disparity Threshold. This suggests a strong downward trend where sellers are consistently making larger moves than buyers.
Blue (Ranging): The disparity is close to zero (within your Disparity Threshold), and the overall Average Size of the swings is small (below your Size Threshold). This indicates a tight, choppy, and indecisive market with no clear direction.
Silver (Consolidating or drifting in direction of most recent trend): The disparity is close to zero, but the overall Average Size of the swings is large. This suggests a sideways market with wide swings, also known as a trading range.
How to Use It:
Trend Confirmation: Use the Green and Red signals to confirm the direction and strength of a trend. A sustained green plot suggests a good environment for long positions, while a sustained red plot favors short positions.
Identify Non-Trending Conditions: Use the Blue and Silver plots to identify when the market is not trending. During these periods, trend-following strategies may not be effective. You might look for breakout opportunities (from a blue plot) or use a range-bound trading strategy (within a silver plot).
Risk Management: The oscillator can serve as a warning sign. For example, if you are in an uptrending market (green plot) but the oscillator suddenly turns silver or blue, it may signal that the trend is losing momentum and that you should consider reducing your position or tightening your stop-loss.
Settings:
Zigzag Depth: This controls the sensitivity of the Zigzag, which in turn defines the "legs." A higher value will ignore smaller price fluctuations, focusing on larger swings. A lower value will capture more detail.
Number of Legs for Average: This determines the lookback period for the average size calculation. A higher number will create a smoother, more stable oscillator but will react more slowly to changes in market behavior.
Disparity Threshold: This is the key setting that determines the line between a trending market and a non-trending one. Adjust this to a level that you believe represents a significant difference between up and down moves.
Size Threshold (%): This separates Ranging (small swings) from Consolidating (large swings). Adjust this to define what you consider a "small" vs. a "large" price swing for the asset you are trading.
This indicator is a powerful tool for analyzing market conditions by categorizing price action into one of four states: Up-Trending, Down-Trending, Consolidating, or Ranging. It uses a Zigzag pattern to identify swings and then calculates the average size of upward and downward price movements to determine the prevailing market type.
How It Works:
Swing Detection: The script first uses a Zigzag algorithm (based on the Zigzag Depth input) to find significant highs and lows in the market. These swings are considered the "legs" of price movement.
Average Leg Size: It keeps track of the percentage change of the most recent upward and downward legs. The Number of Legs for Average setting controls how many past legs are used to calculate the average size of up-moves and down-moves.
Disparity Calculation: The core of the indicator is the Disparity value, which measures the difference between the average size of up-legs and down-legs.
- A positive disparity means up-legs are, on average, larger than down-legs.
- A negative disparity means down-legs are, on average, larger than up-legs.
- A disparity near zero means up-legs and down-legs are roughly the same size.
Market Type Classification: The indicator then uses the Disparity and Average Size values to color-code the oscillator, providing a clear visual signal of the market type:
Green (Up-Trending): The disparity is positive and above your Disparity Threshold. This suggests a strong upward trend where buyers are consistently making larger moves than sellers.
Red (Down-Trending): The disparity is negative and below your -Disparity Threshold. This suggests a strong downward trend where sellers are consistently making larger moves than buyers.
Blue (Ranging): The disparity is close to zero (within your Disparity Threshold), and the overall Average Size of the swings is small (below your Size Threshold). This indicates a tight, choppy, and indecisive market with no clear direction.
Silver (Consolidating or drifting in direction of most recent trend): The disparity is close to zero, but the overall Average Size of the swings is large. This suggests a sideways market with wide swings, also known as a trading range.
How to Use It:
Trend Confirmation: Use the Green and Red signals to confirm the direction and strength of a trend. A sustained green plot suggests a good environment for long positions, while a sustained red plot favors short positions.
Identify Non-Trending Conditions: Use the Blue and Silver plots to identify when the market is not trending. During these periods, trend-following strategies may not be effective. You might look for breakout opportunities (from a blue plot) or use a range-bound trading strategy (within a silver plot).
Risk Management: The oscillator can serve as a warning sign. For example, if you are in an uptrending market (green plot) but the oscillator suddenly turns silver or blue, it may signal that the trend is losing momentum and that you should consider reducing your position or tightening your stop-loss.
Settings:
Zigzag Depth: This controls the sensitivity of the Zigzag, which in turn defines the "legs." A higher value will ignore smaller price fluctuations, focusing on larger swings. A lower value will capture more detail.
Number of Legs for Average: This determines the lookback period for the average size calculation. A higher number will create a smoother, more stable oscillator but will react more slowly to changes in market behavior.
Disparity Threshold: This is the key setting that determines the line between a trending market and a non-trending one. Adjust this to a level that you believe represents a significant difference between up and down moves.
Size Threshold (%): This separates Ranging (small swings) from Consolidating (large swings). Adjust this to define what you consider a "small" vs. a "large" price swing for the asset you are trading.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.