コンテンツにスキップ

Statistical Mean Reversion

EA0044_Statistical_Mean_Reversion_v1.0 / ✅ LIVE — バックテスト合格・運用中

ワンライナー

Statistical Mean Reversion

基本情報

項目 項目
シンボル USDJPY エントリー種別 oscillator_reversal
時間足 H1 エグジット fixed_sl
方向 both 主要インジケータ

🧬 DNA 4軸

primary_style entry_mechanism regime_target position_logic
mean_reversion oscillator_reversal ranging fixed_sl

📊 バックテスト結果

判定: ✅ PASS / 期間: 2024.08.15 〜 2026.02.06

PF 損益率 勝率 最大DD シャープ 取引数
1.50 +1.24% 85.7% 1.00% 2.45 15

📝 仕様書 / Specification

🇯🇵 クリックで展開(日本語版)

Research EA Spec: Statistical Mean Reversion

EA Identity

  • EA name: REF0502_01_Statistical_Mean_Reversion_v1
  • Symbol: USDJPY
  • Timeframe: H1
  • Primary style: mean_reversion
  • Entry mechanism: oscillator_reversal
  • Regime target: ranging
  • Position logic: fixed_sl

Research Thesis

Statistical Mean Reversion candidate generated from 2 research source(s). The strategy must preserve the source idea while keeping parameters broad enough to survive out-of-sample testing.

Source Evidence

  • [FILTER] [MR] 市場クローズ前後 (23:00-01:30 JST) は日次決算ポジション調整で流動性低下、スキャルは避ける
  • [SEASONAL] [MR] 月初の週 (1-5営業日) は機関の月次リバランスでドルが買われやすい傾向
  • Mean Reversion Patterns
  • [MR] Bollinger Bands σ=2 では統計的エッジがほぼない、σ=2.5以上で初めて意味を持つ (Aronson 2007)

Tradable Spec

  • Entry logic: Mean-reversion oscillator entry: BUY entry: RSI(14) on bar[1] recovers from oversold — rsi[1] > InpOversold && rsi[2] <= InpOversold (input default InpOversold=35). A near-zone recovery is also allowed for activity: rsi[1] > rsi[2] && rsi[2] <= InpOversold + InpRSIReentryBuffer (default buffer=5). SELL entry: RSI rolls down from overbought — rsi[1] < InpOverbought && rsi[2] >= InpOverbought (default InpOverbought=65), or rsi[1] < rsi[2] && rsi[2] >= InpOverbought - InpRSIReentryBuffer. Mean-zone anchor: use a separate 50-bar SMA only as a broad reversion zone, not as a trend filter. Define buyZone = close[1] <= sma50[1] + atr[1] * InpMeanZoneATR and sellZone = close[1] >= sma50[1] - atr[1] * InpMeanZoneATR (default InpMeanZoneATR=1.0). BUY requires buyZone; SELL requires sellZone. ONE zone variable per side only: do not add any second regime gate such as SMA slope, ADX, BUY-above-SMA, or SELL-below-SMA. The zone is intentionally permissive so RSI recovery can still fire and avoid NO_TRADE.
  • Exit logic: Take profit: (1) price returns to N-bar SMA (default N=20), OR (2) RSI crosses back through midline (from oversold: RSI[1] > 50; from overbought: RSI[1] < 50) — whichever fires first. Stop loss: ATR(14)*1.5 beyond entry bar, FIXED (never trail — trailing converts reversion to trend trade). Time exit: close at bar InpMaxBars (default=12) if neither TP nor SL triggered (stale reversion = structural failure, not an opportunity). Do NOT hold mean reversion trades past session boundary.
  • Risk management: Fixed fractional risk per trade, no martingale, no grid expansion, max one position per symbol, and hard daily loss guard.
  • Regime filter: ranging regime confirmation
  • Invalidation condition: To be determined during testing or derived from logic

Filters

  • Spread and session filter
  • Minimum ATR activity filter
  • Regime-specific confirmation filter from source evidence

Logic Independence Requirements

