MID Regime Filter

MID Regime Filter – Adaptive Market Regime Filter

(protection, adaptive filtering, and the 4 market regimes)

📌 Overview

The MID Regime Filter is not a classic entry signal indicator. It is a powerful, adaptive market context filter designed specifically for algorithmic traders and Expert Advisor (EA) developers.
It analyzes real-time market volatility and directionality to classify the current environment into one of 4 distinct market regimes. This allows your EA to dynamically enable, disable, or adjust its strategies based on actual market conditions.

🛡️ Vital Protection for Grid and Martingale Strategies

Grid and Martingale strategies excel in ranging markets, but they are extremely vulnerable to strong unidirectional trends and explosive volatility spikes. Opening new grid orders or doubling down during a market crash or pump can lead to catastrophic drawdowns or a blown account.
The MID Regime Filter acts as a smart circuit breaker for your EA:
  • It instantly detects shifts into TREND (2) or EXPLOSIVE (3) regimes.
  • Your EA can be programmed to immediately block any new grid or martingale entries as long as volatility remains high.
  • It allows the EA to "survive" market storms by only managing existing positions, waiting for the market to calmly return to a RANGE (1) or DEAD (0) regime before safely resuming entries.

⚙️ How It Works

Unlike indicators with fixed thresholds, the MID Regime Filter uses an adaptive statistical approach:
  1. Normalization: ATR and Standard Deviation (StdDev) are normalized against the current price, making the indicator effective across all asset classes (Forex, Indices, Crypto, Stocks).
  2. Percentile Ranks: It calculates the current position of these values over a rolling window (InpRankLookback ). A rank of 80 means current volatility is higher than 80% of recent periods.
  3. Smart Fusion: It combines these ranks to determine the dominant regime without false signals caused by nominal price changes.

📊 The 4 Market Regimes

The indicator displays a colored histogram in a separate window:
  • 0 = DEAD (Gray): Very low volatility and directionality. Sleeping market.
  • 1 = RANGE (Blue): Low to medium volatility, no clear direction. Ideal zone for Grid/Martingale entries.
  • 2 = TREND (Green): Moderate to high directionality (ADX) and volatility. Danger zone for Martingale: blocking new entries is highly recommended.
  • 3 = EXPLOSIVE (OrangeRed): Extreme volatility and directionality. Maximum alert: total freeze of new positions advised.

💻 Integration into a Grid/Martingale EA

The indicator is optimized to be read via iCustom . The market regime is stored in Buffer 2.

Example MQL5 code to protect your EA:

//--- Handle declaration
int regimeHandle = iCustom(_Symbol, _Period, "MID_Regime_Filter", 14, 20, 10, 150, 30.0, 50.0, 70.0);

//--- Inside OnTick(), BEFORE any grid/martingale opening logic
double currentRegime[];
if(CopyBuffer(regimeHandle, 2, 0, 1, currentRegime) > 0)
  {
   int regime = (int)currentRegime[0];
   
   // 🛡️ SAFETY CIRCUIT BREAKER
   if(regime == 2 || regime == 3) 
     {
      // TREND or EXPLOSIVE Market: DO NOT open new orders
      // Only allow logic for managing/closing existing positions to run
      return; 
     }
     
   // If regime == 0 or 1, normal Grid/Martingale logic can execute safely
   // ... (your order opening code here) ...
  }

✅ Key Features

  • Account Saver: Prevents fatal drawdowns in mean-reversion strategies during news events or market crashes.
  • Multi-Asset Ready: Thanks to price normalization, the same parameters protect your EA on EURUSD, NAS100, or BTCUSD seamlessly.
  • Lightweight & Optimized: Efficient calculations, proper handle management, designed not to slow down your backtests or live trading.
Filtro:
Sem comentários
Responder ao comentário