Capstan Gold Regime
- Experts
- Versione: 1.0
- Attivazioni: 5
Capstan Gold Regime is an original Expert Advisor for gold (XAUUSD). On each closed signal bar it classifies the market as TREND, RANGE or HIGH-VOL/CHAOS, then trades only when the classified regime allows it. By default it takes RANGE mean-reversion trades and stands aside in TREND and CHAOS. Every order has a stop-loss. It holds one position at a time.
No grid, no martingale, no averaging, no partial closes, no DLL, no web requests, no hidden behaviour.
How it trades
- Regime classification (closed bars only). The signal timeframe defaults to H1; the chart timeframe does not matter. Four original measures are combined: ATR(14) percentile over 100 bars, the ratio of short (24-bar) to long (120-bar) realised volatility of log returns, a 20-bar Kaufman efficiency ratio, and the t-statistic plus R² of a 36-bar linear regression of close prices.
- CHAOS. Declared when the ATR percentile is at least 88, or the short/long vol ratio is at least 1.85, or a low efficiency ratio (0.18 or below) coincides with an elevated ATR percentile (72 or above). No new entries. An open position is closed (default) or, optionally, its stop is tightened.
- TREND. Declared when the market is not in CHAOS, the efficiency ratio is at least 0.32, the absolute regression t-statistic is at least 2.0 and R² is at least 0.38. Optional pullback-continuation entries in the slope direction are included in the code but are off by default. In the 8-month tuning window, trend-only entries were weak (PF 1.12) and enabling them alongside RANGE raised net profit slightly but worsened the profit factor and drawdown.
- RANGE (default entries). If the market is neither CHAOS nor TREND, the EA mean-reverts to a volatility-adjusted typical-price centre (typical price weighted by tick volume / true range over 48 bars) when the z-score of the close reaches ±1.70, provided it is not already beyond ±3.20 and the signal bar closes back toward the mean.
- Stop. 2.0× ATR(14) of the signal timeframe on RANGE trades (2.5× ATR if TREND entries are enabled), sent with the order.
- Target. RANGE: a take-profit near the centre (z-score +0.15 through the mean), sent with the order; the trade is also closed if the z-score later reaches that target. TREND (if enabled): 2.5R.
- Regime-change exits. RANGE trades are closed if the regime leaves RANGE. Open trades are closed (default) when the regime switches to CHAOS.
Risk controls
- Volatility-targeted size. Base risk is 1% of equity at the stop, then multiplied by median ATR / current ATR and capped between 0.50 and 1.50, so size is reduced when volatility is high.
- Minimum-lot cap. If the broker's minimum lot is larger than the calculated size, it is used only when its stop risk is at most 5% of equity. Small accounts can tighten the stop down to 1.5× ATR to fit that cap. Otherwise the trade is skipped and logged.
- Daily loss limit. 3% from the start of the server day. No new entries for the rest of that day.
- Equity guard. If equity falls 20% below its peak, new entries are paused for 5 days.
- Spread filter. The spread must be at most 0.15× ATR. An optional cap in points is also available.
- Order checks. OrderCheck, OrderCalcMargin, volume, trade mode, stops level and freeze level are checked before every order, modify and close. Works on hedging and netting accounts.
Tested results (honest)
Test conditions. Every tick based on real ticks, JustMarkets-Demo2 symbol XAUUSD.m, H1, leverage 1:100, v1.00 defaults (RANGE entries only). Period 16 November 2025 to 16 November 2026 (broker data ends 13 November 2026). 81,113,443 ticks, history quality 100% real ticks. Compiled with 0 errors and 0 warnings. No run produced trade errors or a stop-out.
USD 10,000:
- Net profit +576.18, profit factor 1.32, recovery factor 1.36, Sharpe ratio 3.69.
- Equity drawdown maximal 424.81 (4.04%). Balance drawdown 347.92 (3.26%).
- 75 trades, all RANGE, 41.33% winners. Average win +77.02, average loss -41.17, largest loss -132.79. Maximum consecutive losses: 6 (-97.52).
- A netting-account run gave the same result.
Tuning vs held-out months. Settings were chosen on 16 November 2025 to 16 July 2026 only. Seven variants were compared on real ticks with a USD 10,000 deposit: the original combined TREND+RANGE defaults (+649.87, PF 1.25, equity drawdown 6.82%, 116 trades), stricter and looser classification, wider stops, TREND only, RANGE only, and holding through regime changes. RANGE only had the best quality: +583.95, PF 1.54, equity drawdown 4.04%, 50 trades, recovery factor 1.37. TREND only was weak (+189.86, PF 1.12). Holding through regime changes was worse (PF 1.11, equity drawdown 7.59%). Those RANGE-only settings were locked as v1.00 defaults. Split of the full-year USD 10,000 run by deal close time:
- Tuning window: +583.95, PF 1.54, 50 trades, 42.0% winners.
- Held-out last four months: -7.77, PF 0.99, 25 trades, 40.0% winners. The held-out period was essentially flat. Do not expect the tuning-window profit factor to repeat.
USD 5,000 (same period, real ticks): net +275.60, PF 1.28, equity drawdown 253.04 (4.86%), 75 trades. Tuning window +221.37 (PF 1.32), held-out four months +54.23 (PF 1.19). At this size 19 of the 75 entries used the 0.01 minimum lot, so those trades risked more than 1% (up to the 5% cap).
USD 1,000 (same period, real ticks): net -32.75, PF 0.95, equity drawdown 265.57 (24.30%), 60 trades. All 60 entries used the minimum lot; 22 further signals were skipped because the 0.01 lot would have risked more than 5% of equity; the daily-loss guard halted new entries on 11 days and the equity-drawdown pause tripped once. Tuning window -51.94 (PF 0.86), held-out +19.19 (PF 1.09). This deposit was not profitable and the drawdown is too large for a USD 1,000 gold account.
Small-deposit netting checks (1-minute OHLC, same period; technical checks only, to confirm the EA can open trades and skip safely):
- XAUUSD D1 chart, USD 1,000: -32.53, 60 trades, equity drawdown 24.40%. (The signal timeframe is still H1.)
- EURUSD H1, USD 1,000: -60.08, 89 trades, equity drawdown 9.15%. The EA is not designed for EURUSD.
- XAUUSD, USD 100: 0 trades. All 108 candidate entries were skipped and logged because the 0.01 minimum lot would have risked far more than 5% of equity at a gold ATR stop.
- EURUSD H1, USD 100: -7.94, 84 trades, equity drawdown 22.28%.
Recommendations
- XAUUSD, any chart timeframe. The signal timeframe defaults to H1.
- Minimum deposit: USD 5,000 (tested: profitable, 4.86% equity drawdown; some minimum-lot trades). USD 10,000 or more lets the 1% volatility-targeted sizing work on almost every trade. USD 1,000 was not profitable in this test and is not recommended. Use a low-spread gold account and a VPS.
- The full-year result on USD 10,000 is modest (about +5.8%, PF 1.32) with a low 4.04% equity drawdown. The held-out four months were essentially break-even (PF 0.99). Results will vary with the broker, spread and the mix of RANGE vs CHAOS regimes.
Inputs (v1.00 defaults)
| SignalTF | H1 |
| AtrPeriod / AtrLookback | 14 / 100 |
| VolShortPeriod / VolLongPeriod | 24 / 120 |
| ErPeriod / RegPeriod | 20 / 36 |
| ChaosAtrPct / ChaosVolRatio | 88 / 1.85 |
| ChaosErMax / ChaosErAtrPct | 0.18 / 72 |
| TrendErMin / TrendTStatMin / TrendR2Min | 0.32 / 2.00 / 0.38 |
| TradeTrend / TradeRange | false / true (RANGE entries only by default) |
| TrendPullbackATR / TrendMaxExtATR | 0.35 / 1.80 |
| TrendStopATR / TrendTakeProfitR | 2.50 / 2.50 |
| TrendExitOnSlopeFlip / TrendExitOnRegimeLeave | true / true |
| RangeLookback / RangeZEntry / RangeZMax | 48 / 1.70 / 3.20 |
| RangeStopATR / RangeTargetZ / RangeExitOnRegimeLeave | 2.00 / 0.15 / true |
| ChaosAction / ChaosTightenATR | 1 (exit) / 1.00 |
| EnableLong / EnableShort | true / true |
| SessionStartHour / SessionEndHour / FridayCutoffHour | 0 / 0 (24h) / 0 (off) |
| CooldownBars | 1 |
| RiskPercent / VolTargetMinScale / VolTargetMaxScale | 1.0 / 0.50 / 1.50 |
| MaxMinLotRiskPct / SmallAccountStopATR | 5.0 / 1.5 |
| DailyLossPercent | 3.0 |
| EquityDDPercent / PauseDays | 20.0 / 5 |
| MaxSpreadATR / MaxSpreadPoints | 0.15 / 0 (off) |
| MaxFreeMarginUsePercent / MinMarginLevel | 30 / 300 |
| SlippagePoints / MagicNumber / ShowPanel | 30 / 26111801 / true |
Disclaimer
These are historical simulations on one broker's data over one year. They do not promise future results. Trading gold with leverage can lose money, including more than the backtests show. The held-out four months were essentially flat; past profit factors from the tuning window should not be treated as expected live performance.