必須チェック(実装前に確認すること):

  • エントリーシグナル変数とレジームフィルター変数は独立したデータ源または独立したlookbackから計算すること
  • 悪い例: bullishCross = fastMA[1] > slowMA[1]isBearishRegime = fastMA[1] < slowMA[1] を AND 結合 → 同一バーで両立不可、取引ゼロになる
  • 正しいレジーム定義: slowMA[1] - slowMA[10] の傾き、上位足のMA方向、長い lookback(50本以上)の傾き
  • 全フィルターを AND 結合した時に、理論上発火できるバーが存在することをスケッチで確認すること
  • 逆張り戦略では「エントリー条件の否定 ≠ レジーム条件」になっているか必ず確認すること
  • RSI・BB・ATR など同一インジケーターを「シグナル源」と「フィルター源」の両方に使う場合、同じバーで矛盾する不等式を要求していないか確認すること
  • レジーム変数は1本のみ: bullishRegime (または uptrend 等) という bool 変数を1つ定義し、エントリー条件の AND に使うのはその1変数のみにすること。bullishRegime && regimeUp のように2本のレジーム変数を AND 結合することを禁止する。スロープ・価格位置・ADX など複数軸で判断したい場合は、それらを統合した1本の bool 変数にまとめてから AND に組み込むこと。

Optimization Envelope

  • Relaxable: confirmation thresholds, ATR activity threshold, session window, signal confirmation bars.
  • Not relaxable: stop-loss discipline, max one position, no martingale, no fixed historical price levels.
  • Initial optimization scope: 3-5 parameters only.
  • If no trades: loosen entry confirmation first, then session restriction, then ATR threshold.
  • If too many trades: strengthen regime filter and minimum signal distance.

Backtest Acceptance

  • Backtest at least 18 months with the latest 3 months held out.
  • Use walk-forward setting 6:2 when MT5 runner is available.
  • Reject if OOS/IS PF ratio is below 0.70 or if OOS PF min is below 1.10.
  • Reject if OOS trade count is too low; first loosen entry filters before optimizing profit targets.

Overfitting Controls

  • Keep each numeric parameter in a wide theory-backed range; do not tune to a single date range.
  • Limit optimization to 3-5 core parameters in the first pass.
  • Prefer regime filters with clear market meaning over curve-fitted thresholds.
  • Stop improving the candidate after repeated NO_TRADE/LOW_SAMPLE failures.

Learning Feedback

  • ledger: 1 prior strategy failure(s) for this DNA
  • ledger: 1 prior tick-model mismatch hit(s) for this DNA
  • ledger: improve: loosen entry confirmation or session restriction before touching exits
  • ledger: improve: prefer theory-backed ranges and freeze nonessential parameters
  • ledger: improve: reduce blocking guards such as session, spread, cooldown, or confirmation before altering signal logic
  • ledger: improve: rerun with every-tick backtest before loosening entries because bar-based tests may miss tick-sensitive triggers
  • ledger: improve: signal_candidates / entry_blocked_count 等の診断、同一バー内の矛盾、session/spread/cooldown/filter のブロックを優先確認する。
  • ledger: improve: widen active sessions or simplify filters to increase sample size
  • ledger: learned: NO_TRADEが連続する場合、期間を小刻みに変えるより入口条件・到達不能条件・ガードブロックを先に調べる。

