market-regime
Market regime detection and filtering for MQL5 EAs. Use for all logic that determines WHETHER to trade: trend vs range classification via ADX; volatility regime via ATR (high/normal/reduced); session filtering (London/NY/Asian killzones); news event avoidance; spread spike detection; weekend and holiday blocking. This is Layer 2 — signals are never generated without passing through regime first. Trigger: "market regime", "trending vs ranging", "session filter", "news filter", "volatility filter", "spread filter", "when to trade", "ATR regime", "ADX trend strength", "killzone", "dead zone", "regime detection", "Layer 2".
Unsigned, install at your own risk
UnverifiedThis skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install metatrader-market-regimeManual setup by platform
Claude Code
~/.claude/skills/metatrader-market-regime/SKILL.md
Instructions
Market Regime
The regime filter decides WHETHER to trade. Signals decide WHAT to trade.
Never generate signals without first passing the regime gate.
See also: For post-hoc regime analysis in Python/pandas (rolling ATR,
trend-strength metrics, regime classification over historical data), see
the analytics skill under metatrader-research.
Purpose
Defines Layer 2 of the 5-layer EA architecture: classifying the current market
state (trending bull/bear, ranging, volatile, dead) and gating trade execution
through session, news, spread, and weekend filters. Every signal from Layer 3
must be passed a regime context.
When to Use
- Building the Layer 2 RegimeFilter module for any EA
- Deciding if a particular time/condition should allow trading
- Diagnosing why an EA trades during illiquid or high-spread periods
- Configuring session-specific strategies (London open, NY overlap, etc.)
- Reading tick/bar data structures or querying DOM depth
Do NOT use for:
- Entry signal generation -> use
signal-engine - Risk/sizing policy -> use
risk-engine - EA architecture / module wiring -> use
ea-architect
Core Guidance
Regime Classification Enum
All modules share this enum. Define it in CoreEngine.mqh.
enum ENUM_REGIME {
REGIME_UNDEFINED = 0,
REGIME_TRENDING_BULL,
REGIME_TRENDING_BEAR,
REGIME_RANGING,
REGIME_VOLATILE,
REGIME_DEAD,
};
Regime-to-signal mapping:
| Regime | Use | Skip |
|---|---|---|
| TRENDING_BULL | OB pullback longs, EMA bounce | Mean reversion shorts |
| TRENDING_BEAR | FVG fill shorts, breakdown entries | Mean reversion longs |
| RANGING | BBand bounce, RSI extremes, range boundaries | Breakout signals |
| VOLATILE | Reduce lot 50%, widen SL 50% | Tight scalping signals |
| DEAD | -- | Everything |
| UNDEFINED | -- | Everything, wait for clarity |
CRegimeFilter — ADX/ATR Detection
class CRegimeFilter : public IModule {
private:
int m_adxPeriod;
double m_adxTrendThreshold;
double m_adxRangeThreshold;
int m_atrPeriod;
double m_volatilityMultiplier;
public:
CRegimeFilter(int adxPeriod=14, double trendTH=25.0, double rangeTH=20.0,
int atrPeriod=14, double volMult=2.0) { ... }
ENUM_REGIME GetCurrentRegime() {
if(IsDeadZone()) return REGIME_DEAD;
if(IsHighVolatility()) return REGIME_VOLATILE;
double adx=GetADX(PERIOD_H4), plusDI=GetPlusDI(PERIOD_H4), minusDI=GetMinusDI(PERIOD_H4);
if(adx>=m_adxTrendThreshold) {
if(plusDI>minusDI) return REGIME_TRENDING_BULL;
if(minusDI>plusDI) return REGIME_TRENDING_BEAR;
}
if(adx<m_adxRangeThreshold) return REGIME_RANGING;
return REGIME_UNDEFINED;
}
bool IsDeadZone() {
MqlDateTime t; TimeToStruct(TimeGMT(), t);
return (t.hour>=21||t.hour<1); // 21:00-01:00 UTC thin liquidity
}
bool IsHighVolatility() {
double current=iATR(_Symbol,PERIOD_H1,m_atrPeriod,1);
double avg=0;
for(int i=1;i<=20;i++) avg+=iATR(_Symbol,PERIOD_H1,m_atrPeriod,i);
avg/=20.0;
return (current>avg*m_volatilityMultiplier);
}
bool IsReady(){return true;}
void Reset(){}
string GetStatus(){return "Regime: "+EnumToString(GetCurrentRegime());}
};
Session Filter — London, NY, Asian Killzones
class CSessionFilter {
private:
int m_gmtOffset;
bool m_london, m_ny, m_asian;
public:
CSessionFilter(int gmtOffset, bool london=true, bool ny=true, bool asian=false) { ... }
bool IsActiveSession() {
if(IsWeekend()) return false;
if(IsPreWeekendClose()) return false;
MqlDateTime t; TimeToStruct(TimeGMT(), t);
int h=t.hour;
if(m_london&&h>=7&&h<9) return true; // London killzone
if(m_ny &&h>=12&&h<16) return true; // London-NY overlap
if(m_ny &&h>=19&&h<21) return true; // NY close hunt
if(m_asian &&h>=0&&h<2) return true; // Asian killzone
return false;
}
bool IsWeekend(){MqlDateTime t;TimeToStruct(TimeGMT(),t);return(t.day_of_week==0||t.day_of_week==6);}
bool IsPreWeekendClose(){MqlDateTime t;TimeToStruct(TimeGMT(),t);return(t.day_of_week==5&&t.hour>=20);}
};
Spread Monitor and News Filter
bool IsSpreadAcceptable(double maxSpreadPoints) {
double spread=(double)SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
return(spread<=maxSpreadPoints);
}
class CNewsFilter {
int m_bufferMinutes;
public:
CNewsFilter(int bufferMin=30){m_bufferMinutes=bufferMin;}
bool IsSafeToTrade(){
MqlDateTime t; TimeToStruct(TimeGMT(),t);
int h=t.hour, m=t.min;
// Simplified: avoid 12:20-13:00 UTC on weekdays (catches most USD releases)
if(t.day_of_week>=1&&t.day_of_week<=5)
if(h==12&&m>=20)return false;
if(h==13&&m<10)return false;
return true;
}
};
Wiring Regime Into OnTick
void OnTick() {
if(!IsNewBar(PERIOD_M15)) return;
if(!g_RiskMgr.IsTradeAllowed()) return; // Layer 1
if(!g_Session.IsActiveSession()) return; // Session timing
if(!g_NewsFilter.IsSafeToTrade()) return; // News avoidance
if(!IsSpreadAcceptable(50)) return; // Spread check
ENUM_REGIME regime=g_Regime.GetCurrentRegime();
if(regime==REGIME_DEAD||regime==REGIME_UNDEFINED) return;
double lotMultiplier=(regime==REGIME_VOLATILE)?0.5:1.0;
STradeSignal sig=g_Signal.GetSignal(regime);
if(sig.type==SIGNAL_NONE) return;
double lots=g_RiskMgr.CalculateLotSize(sig.slDistance)*lotMultiplier;
g_TradeMgr.OpenTrade(sig,lots);
}
References
Market data structures (MqlTick, MqlRates, MqlBookInfo), ENUM_BOOK_TYPE,
ENUM_SERIES_INFO_INTEGER, ENUM_TIMEFRAMES, ENUM_APPLIED_PRICE, and
ENUM_MA_METHOD are documented in the MQL5 Reference:
docs/mql5_com_-_docs/constants-structures-mqltick.mddocs/mql5_com_-_docs/constants-structures-mqlrates.mddocs/mql5_com_-_docs/constants-structures-mqlbookinfo.mddocs/mql5_com_-_docs/constants-tradingconstants-enum_series_info_integer.mddocs/mql5_com_-_docs/constants-chartconstants-enum_timeframes.mddocs/mql5_com_-_docs/constants-indicatorconstants-prices.mddocs/mql5_com_-_docs/constants-indicatorconstants-enum_ma_method.md
For post-hoc regime analysis in Python, see analytics under
metatrader-research.
Security
Reviews (0)
Related skills
Browse all →More from MetaTrader Skills
View source →More Build skills
Browse category →Frequently asked questions about market-regime
What does the market-regime skill do?
Market regime detection and filtering for MQL5 EAs. Use for all logic that determines WHETHER to trade: trend vs range classification via ADX; volatility regime via ATR (high/normal/reduced); session filtering (London/NY/Asian killzones); news event avoidance; spread spike detection; weekend and holiday blocking. This is Layer 2 — signals are never generated without passing through regime first. Trigger: "market regime", "trending vs ranging", "session filter", "news filter", "volatility filter", "spread filter", "when to trade", "ATR regime", "ADX trend strength", "killzone", "dead zone", "regime detection", "Layer 2". It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the market-regime skill?
Run `npx @skills-hub-ai/cli install metatrader-market-regime` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/metatrader-market-regime/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does market-regime work with?
market-regime runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the market-regime skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use market-regime after installing it?
In Claude Code, type `/metatrader-market-regime` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the market-regime skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.