[GYTS-CE] Market Regime Detector

๐ธ Part of GoemonYae Trading System (GYTS) ๐ธ
๐ธ --------- INTRODUCTION --------- ๐ธ
๐ฎ What is the Market Regime Detector?
The Market Regime Detector is an advanced, consensus-based indicator that identifies the current market state to increase the probability of profitable trades. By distinguishing between trending (bullish or bearish) and cyclic (range-bound) market conditions, this detector helps you select appropriate tactics for different environments. Instead of forcing a single strategy across all market conditions, our detector allows you to adapt your approach based on real-time market behaviour.
๐ฎ The Importance of Market Regimes
Markets constantly shift between different behavioural states or "regimes":
โข Bullish trending markets - characterised by sustained upward price movement
โข Bearish trending markets - characterised by sustained downward price movement
โข Cyclic markets - characterised by range-bound, oscillating behaviour
Each regime requires fundamentally different trading approaches. Trend-following strategies excel in trending markets but fail in cyclic ones, while mean-reversion strategies shine in cyclic markets but underperform in trending conditions. Detecting these regimes is essential for successful trading, which is why we've developed the Market Regime Detector to accurately identify market states using complementary detection methods.
๐ธ --------- KEY FEATURES --------- ๐ธ
๐ฎ Consensus-Based Detection
Rather than relying on a single method, our detector employs two complementary detection methodologies that analyse different aspects of market behaviour:
โข Dominant Cycle Average (DCA) - analyzes price movement relative to its lookback period, a proxy for the dominant cycle
โข Volatility Channel - examines price behaviour within adaptive volatility bands
These diverse perspectives are synthesised into a robust consensus that minimises false signals while maintaining responsiveness to genuine regime changes.
๐ฎ Dominant Cycle Framework
The Market Regime Detector uses the concept of dominant cycles to establish a reference framework. You can input the dominant cycle period that best represents the natural rhythm of your market, providing a stable foundation for regime detection across different timeframes.
๐ฎ Intuitive Parameter System
We've distilled complex technical parameters into intuitive controls that traders can easily understand:
โข Adaptability - how quickly the detector responds to changing market conditions
โข Sensitivity - how readily the detector identifies transitions between regimes
โข Consensus requirement - how much agreement is needed among detection methods
This approach makes the detector accessible to traders of all experience levels while preserving the power of the underlying algorithms.
๐ฎ Visual Market Feedback
The detector provides clear visual feedback about the current market regime through:
โข Colour-coded chart backgrounds (purple shades for bullish, pink for bearish, yellow for cyclic)
โข Colour-coded price bars
โข Strength indicators showing the degree of consensus
โข Customizable colour schemes to match your preferences or trading system
๐ฎ Integration in the GYTS suite
The Market Regime Detector is compatible with the GYTS Suite, i.e. it passes the regime into the ๐ผ Order Orchestrator where you can set how to trade the trending and cyclic regime.
๐ธ --------- CONFIGURATION SETTINGS --------- ๐ธ
๐ฎ Adaptability
Controls how quickly the Market Regime detector adapts to changing market conditions. You can see it as a low-frequency, long-term change parameter:
- Very Low: Very slow adaptation, most stable but may miss regime changes
- Low: Slower adaptation, more stability but less responsiveness
- Normal: Balanced between stability and responsiveness
- High: Faster adaptation, more responsive but less stable
- Very High: Very fast adaptation, highly responsive but may generate false signals
This setting affects lookback periods and filter parameters across all detection methods.
๐ฎ Sensitivity
Controls how sensitive the detector is to market regime transitions. This acts as a high-frequency, short-term change parameter:
- Very Low: Requires substantial evidence to identify a regime change
- Low: Less sensitive, reduces false signals but may miss some transitions
- Normal: Balanced sensitivity suitable for most markets
- High: More sensitive, detects subtle regime changes but may have more noise
- Very High: Very sensitive, detects minor fluctuations but may produce frequent changes
This setting affects thresholds for regime detection across all methods.
๐ฎ Dominant Cycle Period
This parameter allows you to specify the market's natural rhythm in bars. This represents a complete market cycle (up and down movement). Finding the right value for your specific market and timeframe might require some experimentation, but it's a crucial parameter that helps the detector accurately identify regime changes. Most of the times the cycle is between 20 and 40 bars.
๐ฎ Consensus Mode
Determines how the signals from both detection methods are combined to produce the final market regime:
โข Any Method (OR): Signals bullish/bearish if either method detects that regime. If methods conflict (one bullish, one bearish), the stronger signal wins. More sensitive, catches more regime changes but may produce more false signals.
โข All Methods (AND): Signals only when both methods agree on the regime. More conservative, reduces false signals but might miss some legitimate regime changes.
โข Weighted Decision: Balances both methods with equal weighting. Provides a middle ground between sensitivity and stability.
Each mode also calculates a continuous regime strength value that's used for colour intensity in the 'unconstrained' display mode.
๐ฎ Display Mode
Choose how to display the market regime colours:
โข Unconstrained regime: Shows the regime strength as a continuous gradient. This provides more nuanced visualisation where the intensity of the colour indicates the strength of the trend.
โข Consensus only: Shows only the final consensus regime with fixed colours based on the detected regime type.
The background and bar colours will change to indicate the current market regime:
โข Purple shades: Bullish trending market (darker purple indicates stronger bullish trend)
โข Pink shades: Bearish trending market (darker pink indicates stronger bearish trend)
โข Yellow: Cyclic (range-bound) market
๐ฎ Custom Colour Options
The Market Regime Detector allows you to customize the colour scheme to match your personal preferences or to coordinate with other indicators:
โข Use custom colours: Toggle to enable your own colour choices instead of the default scheme
โข Transparency: Adjust the transparency level of all regime colours
โข Bullish colours: Define custom colours for strong, medium, weak, and very weak bullish trends
โข Bearish colours: Define custom colours for strong, medium, weak, and very weak bearish trends
โข Cyclic colour: Define a custom colour for cyclic (range-bound) market conditions
๐ธ --------- DETECTION METHODS --------- ๐ธ
๐ฎ Dominant Cycle Average (DCA)
The Dominant Cycle Average method forms a key part of our detection system:
1. Theoretical Foundation:
The DCA method builds on cycle analysis and the observation that in trending markets, price consistently remains on one side of a moving average calculated using the dominant cycle period. In contrast, during cyclic markets, price oscillates around this average.
2. Calculation Process:
โข We calculate a Simple Moving Average (SMA) using the specified lookback period - a proxy for the dominant cycle period
โข We then analyse the proportion of time that price spends above or below this SMA over a lookback window. The theory is that the price should cross the SMA each half cycle, assuming that the dominant cycle period is correct and price follows a sinusoid.
โข This lookback window is adaptive, scaling with the dominant cycle period (controlled by the Adaptability setting)
โข The different values are standardised and normalised to possess more resolving power and to be more robust to noise.
3. Regime Classification:
โข When the normalised proportion exceeds a positive threshold (determined by Sensitivity setting), the market is classified as bullish trending
โข When it falls below a negative threshold, the market is classified as bearish trending
โข When the proportion remains between these thresholds, the market is classified as cyclic
๐ฎ Volatility Channel
The Volatility Channel method complements the DCA method by focusing on price movement relative to adaptive volatility bands:
1. Theoretical Foundation:
This method is based on the observation that trending markets tend to sustain movement outside of normal volatility ranges, while cyclic markets tend to remain contained within these ranges. By creating adaptive bands that adjust to current market volatility, we can detect when price behaviour indicates a trending or cyclic regime.
2. Calculation Process:
โข We first calculate a smooth base channel center using a low pass filter, creating a noise-reduced centreline for price
โข True Range (TR) is used to measure market volatility, which is then smoothed and scaled by the deviation factor (controlled by Sensitivity)
โข Upper and lower bands are created by adding and subtracting this scaled volatility from the centreline
โข Price is smoothed using an adaptive A2RMA filter, which has a very flat and stable behaviour, to reduce noise while preserving trend characteristics
โข The position of this smoothed price relative to the bands is continuously monitored
3. Regime Classification:
โข When smoothed price moves above the upper band, the market is classified as bullish trending
โข When smoothed price moves below the lower band, the market is classified as bearish trending
โข When price remains between the bands, the market is classified as cyclic
โข The magnitude of price's excursion beyond the bands is used to determine trend strength
4. Adaptive Behaviour:
โข The smoothing periods and deviation calculations automatically adjust based on the Adaptability setting
โข The measured volatility is calculated over a period proportional to the dominant cycle, ensuring the detector works across different timeframes
โข Both the center line and the bands adapt dynamically to changing market conditions, making the detector responsive yet stable
This method provides a unique perspective that complements the DCA approach, with the consensus mechanism synthesising insights from both methods.
๐ธ --------- USAGE GUIDE --------- ๐ธ
๐ฎ Starting with Default Settings
The default settings (Normal for Adaptability and Sensitivity, Weighted Decision for Consensus Mode) provide a balanced starting point suitable for most markets and timeframes. Begin by observing how these settings identify regimes in your preferred instruments.
๐ฎ Finding the Optimal Dominant Cycle
The dominant cycle period is a critical parameter. Here are some approaches to finding an appropriate value:
โข Start with typical values, usually something around 25 works well
โข Visually identify the average distance between significant peaks and troughs
โข Experiment with different values and observe which provides the most stable regime identification
โข Consider using cycle-finding indicators to help identify the natural rhythm of your market
๐ฎ Adjusting Parameters
โข If you notice too many regime changes โ Decrease Sensitivity or increase Consensus requirement
โข If regime changes seem delayed โ Increase Adaptability
โข If a trending regime is not detected, the market is automatically assigned to be in a cyclic state
โข If you want to see more nuanced regime transitions โ Try the "unconstrained" display mode (note that this will not affect the output to other indicators)
๐ฎ Trading Applications
Regime-Specific Strategies:
โข Bullish Trending Regime - Use trend-following strategies, trail stops wider, focus on breakouts, consider holding positions longer, and emphasize buying dips
โข Bearish Trending Regime - Consider shorts, tighter stops, focus on breakdown points, sell rallies, implement downside protection, and reduce position sizes
โข Cyclic Regime - Apply mean-reversion strategies, trade range boundaries, apply oscillators, target definable support/resistance levels, and use profit-taking at extremes
Strategy Switching:
Create a set of rules for each market regime and switch between them based on the detector's signal. This approach can significantly improve performance compared to applying a single strategy across all market conditions.
GYTS Suite Integration:
โข In the GYTS ๐ผ Order Orchestrator, select the '๐ STREAM-int ๐ง Market Regime' as the market regime source
โข Note that the consensus output (i.e. not the "unconstrained" display) will be used in this stream
โข Create different strategies for trending (bullish/bearish) and cyclic regimes. The GYTS ๐ผ Order Orchestrator is specifically made for this.
โข The output stream is actually very simple, and can possibly be used in indicators and strategies as well. It outputs 1 for bullish, -1 for bearish and 0 for cyclic regime.
๐ธ --------- FINAL NOTES --------- ๐ธ
๐ฎ Development Philosophy
The Market Regime Detector has been developed with several key principles in mind:
1. Robustness - The detection methods have been rigorously tested across diverse markets and timeframes to ensure reliable performance.
2. Adaptability - The detector automatically adjusts to changing market conditions, requiring minimal manual intervention.
3. Complementarity - Each detection method provides a unique perspective, with the collective consensus being more reliable than any individual method.
4. Intuitiveness - Complex technical parameters have been abstracted into easily understood controls.
๐ฎ Ongoing Refinement
The Market Regime Detector is under continuous development. We regularly:
โข Fine-tune parameters based on expanded market data
โข Research and integrate new detection methodologies
โข Optimise computational efficiency for real-time analysis
Your feedback and suggestions are very important in this ongoing refinement process!
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda โ ketahui lebih lanjut di sini.
๐ Website (launching soon): goemonyae.com
๐ฌ Discord server (including YaeBot): discord.gg/ef6Tu4kha3
๐ personal LinkedIn: linkedin.com/in/arthur-nazarian
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda โ ketahui lebih lanjut di sini.
๐ Website (launching soon): goemonyae.com
๐ฌ Discord server (including YaeBot): discord.gg/ef6Tu4kha3
๐ personal LinkedIn: linkedin.com/in/arthur-nazarian