Implementation Guardrails

  • [META] [RISK] [CONTRA] MT5 Strategy Testerは同名EAのinput値をキャッシュすることがあり、mq5側のinputデフォルトを変更して再コンパイルしても、BTでは前回値が使われる場合がある。inputデフォルト変更の検証では、別EA名/別ファイル名にするか、tester.ini/ExpertParametersで明示的に値を渡し、Testerログの「started with inputs」を必ず確認する。 (.clinerules)
  • [RISK] [META] [CONTRA] 【部分決済後のコメント管理パターン】MQL5ではPositionModifyでコメントを変更できないため、TP1部分決済後の状態管理にコメントプレフィックスを使う設計は「二重部分決済」リスクを内包する。対策として: (1)グローバルなulong配列でTP1済みチケットを管理する、(2)部分決済後に残りを即クローズ→新コメントで再エントリーする、のいずれかのパターンを採用すること。 (.clinerules)
  • [TREND] [BREAKOUT] [FILTER] [META] マルチタイムフレームEAでATR等のボラティリティ指標をCopyBufferする際、エントリー判定用の価格・MA(start_pos=1で確定足参照)とATR(start_pos=0で未確定バー参照)でstart_posが混在しやすい。設計方針として「全バッファのstart_posを統一する」か「ATRのみ最新値を使う理由をコメントで明記する」かを決めておくべき。 (.clinerules)
  • [FILTER] SYMBOL_SPREADはポイント単位のlong値を返すため、価格単位に変換するには* _Pointを直接使用する (.clinerules)
  • [FILTER] スキャルピングEAでXAUUSD等のスプレッド変動が大きい銘柄を扱う場合、pips単位ではなく価格単位(ドル)でスプレッド閾値・トレランスを指定する設計が適切。_Digits==2環境ではpips×_Pointが意図しない極小値になる (.clinerules)
  • [TREND] [FILTER] スプレッドリトライパターン(予約エントリーのスプレッド不良時リトライ): 予約フラグ方式でスプレッド不良時に即破棄せず、MAX_SPREAD_RETRY回まで次バーで再試行する設計。リトライカウンターは予約フラグと同時にリセットし、クールダウンや金曜制限等の他条件で予約破棄する際もリセットを忘れないこと。リトライの粒度(ティック単位 vs バー単位)を設計時に明確にすべき。 (.clinerules)
  • [META] HistorySelect(0, TimeCurrent()) は全取引履歴を走査対象にするため、長期運用や多数の取引がある口座ではパフォーマンスに影響する。連敗カウント等の直近履歴のみが必要な場合は、開始時刻を限定する(例: TimeCurrent() - 30243600)か、最後のチェック時刻を記録して差分走査にする。 (.clinerules)
  • [META] MQL5のOnTradeTransactionではDEAL_ENTRY_INOUTも処理対象に含めないと、ネッティング口座での約定イベントを捕捉できない場合がある (.clinerules)

Story Package

  • Hook: AIが研究メモから自律発掘した「Statistical Mean Reversion」をEA化して検証。
  • Blog angle: 研究アイデアは本当にMT5で再現できるのか、OOSで崩れるかまで公開する。
  • Failure angle: 失敗時は NO_TRADE / LOW_SAMPLE / OVERFIT / HIGH_DD に分類して次の研究候補へ進む。

