MID Regime Filter
- インディケータ
- バージョン: 1.0
- アクティベーション: 5
MID Regime Filter – Adaptive Market Regime Filter
📌 Overview
🛡️ Vital Protection for Grid and Martingale Strategies
- 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
- Normalization: ATR and Standard Deviation (StdDev) are normalized against the current price, making the indicator effective across all asset classes (Forex, Indices, Crypto, Stocks).
- 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.
- Smart Fusion: It combines these ranks to determine the dominant regime without false signals caused by nominal price changes.
📊 The 4 Market Regimes
- 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
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.
