BKT RegimeShift EA Trend Range Engine
- エキスパート
-
Khac Thanh Bui
トレードのロジックをアルゴリズムの精度へ。実践的なトレードのニーズとハイエンドなソフトウェア開発の架け橋となり、FXとゴールド向けのプロフェッショナルツールを開発しています。
私の開発物:
- ⚙️ アルゴリズムシステム:プロップファーム(Prop-Firm)の厳しい基準を満たすロジック(安全なブレイクアウト、マーチンゲールなし)から、ダイナミックで高利回りのエンジン(スマートグリッド/DCA)まで提供します。
- 📊 高度なユーティリティ:シームレスな裁量トレードを実現する、プロ仕様のUIを備えた高性能ダッシュボードおよびポジション管理ツール。
私のコミットメント: - バージョン: 1.13
BKT RegimeShift — Trend & Range Engine
An adaptive expert advisor for MetaTrader 5 that classifies the market regime before it trades, applying a different entry method to trending and non-trending conditions.
Most automated systems apply one fixed method to every market condition. A trend-following approach struggles in a range, and a mean-reversion approach struggles in a trend. BKT RegimeShift measures how directional price movement currently is, and selects its behaviour from that measurement rather than a fixed rule. The classifier runs on closed bars only, independent of the trading logic that consumes it.
Overview
The core of the system is an Efficiency Ratio calculation, comparing the net distance price travelled over a lookback period against the total distance actually covered bar by bar. A value near one means price moved in a straight line; near zero means it covered ground without going anywhere.
That value is then converted into a percentile rank against its own recent history. This matters because a given reading means one thing on gold and another on a major currency pair. Ranking removes the need to tune absolute thresholds per symbol.
The percentile drives a four-state machine: mean-reversion, transition, trend and cooldown. Entry and exit thresholds are deliberately asymmetric, with a minimum dwell time enforced, both to stop the classifier flipping on noise.
In trend mode it trades with the measured move and can add positions as price advances in its favour. In mean-reversion mode, disabled by default, it fades the move and averages on a grid spaced by Average True Range. Positions close on a portfolio target in account currency, not a fixed price distance.
Key Features
- Percentile-based classifier — Thresholds are percentile ranks, not absolute values, so the same settings adapt across symbols and volatility conditions.
- Asymmetric state machine — Separate entry and exit thresholds plus a minimum dwell period reduce flip-flopping in choppy conditions.
- Dual-mode operation — Trend-following and mean-reversion are separate engines with separate parameters, and mean-reversion can be switched off entirely.
- Portfolio-level exit — Positions close on a combined target in account currency, one side or both together, with optional trailing.
- Target scaling — The target can scale with total position size, so it stays proportionate as a basket grows rather than becoming easier to reach.
- Multiple entry brakes — Independent checks pause new averaging entries when directional strength rises, when tiers fill unusually fast, or past a defined floating loss.
- Reversal entry — When direction flips while a position is still open on the opposite side, a lower threshold allows the new direction without waiting for the full state cycle.
- On-chart dashboard — A canvas panel shows the active regime, an equity sparkline, per-side position data, floating result and current drawdown.
How It Works
On each closed bar the expert advisor recalculates the Efficiency Ratio and Average True Range, ranks both against their rolling windows, and updates the regime state. On every tick it manages open positions and checks whether a new entry is permitted.
An open basket has its floating result compared against the configured target, with a lone position using a smaller target than a multi-position basket. Where trailing is enabled, it arms at a defined profit and closes after a defined giveback from the peak recorded.
Closing is a single grouped operation: orders are sorted by result, sent asynchronously, then verified, with a synchronous retry only for any position not confirmed within a short grace period.
Recommended Settings
The supplied defaults were prepared for XAUUSD on the M5 classifier timeframe. Classifier periods, percentile window, dwell and cooldown values are all scaled to that timeframe, so changing it means reviewing those values together rather than individually.
An account with competitive spreads is advised, since grid spacing has a spread-based floor. A VPS is recommended for uninterrupted operation. Test on a demo account and establish your own parameter set before considering live use.
Input Parameters
Regime classifier:
- Classifier timeframe — Used for all regime calculations — Default: M5
- Efficiency Ratio period — Lookback length in bars — Default: 24
- Percentile window — History used for ranking — Default: 1000
- Trend entry and exit thresholds — Percentile ranks that change state — Default: 60 and 25
Position sizing and grid:
- Equity risk percent — Sizes the first entry — Default: 0.5
- Grid step multiple — Averaging entry spacing, in Average True Range — Default: 0.6
- Lot multipliers — Applied per tier, set separately for each mode — Default: 1.09 and 1.1
- Maximum tiers — Ceiling per basket — Default: 50
Exits and protection:
- Single position target — Target in account currency for one isolated position — Default: 1.5
- Basket target — Target in account currency for a basket — Default: 30.0
- Trailing activation and giveback — Arms, then closes on giveback — Default: 16.0 and 8.0
- Account drawdown limit — Closes all positions past this drawdown from peak equity — Default: 20.0
This expert advisor uses grid and averaging position sizing. In mean-reversion mode it adds to a position moving against it, with an increasing lot size. There is no per-position stop loss and no per-basket loss limit. The only loss protection is the account-level drawdown limit, which closes every open position at once when reached. Baskets can grow until that threshold is met, bounded only by the tier ceiling and available margin. Set the drawdown limit deliberately and test on a demo account before any live use.