Spec Validation Warnings (auto-generated)

  • CONTRADICTION: Mean-zone anchor conditions create logical impossibility for simultaneous entry. BUY requires close[1] <= sma50[1] + atr[1] * InpMeanZoneATR (price at or below upper zone boundary) AND RSI recovery from oversold rsi[1] > InpOversold && rsi[2] <= InpOversold. SELL requires close[1] >= sma50[1] - atr[1] * InpMeanZoneATR (price at or above lower zone boundary) AND RSI recovery from overbought rsi[1] < InpOverbought && rsi[2] >= InpOverbought. However, the spec explicitly states 'do not add any second regime gate such as SMA slope, ADX, BUY-above-SMA, or SELL-below-SMA' and 'The zone is intentionally permissive so RSI recovery can still fire and avoid NO_TRADE.' This creates a contradiction: if the zone is truly permissive (allowing price anywhere), then the zone condition becomes meaningless; if the zone is restrictive (price must be within bounds), then it acts as a second regime gate, violating the explicit prohibition. The practical result is that the zone condition either (1) blocks most RSI signals by requiring price proximity to SMA, or (2) is ignored entirely, leaving only RSI which may not fire frequently enough to generate trades.
  • Fix: Clarify whether the zone condition is a hard gate (in which case it IS a regime filter and the prohibition is violated) or purely informational (in which case remove it from the entry logic entirely). If zone is meant to be permissive, define a numerical threshold (e.g., 'zone width must be > 2*ATR') that allows RSI signals to fire independently. Alternatively, separate zone confirmation into a distinct bar: check zone on bar[2], RSI recovery on bar[1].
  • WARNING: RSI reentry buffer condition creates potential logical contradiction. The spec defines two BUY entry paths: (1) rsi[1] > InpOversold && rsi[2] <= InpOversold (recovery from oversold), and (2) rsi[1] > rsi[2] && rsi[2] <= InpOversold + InpRSIReentryBuffer (near-zone recovery). The second condition allows entry when RSI[2] is between InpOversold (default 35) and InpOversold+5 (default 40). However, if InpOversold is set to 35 and InpRSIReentryBuffer to 5, the second condition fires when rsi[2] is in [35, 40]. This overlaps with the first condition's requirement rsi[2] <= 35. The overlap itself is not contradictory, but the spec does not clarify whether both conditions can fire on the same bar or if they are mutually exclusive. More critically, if both conditions are evaluated as separate OR branches without proper state management, a single bar could trigger multiple entries or create ambiguity in position tracking. The spec states 'max one position per symbol' but does not specify how to handle simultaneous signal firing.
  • Fix: Define entry priority explicitly: either (1) use OR with first-match-wins logic, (2) combine into a single condition (rsi[1] > InpOversold && rsi[2] <= InpOversold) || (rsi[1] > rsi[2] && rsi[2] <= InpOversold + InpRSIReentryBuffer) with clear state tracking, or (3) separate reentry into a distinct cooldown period after the primary entry to avoid same-bar ambiguity.
  • WARNING: Exit logic contains temporal contradiction between TP and RSI midline cross. The spec states: 'Take profit: (1) price returns to N-bar SMA (default N=20), OR (2) RSI crosses back through midline (from oversold: RSI[1] > 50; from overbought: RSI[1] < 50) — whichever fires first.' For a BUY entry from oversold (RSI was < 35), the TP condition is RSI[1] > 50. However, RSI recovery from oversold typically moves RSI upward gradually (35 → 40 → 50 → ...). The condition RSI[1] > 50 will eventually fire if the trade is held long enough. But the spec also requires 'Do NOT hold mean reversion trades past session boundary' and 'Time exit: close at bar InpMaxBars (default=12).' If RSI has not yet crossed 50 by bar 12, the trade is force-closed at bar 12 without hitting the RSI TP. This is not a logical contradiction per se, but it creates a scenario where the stated TP condition (RSI > 50) may never execute because the time exit fires first. The spec does not clarify the priority order: does RSI TP take precedence over time exit, or vice versa? If time exit takes precedence, then the RSI TP condition is effectively dead code for fast-moving reversions.
  • Fix: Clarify exit priority: (1) if RSI TP is primary, set InpMaxBars high enough (e.g., 20-30 bars) to allow RSI to reach 50, or (2) if time exit is primary, remove the RSI TP condition and rely on SMA return + time exit only. Alternatively, define a 'stale reversion' threshold: if RSI has not crossed 50 by bar N, close the trade as a structural failure (as the spec hints: 'stale reversion = structural failure').
  • WARNING: The spec prohibits 'second regime gate' but the mean-zone anchor (buyZone / sellZone) functions as a price-proximity filter. If this is intentionally permissive, it should be removed from the entry logic or redefined as a non-blocking informational zone. If it is restrictive, the prohibition is violated.
  • WARNING: RSI reentry buffer overlaps with primary recovery range; state management and entry priority must be explicitly coded to avoid same-bar ambiguity.
  • WARNING: Time exit (bar 12) may fire before RSI TP condition (RSI > 50) is reached in fast reversions; exit priority and InpMaxBars tuning are critical.
  • WARNING: The spec references 'Invalidation condition: To be determined during testing' — this is incomplete. Without a defined invalidation condition, the EA may hold losing trades longer than intended.
  • WARNING: Session filter (23:00-01:30 JST) and spread filter are mentioned in Filters section but not formally defined in Entry logic; implementation must ensure these are checked before entry signal evaluation.
  • WARNING: Minimum ATR activity filter is mentioned but no threshold is specified; this is a relaxable parameter per Optimization Envelope, but the default value is missing.
  • WARNING: The spec warns against 'two regime variables AND combined' but does not explicitly list all regime variables in the code. Ensure only one rangeRegime (or equivalent) bool is used in the final AND chain.
  • WARNING: Learning Feedback mentions 'signal_candidates / entry_blocked_count' diagnostics; if entry is blocked by session/spread/cooldown guards, the EA will report NO_TRADE even if RSI signals are present. Prioritize loosening guards over changing signal logic.
