The existing Z-Score EAs test profitable on M1 OHLC but fail under
Every Tick because they decide on individual ticks: noise fires the
Z-exit at the worst price, market-order exits pay spread twice, and
no minimum-edge check means quiet-market trades only ever pay spread.
XAU_Quant_Reversion_TickRobust.mq5 closes that gap:
- All decisions (entry, exits, breakeven, TP retarget) run exactly
once per bar on closed-bar data, so OHLC and Every Tick converge
- Cost gate: StdDev >= 3x and TP distance >= 4x the round-trip cost
(live spread + commission points) or the trade is skipped
- Server-side limit TP placed at the mean, retargeted per bar with a
cost-covering floor (no spread paid on exit)
- Turn-confirmation bar before entry (no knife-catching)
- Volatility-aware SL: max(800 pts, 2.5x ATR) against tick spikes
Docs: README section for the new EA, CLAUDE.md overview updated.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012knbN7oGPQ7K4TnRroZjWF
OHLC EA improvements:
- Add ADX regime filter (InpADXMax, default 25): block mean-reversion
entries in trending markets, restoring the documented ADX gate
- Require live Z-Score (>= 90% of threshold) alongside the closed-bar
signal so entries no longer chase price after an intra-bar snap-back,
and no instant re-entry fires after a Gravity Exit win
- Add loss cooldown (InpCooldownMins, default 10): pause entries after
a losing trade instead of re-entering the same extended move
- Remove the soft 0.75x Z threshold that entered at weak extremes
(~1.5 sigma) in stable markets; full threshold always applies
- Recover open position on restart (adopt ticket + rebuild trade record)
and seed Z-Score at init so a recovered position is managed instead of
being orphaned or instantly closed on a bogus Z=0
- Restore the absolute spread cap (InpMaxSpreadPts was declared but unused)
- Give the velocity filter a 10-second time window so slow drift across
10 ticks in quiet markets no longer false-triggers the spike block
- Capture position ticket via DEAL_POSITION_ID with ordered fallbacks
- Extend news load window past midnight for early-next-day events
- Guard daily-loss check against zero starting balance
EveryTick EA: remove dead no-op confirmation block
https://claude.ai/code/session_01GPhWxikvDKmDNwQGhs6gFp
Remove old XAU_Quant_Reversion.mq5 and RT variant, add new M1 timeframe
optimized versions with separate EveryTick and OHLC modeling modes.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- CheckBreakeven(): moves SL to entry+10pts once price gains 1.5*ATR,
guaranteeing a no-loss trade; runs every tick with broker stop-level safety
- HandleTrailingStop(): halves ATR trail multiplier after 50% of
InpMaxHoldMinutes has elapsed to tighten gains before time-exit fires
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Dynamic Z threshold: raises InpEntryZ by 0.5 when current ATR > 1.5x
its 100-bar average, avoiding premature entries in high-volatility spikes
- ATR-relative spread gate: blocks entry when spread exceeds 12% of current
ATR in points (transaction cost too high relative to expected M1 move),
replacing the fixed 1.0x ATR cap
- Comment() now displays Volatility Ratio, Dynamic Z-Target, and MaxAllowed
spread for real-time filter visibility
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduces a per-trade CSV log (N30_TradeLog_SYMBOL_MMAGIC.csv) that
captures full entry context and exit metrics on every closed position.
Position selection now uses a cached ticket (glTicket) via
PositionSelectByTicket for efficiency and correctness in both live
trading and Strategy Tester.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace invalid SYMBOL_STOPLEVEL with correct SYMBOL_TRADE_STOPS_LEVEL
- Add SymbolSelect() in OnInit to ensure symbol is in Market Watch
- Fix NormalizeLot digit calculation (log10-based, removes fragile float ==)
- Add minimum lot guard in ExecuteTrade to prevent oversized clamped lots
- Add defensive SelectOwnPosition() re-call in HandleTrailingStop
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Marubozu filter: skips entry if last M1 candle body > 90% of range (high-momentum breakout guard)
- Spread check: now also blocks if spread > 50% of current ATR in points, preventing entries in illiquid conditions
- Comment refactored to show real-time status of all filters: Z-Hook, Vol-Filter, H1 Trend, Marubozu, Spread, Session, News
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Instructs Claude to place "// This work is my worship unto GOD" as the very last line after every EA file update.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds InpFilterPeriodH1 input (default 200) and handleMA_H1 to filter
mean-reversion entries against the H1 structural trend. BUY signals
require price above H1 SMA; SELL signals require price below it.
Set InpFilterPeriodH1=0 to disable.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds full documentation for XAU_Quant_Reversion_Breakout.mq5 including
dual strategy overview, all input parameters, and design notes. Also
adds missing InpMaxPositions param to the primary EA's parameter table.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use day_of_year instead of day in IsNearNews() to avoid skipping
news reloads on same-numbered days across different months (both EAs)
- Remove alreadyPartial requirement from MR Z-TP condition in Breakout
EA so position closes when Z reverts even if scale-out zone was skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Critical bugs fixed:
- Breakout EA: early `return` in MR/TB entry blocks now conditional so
both strategies run independently regardless of each other's position count
- Breakout EA: partial close detection replaced comment-based tracking
(broken in MQL5) with partialClosedTicket global variable
- Breakout EA: cooldown now triggers correctly via lastTBCount change
detection instead of never resetting barsSinceClose
Moderate issues fixed:
- Both EAs: symbol validated on init with XAUUSD fallback
- Both EAs: magic number comparisons cast to long to fix type mismatch
- Both EAs: fill mode now includes ORDER_FILLING_RETURN as fallback
- Both EAs: margin check added before trade execution
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix CalendarValueHistory return type bug (was int, should be bool)
- Add dynamic risk tiers to breakout EA (synced from primary)
- Replace ATR-based SL with fixed-point SL/TP in breakout EA
- Add Z-Score full exit to breakout EA's mean reversion
- Add new-bar trailing (reduces broker modify requests)
- Add max positions limit input to both EAs
- Add comment truncation (MT5 31-char limit)
- Fix explicit ulong cast for position ticket
- Add CLAUDE.md for codebase documentation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- SL: fixed 800 points instead of ATR-based (survives gold spikes)
- TP: close when Z-Score reverts to ±0.3 (natural mean reversion exit)
- Hard TP: 1500 points server-side safety net
- Trailing stop still active on new bars
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Wider SL gives room for gold whipsaws, closer TP is reachable for
mean reversion snap-backs, trail won't choke winners early.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add server-side hard TP (4x ATR) to survive disconnects
- Remove dead scale-out/partial close code (unusable at 0.01 lots)
- Trail stop only on new bar close instead of every tick
- Add CountOwnPositions() guard against duplicate entries
- Cache volatility filter result instead of calling twice
- Fix header filename and version to v5
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MQL5 calendar MODERATE importance doesn't match Forex Factory orange
folder — it includes CFTC positioning and Baker Hughes rig counts which
don't move gold. Removed two-tier VHI/HI split, now single 60-min
pause window for all red-folder USD events.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TimeGMT() was incorrect — CalendarValueHistory() and MqlCalendarValue.time
both use broker server time, not UTC. Reverts to TimeCurrent() for
consistent time base.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update Print logs, trade comments, dashboard text, and code comments
to use descriptive Forex Factory folder color labels.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously all CALENDAR_IMPORTANCE_HIGH events were split by keyword into
VHI/HI tiers, and moderate-impact (orange) events were ignored entirely.
Now maps directly to Forex Factory colors: red (HIGH) → VHI with 60-min
window, orange (MODERATE) → HI with 15-min window, yellow (LOW) → ignored.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CalendarValueHistory() returns events in UTC, but the day window and
time comparisons were using TimeCurrent() (broker server time), causing
the EA to pick up wrong-day news events due to timezone offset.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reduce breakout losses by cutting risk from 10% to 3%, raising ADX
threshold to 30, extending Donchian period to 30, doubling cooldown to
10 bars, widening ATR stop to 2.5x, and adding min DI spread filter (5.0).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix MQL5 compilation errors: proper enum casts for PositionGetInteger(),
ulong cast for POSITION_TICKET, and replace goto with inverted condition.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Trade comments encode signal context (direction, Z-score, ADX, ATR)
for post-trade analysis. Scale-out, news close, and daily loss close
actions also get descriptive comments.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Old README described features that no longer exist (partial closes,
trailing stops, news filter, scaled entry, weekly/equity stops,
volatility filter). Updated to accurately document both gold and BTC
EAs with their current parameters and design rationale.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Gold EA: remove dead partial close/trailing code (impossible at 0.01 lots),
add mandatory hard TP at 2.0 ATR, tighten SL to 1.2 ATR, lower daily
loss limit to 25%.
BTC EA: new file adapted for BTCUSD M15 with RSI filter enabled,
ADX 22, Z-score 2.2, hard TP 1.5 ATR for fast mean reversion scalps.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>