PROTECTED SOURCE SCRIPT

Full Regime Engine – Trend / Mean Revert / No-Trade

57
🚀 Full Regime Engine Strategy: Trend / Mean Revert / No-Trade
This comprehensive strategy, named the Full Regime Engine, is designed to adapt its trading logic based on prevailing market conditions, classifying the market into three distinct regimes: Trend, Mean Reversion (MR), and No-Trade. It uses a combination of Average True Range (ATR) volatility ratio and the Average Directional Index (ADX) to determine the current regime, ensuring the appropriate entry and exit logic is applied.

⚙️ How the Regime Engine Works
The strategy uses two core indicators to define the market regime:

Volatility Ratio (ATR / SMA of ATR):

High Volatility Ratio (above highVolThr) suggests an active, potentially trending market.

Low Volatility Ratio (below lowVolThr) suggests a calmer, mean-reverting environment.

Average Directional Index (ADX):

High ADX (above adxTrendMin) confirms the strength of a potential trend.

Low ADX (below adxChopMax) confirms a weak, non-directional, or choppy market suitable for mean reversion.

The regimes are defined as follows:

🟢 Trend Regime: High Volatility Ratio AND High ADX.

🔵 Mean Reversion (MR) Regime: Low Volatility Ratio AND Low ADX.

⚫ No-Trade Regime: Any other condition, including outside of the defined session/time filters.

🎯 Entry and Exit Logic by Regime
The strategy employs a different entry and exit approach for each active regime:

1. Trend Regime (Pullback Entries)
Definition: The trend is established using a cross of Fast and Slow EMAs (emaFastLen and emaSlowLen).

Entry Signal: A pullback entry, where the price momentarily touches the Fast EMA and then closes back in the direction of the trend.

Long: low <= Fast EMA and close > Fast EMA (during a bullish trend).

Short: high >= Fast EMA and close < Fast EMA (during a bearish trend).

Risk Management: Uses a wider Stop Loss (slTrend) and Take Profit (tpTrend) based on ATR multiples, reflecting the expectation of larger moves in a trending market.

2. Mean Reversion Regime (VWAP Deviation Fades)
Definition: Trades the fade of extreme price movements back towards the Volume-Weighted Average Price (VWAP).

Entry Signal: Price is significantly deviated from VWAP (measured in ATR multiples mrDevATR) and shows a reversal candle.

Long (Fade Short): Price is far below VWAP (devZ < -mrDevATR) and the current candle is bullish (close > open).

Short (Fade Long): Price is far above VWAP (devZ > mrDevATR) and the current candle is bearish (close < open).

Risk Management: Uses a tighter Stop Loss (slMR) and Take Profit (tpMR) based on ATR multiples, suitable for capturing smaller moves near the mean.

⏱️ Time-Based Filters
The strategy includes robust time filters to only trade during periods with higher liquidity and predictable activity:

RTH Session Filter: Trades only within the defined "Regular Trading Hours" session (sessionStr).

Midday Filter: Optionally avoids the typically slow and choppy midday trading hours (11:00–13:00).

📊 Visuals & Customization
Background Colors: The chart background automatically colors to display the current regime: Green for Trend, Blue for Mean Revert, and Gray for No-Trade.

Plot Shapes: Distinct shapes and labels mark the raw entry signals for both Trend (Triangles) and Mean Reversion (Circles).

ATR Exits: Plots the dynamically calculated Stop Loss (Red) and Take Profit (Green) lines based on the trade's entry mode (Trend or MR).

💡 Note: This is a comprehensive engine that requires careful optimization of the input parameters for your specific instrument and timeframe. Start with the default settings and adjust the regime thresholds (ATR Ratio and ADX) and the risk/reward multiples (SL/TP) to suit your trading style.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.