🇬🇧 Click to expand (English version)

Research EA Spec: Statistical Mean Reversion

EA Identity

  • EA name: REF0502_01_Statistical_Mean_Reversion_v1
  • Symbol: USDJPY
  • Timeframe: H1
  • Primary style: mean_reversion
  • Entry mechanism: oscillator_reversal
  • Regime target: ranging
  • Position logic: fixed_sl

Research Thesis

Statistical Mean Reversion candidate generated from 2 research source(s). The strategy must preserve the source idea while keeping parameters broad enough to survive out-of-sample testing.

Source Evidence

  • [FILTER] [MR] 市場クローズ前後 (23:00-01:30 JST) は日次決算ポジション調整で流動性低下、スキャルは避ける
  • [SEASONAL] [MR] 月初の週 (1-5営業日) は機関の月次リバランスでドルが買われやすい傾向
  • Mean Reversion Patterns
  • [MR] Bollinger Bands σ=2 では統計的エッジがほぼない、σ=2.5以上で初めて意味を持つ (Aronson 2007)

Tradable Spec

  • Entry logic: Mean-reversion oscillator entry: BUY entry: RSI(14) on bar[1] recovers from oversold — rsi[1] > InpOversold && rsi[2] <= InpOversold (input default InpOversold=35). A near-zone recovery is also allowed for activity: rsi[1] > rsi[2] && rsi[2] <= InpOversold + InpRSIReentryBuffer (default buffer=5). SELL entry: RSI rolls down from overbought — rsi[1] < InpOverbought && rsi[2] >= InpOverbought (default InpOverbought=65), or rsi[1] < rsi[2] && rsi[2] >= InpOverbought - InpRSIReentryBuffer. Mean-zone anchor: use a separate 50-bar SMA only as a broad reversion zone, not as a trend filter. Define buyZone = close[1] <= sma50[1] + atr[1] * InpMeanZoneATR and sellZone = close[1] >= sma50[1] - atr[1] * InpMeanZoneATR (default InpMeanZoneATR=1.0). BUY requires buyZone; SELL requires sellZone. ONE zone variable per side only: do not add any second regime gate such as SMA slope, ADX, BUY-above-SMA, or SELL-below-SMA. The zone is intentionally permissive so RSI recovery can still fire and avoid NO_TRADE.
  • Exit logic: Take profit: (1) price returns to N-bar SMA (default N=20), OR (2) RSI crosses back through midline (from oversold: RSI[1] > 50; from overbought: RSI[1] < 50) — whichever fires first. Stop loss: ATR(14)*1.5 beyond entry bar, FIXED (never trail — trailing converts reversion to trend trade). Time exit: close at bar InpMaxBars (default=12) if neither TP nor SL triggered (stale reversion = structural failure, not an opportunity). Do NOT hold mean reversion trades past session boundary.
  • Risk management: Fixed fractional risk per trade, no martingale, no grid expansion, max one position per symbol, and hard daily loss guard.
  • Regime filter: ranging regime confirmation
  • Invalidation condition: To be determined during testing or derived from logic

Filters

  • Spread and session filter
  • Minimum ATR activity filter
  • Regime-specific confirmation filter from source evidence

Logic Independence Requirements

Mandatory check (must verify before implementation):

  • Entry signal variables and regime filter variables must be calculated from independent data sources or independent lookback periods.
  • Bad example: bullishCross = fastMA[1] > slowMA[1] AND isBearishRegime = fastMA[1] < slowMA[1] — these cannot both be true on the same bar, resulting in zero trades.
  • Correct regime definition: slope of slowMA[1] - slowMA[10], higher timeframe MA direction, or slope over a long lookback (50+ bars).
  • When all filters are AND-combined, sketch-verify that at least one bar can theoretically trigger.
  • For mean-reversion strategies, always verify that "negation of entry condition ≠ regime condition".
  • When using the same indicator (RSI, BB, ATR, etc.) as both "signal source" and "filter source", confirm you are not demanding contradictory inequalities on the same bar.
  • Single regime variable only: Define exactly one bool variable (e.g., bullishRegime or uptrend) and use only that one variable in the entry AND condition. Ban combining two regime variables with AND (e.g., bullishRegime && regimeUp). If you need to judge across multiple axes (slope, price position, ADX), merge them into a single composite bool variable before AND-combining.

Optimization Envelope

  • Relaxable: confirmation thresholds, ATR activity threshold, session window, signal confirmation bars.
  • Not relaxable: stop-loss discipline, max one position, no martingale, no fixed historical price levels.
  • Initial optimization scope: 3-5 parameters only.
  • If no trades: loosen entry confirmation first, then session restriction, then ATR threshold.
  • If too many trades: strengthen regime filter and minimum signal distance.

Backtest Acceptance

  • Backtest at least 18 months with the latest 3 months held out.
  • Use walk-forward setting 6:2 when MT5 runner is available.
  • Reject if OOS/IS PF ratio is below 0.70 or if OOS PF min is below 1.10.
  • Reject if OOS trade count is too low; first loosen entry filters before optimizing profit targets.

Overfitting Controls

  • Keep each numeric parameter in a wide theory-backed range; do not tune to a single date range.
  • Limit optimization to 3-5 core parameters in the first pass.
  • Prefer regime filters with clear market meaning over curve-fitted thresholds.
  • Stop improving the candidate after repeated NO_TRADE/LOW_SAMPLE failures.

Learning Feedback

  • ledger: 1 prior strategy failure(s) for this DNA
  • ledger: 1 prior tick-model mismatch hit(s) for this DNA
  • ledger: improve: loosen entry confirmation or session restriction before touching exits
  • ledger: improve: prefer theory-backed ranges and freeze nonessential parameters
  • ledger: improve: reduce blocking guards such as session, spread, cooldown, or confirmation before altering signal logic
  • ledger: improve: rerun with every-tick backtest before loosening entries because bar-based tests may miss tick-sensitive triggers
  • ledger: improve: signal_candidates / entry_blocked_count 等の診断、同一バー内の矛盾、session/spread/cooldown/filter のブロックを優先確認する。
  • ledger: improve: widen active sessions or simplify filters to increase sample size
  • ledger: learned: NO_TRADEが連続する場合、期間を小刻みに変えるより入口条件・到達不能条件・ガードブロックを先に調べる。

Implementation Guardrails

  • [META] [RISK] [CONTRA] MT5 Strategy Testerは同名EAのinput値をキャッシュすることがあり、mq5側のinputデフォルトを変更して再コンパイルしても、BTでは前回値が使われる場合がある。inputデフォルト変更の検証では、別EA名/別ファイル名にするか、tester.ini/ExpertParametersで明示的に値を渡し、Testerログの「started with inputs」を必ず確認する。 (.clinerules)
  • [RISK] [META] [CONTRA] 【部分決済後のコメント管理パターン】MQL5ではPositionModifyでコメントを変更できないため、TP1部分決済後の状態管理にコメントプレフィックスを使う設計は「二重部分決済」リスクを内包する。対策として: (1)グローバルなulong配列でTP1済みチケットを管理する、(2)部分決済後に残りを即クローズ→新コメントで再エントリーする、のいずれかのパターンを採用すること。 (.clinerules)
  • [TREND] [BREAKOUT] [FILTER] [META] マルチタイムフレームEAでATR等のボラティリティ指標をCopyBufferする際、エントリー判定用の価格・MA(start_pos=1で確定足参照)とATR(start_pos=0で未確定バー参照)でstart_posが混在しやすい。設計方針として「全バッファのstart_posを統一する」か「ATRのみ最新値を使う理由をコメントで明記する」かを決めておくべき。 (.clinerules)
  • [FILTER] SYMBOL_SPREADはポイント単位のlong値を返すため、価格単位に変換するには* _Pointを直接使用する (.clinerules)
  • [FILTER] スキャルピングEAでXAUUSD等のスプレッド変動が大きい銘柄を扱う場合、pips単位ではなく価格単位(ドル)でスプレッド閾値・トレランスを指定する設計が適切。_Digits==2環境ではpips×_Pointが意図しない極小値になる (.clinerules)
  • [TREND] [FILTER] スプレッドリトライパターン(予約エントリーのスプレッド不良時リトライ): 予約フラグ方式でスプレッド不良時に即破棄せず、MAX_SPREAD_RETRY回まで次バーで再試行する設計。リトライカウンターは予約フラグと同時にリセットし、クールダウンや金曜制限等の他条件で予約破棄する際もリセットを忘れないこと。リトライの粒度(ティック単位 vs バー単位)を設計時に明確にすべき。 (.clinerules)
  • [META] HistorySelect(0, TimeCurrent()) は全取引履歴を走査対象にするため、長期運用や多数の取引がある口座ではパフォーマンスに影響する。連敗カウント等の直近履歴のみが必要な場合は、開始時刻を限定する(例: TimeCurrent() - 30243600)か、最後のチェック時刻を記録して差分走査にする。 (.clinerules)
  • [META] MQL5のOnTradeTransactionではDEAL_ENTRY_INOUTも処理対象に含めないと、ネッティング口座での約定イベントを捕捉できない場合がある (.clinerules)

Story Package

  • Hook: AI autonomously discovered "Statistical Mean Reversion" from research notes and converted it into an EA for verification.
  • Blog angle: Can a research idea truly be reproduced on MT5? We publish results all the way through to OOS decay.
  • Failure angle: Failures are classified as NO_TRADE / LOW_SAMPLE / OVERFIT / HIGH_DD and fed into the next research candidate pipeline.

Spec Validation Warnings (auto-generated)

  • CONTRADICTION: Mean-zone anchor conditions create logical impossibility for simultaneous entry. BUY requires close[1] <= sma50[1] + atr[1] * InpMeanZoneATR (price at or below upper zone boundary) AND RSI recovery from oversold rsi[1] > InpOversold && rsi[2] <= InpOversold. SELL requires close[1] >= sma50[1] - atr[1] * InpMeanZoneATR (price at or above lower zone boundary) AND RSI recovery from overbought rsi[1] < InpOverbought && rsi[2] >= InpOverbought. However, the spec explicitly states 'do not add any second regime gate such as SMA slope, ADX, BUY-above-SMA, or SELL-below-SMA' and 'The zone is intentionally permissive so RSI recovery can still fire and avoid NO_TRADE.' This creates a contradiction: if the zone is truly permissive (allowing price anywhere), then the zone condition becomes meaningless; if the zone is restrictive (price must be within bounds), then it acts as a second regime gate, violating the explicit prohibition. The practical result is that the zone condition either (1) blocks most RSI signals by requiring price proximity to SMA, or (2) is ignored entirely, leaving only RSI which may not fire frequently enough to generate trades.
  • Fix: Clarify whether the zone condition is a hard gate (in which case it IS a regime filter and the prohibition is violated) or purely informational (in which case remove it from the entry logic entirely). If zone is meant to be permissive, define a numerical threshold (e.g., 'zone width must be > 2*ATR') that allows RSI signals to fire independently. Alternatively, separate zone confirmation into a distinct bar: check zone on bar[2], RSI recovery on bar[1].
  • WARNING: RSI reentry buffer condition creates potential logical contradiction. The spec defines two BUY entry paths: (1) rsi[1] > InpOversold && rsi[2] <= InpOversold (recovery from oversold), and (2) rsi[1] > rsi[2] && rsi[2] <= InpOversold + InpRSIReentryBuffer (near-zone recovery). The second condition allows entry when RSI[2] is between InpOversold (default 35) and InpOversold+5 (default 40). However, if InpOversold is set to 35 and InpRSIReentryBuffer to 5, the second condition fires when rsi[2] is in [35, 40]. This overlaps with the first condition's requirement rsi[2] <= 35. The overlap itself is not contradictory, but the spec does not clarify whether both conditions can fire on the same bar or if they are mutually exclusive. More critically, if both conditions are evaluated as separate OR branches without proper state management, a single bar could trigger multiple entries or create ambiguity in position tracking. The spec states 'max one position per symbol' but does not specify how to handle simultaneous signal firing.
  • Fix: Define entry priority explicitly: either (1) use OR with first-match-wins logic, (2) combine into a single condition (rsi[1] > InpOversold && rsi[2] <= InpOversold) || (rsi[1] > rsi[2] && rsi[2] <= InpOversold + InpRSIReentryBuffer) with clear state tracking, or (3) separate reentry into a distinct cooldown period after the primary entry to avoid same-bar ambiguity.
  • WARNING: Exit logic contains temporal contradiction between TP and RSI midline cross. The spec states: 'Take profit: (1) price returns to N-bar SMA (default N=20), OR (2) RSI crosses back through midline (from oversold: RSI[1] > 50; from overbought: RSI[1] < 50) — whichever fires first.' For a BUY entry from oversold (RSI was < 35), the TP condition is RSI[1] > 50. However, RSI recovery from oversold typically moves RSI upward gradually (35 → 40 → 50 → ...). The condition RSI[1] > 50 will eventually fire if the trade is held long enough. But the spec also requires 'Do NOT hold mean reversion trades past session boundary' and 'Time exit: close at bar InpMaxBars (default=12).' If RSI has not yet crossed 50 by bar 12, the trade is force-closed at bar 12 without hitting the RSI TP. This is not a logical contradiction per se, but it creates a scenario where the stated TP condition (RSI > 50) may never execute because the time exit fires first. The spec does not clarify the priority order: does RSI TP take precedence over time exit, or vice versa? If time exit takes precedence, then the RSI TP condition is effectively dead code for fast-moving reversions.
  • Fix: Clarify exit priority: (1) if RSI TP is primary, set InpMaxBars high enough (e.g., 20-30 bars) to allow RSI to reach 50, or (2) if time exit is primary, remove the RSI TP condition and rely on SMA return + time exit only. Alternatively, define a 'stale reversion' threshold: if RSI has not crossed 50 by bar N, close the trade as a structural failure (as the spec hints: 'stale reversion = structural failure').
  • WARNING: The spec prohibits 'second regime gate' but the mean-zone anchor (buyZone / sellZone) functions as a price-proximity filter. If this is intentionally permissive, it should be removed from the entry logic or redefined as a non-blocking informational zone. If it is restrictive, the prohibition is violated.
  • WARNING: RSI reentry buffer overlaps with primary recovery range; state management and entry priority must be explicitly coded to avoid same-bar ambiguity.
  • WARNING: Time exit (bar 12) may fire before RSI TP condition (RSI > 50) is reached in fast reversions; exit priority and InpMaxBars tuning are critical.
  • WARNING: The spec references 'Invalidation condition: To be determined during testing' — this is incomplete. Without a defined invalidation condition, the EA may hold losing trades longer than intended.
  • WARNING: Session filter (23:00-01:30 JST) and spread filter are mentioned in Filters section but not formally defined in Entry logic; implementation must ensure these are checked before entry signal evaluation.
  • WARNING: Minimum ATR activity filter is mentioned but no threshold is specified; this is a relaxable parameter per Optimization Envelope, but the default value is missing.
  • WARNING: The spec warns against 'two regime variables AND combined' but does not explicitly list all regime variables in the code. Ensure only one rangeRegime (or equivalent) bool is used in the final AND chain.
  • WARNING: Learning Feedback mentions 'signal_candidates / entry_blocked_count' diagnostics; if entry is blocked by session/spread/cooldown guards, the EA will report NO_TRADE even if RSI signals are present. Prioritize loosening guards over changing signal logic.

免責事項

本EAは自動生成された検証用コードです。実運用可否はご自身で検証してください。

EA1000 一覧に戻る


関連用語

— SPONSORED —