Add file-prefix isolation and strict split-order parsing
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
- No standard or custom indicators are used.
|
||||
- OHLC data is retrieved with `CopyRates(_Symbol, timeframe, OHLC_START_SHIFT, HISTORY_BARS, rates)`.
|
||||
- M15 entry confirmation uses the latest closed bar, the previous closed bar, average range, candle direction, rejection shape, and distance to the candidate entry price.
|
||||
- M15 entry confirmation uses candle shape, average range, and distance to the candidate price for T2/T4. For T1/T3 it uses M15 impulse confirmation when that option is enabled.
|
||||
|
||||
## 3. Parameters
|
||||
|
||||
@@ -21,6 +21,13 @@
|
||||
- `spread_limit = 60`: Maximum allowed spread in points.
|
||||
- `magic_number = 10001`: Magic number used to identify this EA's orders and positions.
|
||||
- `initial_order = 0`: Enables initial H4/H1 processing on startup when set to `1`.
|
||||
- `input_position_limit = 10`: Practical limit for this EA's pending orders plus positions. Values above the internal `POSITION_LIMIT` are clamped.
|
||||
- `use_split_entry_zone = false`: Enables split entries based on H1 predicted zones.
|
||||
- `split_entry_count = 3`: Number of split entry orders, clamped to 1..10.
|
||||
- `split_lot_mode = SPLIT_LOT_TOTAL`: Split lot mode. `SPLIT_LOT_TOTAL` divides the total lot across slots, and `SPLIT_LOT_FIXED` uses a fixed lot per order.
|
||||
- `split_total_lot_size = 0.09`: Total lot used by total-split mode.
|
||||
- `split_fixed_lot_size = 0.01`: Per-order lot used by fixed-split mode.
|
||||
- `cancel_old_split_pending_on_new_zone = true`: Cancels older split pending orders when a new H1 zone set is loaded.
|
||||
- `use_m15_entry_filter = true`: Enables M15 closed-bar entry timing confirmation.
|
||||
- `m15_entry_zone_atr_multiplier = 1.50`: Allowed proximity multiplier based on the M15 average range.
|
||||
- `use_m15_imbalance_confirmation = true`: Adds M15 impulse confirmation for T1/T3 trend-following candidates.
|
||||
@@ -28,15 +35,15 @@
|
||||
- `m15_imbalance_sensitivity = 2.0`: Required multiple of the average body for M15 impulse confirmation.
|
||||
- `m15_imbalance_min_avg_body_points = 1.0`: Minimum M15 average body in points.
|
||||
- `use_m15_imbalance_debug_log = false`: Enables detailed M15 impulse-confirmation logs.
|
||||
- `input_entry_max_candidate_age_minutes = 45`: Maximum age, in minutes, for using an H1 candidate for new execution. This blocks delayed entries when M15 confirmation appears too late.
|
||||
- `input_entry_max_candidate_age_minutes = 120`: Maximum age, in minutes, for using an H1 candidate for new execution. This blocks delayed entries when M15 confirmation appears too late.
|
||||
- `input_sltp_manager_enabled = false`: Enables UI-driven existing-position SL management through `CSLTPManager`.
|
||||
- `input_sltp_show_panel = true`: Shows the SLTP control panel on the chart.
|
||||
- `input_sltp_use_breakeven = false`: Enables normal break-even.
|
||||
- `input_sltp_breakeven_trigger_pips = 30.0`: Profit threshold for normal break-even.
|
||||
- `input_sltp_breakeven_buffer_pips = 0.0`: Profit-side entry buffer used by normal break-even.
|
||||
- `input_sltp_breakeven_buffer_pips = 3.0`: Profit-side entry buffer used by normal break-even.
|
||||
- `input_sltp_use_elapsed_breakeven = false`: Enables elapsed-time break-even.
|
||||
- `input_sltp_elapsed_breakeven_hours = 4.0`: Holding time required before elapsed-time break-even is allowed.
|
||||
- `input_sltp_elapsed_breakeven_buffer_pips = 0.0`: Profit-side entry buffer used by elapsed-time break-even.
|
||||
- `input_sltp_elapsed_breakeven_buffer_pips = 3.0`: Profit-side entry buffer used by elapsed-time break-even.
|
||||
- `input_sltp_use_active_trailing = false`: Enables active step trailing.
|
||||
- `input_sltp_active_breakeven_pips = 30.0`: Profit threshold that starts active trailing.
|
||||
- `input_sltp_active_stop_loss_offset_pips = 5.0`: Initial locked profit offset from entry.
|
||||
@@ -50,7 +57,7 @@
|
||||
### Main Constants
|
||||
|
||||
- `POSITION_LIMIT = 48`: Maximum number of this EA's pending orders plus positions.
|
||||
- `ENTRY_H1_LIMIT = 1`: Pending-order lifetime in H1 bars.
|
||||
- `ENTRY_H1_LIMIT = 2`: Pending-order lifetime in H1 bars.
|
||||
- `CLOSE_H1_LIMIT = 12`: Position lifetime in H1 bars.
|
||||
- `HISTORY_BARS = 72`: Number of OHLC bars exported to Python.
|
||||
- `OHLC_START_SHIFT = 1`: Shift used to export closed bars only.
|
||||
@@ -58,41 +65,46 @@
|
||||
- `ENTRY_RETRY_SECONDS = 60`: Retry interval for entry checks.
|
||||
- `ENTRY_RETRY_LIMIT = 10`: Maximum retry count for one H1 candidate set.
|
||||
- `TARGET_SIZE = 13`: Number of numeric values expected in `target_prices.txt`.
|
||||
- `TARGET_ZONE_SCHEMA_VERSION = 2`: Schema version used by `target_zones.txt`.
|
||||
- `PYTHON_TIMEOUT_SECONDS = 600`: External Python wait threshold.
|
||||
|
||||
### Python Entry-Candidate Guard
|
||||
|
||||
- After H1 candidate generation, Python invalidates any `entry` that is too far from the current price.
|
||||
- The maximum distance is `max(H1 EATR * 0.65, 5.00)`. A strategy beyond that limit is rewritten to `0.00,0.00,0.00`.
|
||||
- The maximum distance is strategy-specific: T1/T3 Stop candidates use `max(H1 EATR * 1.50, 5.00)`, and T2/T4 Limit candidates use `max(H1 EATR * 1.00, 5.00)`. A strategy beyond its limit is rewritten to `0.00,0.00,0.00`.
|
||||
- This post-filter is intended to reduce delayed entries from deep limit orders or distant breakout waits after M15 confirmation arrives late.
|
||||
|
||||
## 4. File Layout
|
||||
|
||||
- `Experts/MyProject/HIT-EA_refactor_ver5.mq5`: EA entry point. Keeps `OnInit`, `OnDeinit`, `OnTick`, inputs, global state, and DLL imports.
|
||||
- `Experts/MyProject/HIT-EA_refactor_ver6.mq5`: EA entry point. Keeps `OnInit`, `OnDeinit`, `OnTick`, inputs, global state, and DLL imports.
|
||||
- `Include/MyLib/Common/HITRuntimeController.mqh`: Tick flow, H4/H1/M15 update control, status comments, and spread checks.
|
||||
- `Include/MyLib/Signals/HITEntrySignal.mqh`: Entry preconditions, order-type price validation, M15 filter, and retry-state updates.
|
||||
- `Include/MyLib/Common/HITExternalProcess.mqh`: done/running files, external process handles, PID recovery, exit-code checks, and timeout recovery.
|
||||
- `Include/MyLib/Signals/HITPythonSignalGateway.mqh`: OHLC CSV export, Python batch launch, and `trend_state.txt` / `target_prices.txt` loading.
|
||||
- `Include/MyLib/Signals/HITPythonSignalGateway.mqh`: OHLC CSV export, Python batch launch, and `trend_state.txt` / `target_prices.txt` / `target_zones.txt` loading.
|
||||
- `Include/MyLib/Trading/HITTradeManager.mqh`: Order sending, filling policy, pending-order expiration, order/position counting, expired order cancellation, and expired position closing.
|
||||
- `Include/MyLib/Trading/SLTPManager.mqh`: Existing-position break-even, elapsed-time break-even, active trailing, TP-progress SL, and high-volatility SL management.
|
||||
- `Include/MyLib/Panel/SLTPManagerPanel.mqh`: Chart panel that toggles `CSLTPManager` features, validates numeric inputs, and applies settings to the EA.
|
||||
|
||||
## 5. Python Integration Files
|
||||
|
||||
During `OnInit()`, the EA builds a `HIT_<sanitized symbol>_<magic_number>` prefix from `_Symbol` and `magic_number`, then applies it to all MT5 `Files` linkage names. Example: `HIT_GOLD_10001_ohlc_H4.csv`. The same prefix is passed to the batch file as the first argument, and the batch file exposes it to Python as `MT5_EA_FILE_PREFIX`.
|
||||
|
||||
When no prefix is provided, such as manual Python execution, Python keeps using the legacy names like `ohlc_H4.csv`.
|
||||
|
||||
### H4 Trend Analysis
|
||||
|
||||
- MQL5 output: `ohlc_H4.csv`
|
||||
- Python output: `trend_state.txt`
|
||||
- Done marker: `process_done_trend.txt`
|
||||
- Running marker: `process_running_trend.txt`
|
||||
- MQL5 output: `<prefix>_ohlc_H4.csv`
|
||||
- Python output: `<prefix>_trend_state.txt`
|
||||
- Done marker: `<prefix>_process_done_trend.txt`
|
||||
- Running marker: `<prefix>_process_running_trend.txt`
|
||||
- Batch file: `<TerminalDataPath>\MQL5\python_for_ea\bat\get_trend_reply.bat`
|
||||
|
||||
### H1 Entry Candidate Generation
|
||||
|
||||
- MQL5 output: `ohlc_H1.csv`
|
||||
- Python output: `target_prices.txt`
|
||||
- Done marker: `process_done_entry.txt`
|
||||
- Running marker: `process_running_entry.txt`
|
||||
- MQL5 output: `<prefix>_ohlc_H1.csv`
|
||||
- Python output: `<prefix>_target_prices.txt`, `<prefix>_target_zones.txt`
|
||||
- Done marker: `<prefix>_process_done_entry.txt`
|
||||
- Running marker: `<prefix>_process_running_entry.txt`
|
||||
- Batch file: `<TerminalDataPath>\MQL5\python_for_ea\bat\get_entry_reply.bat`
|
||||
|
||||
During `OnInit()`, the EA resolves `MQL5\python_for_ea` from `TerminalInfoString(TERMINAL_DATA_PATH)` and builds absolute batch-file paths. Each batch file resolves the Python project root from its own location, so runtime execution no longer depends on `C:\ea_py`.
|
||||
@@ -107,6 +119,20 @@ Lines 8-10: T3 Sell Stop entry/tp/sl
|
||||
Lines 11-13: T4 Sell Limit entry/tp/sl
|
||||
```
|
||||
|
||||
`target_zones.txt` must contain 7 lines for split entries:
|
||||
|
||||
```text
|
||||
Line 1: schema_version (2)
|
||||
Line 2: res_chk
|
||||
Line 3: candidate_id derived from the closed H1 bar time
|
||||
Line 4: T1 Buy Stop strategy, zone_low, zone_high, tp, sl
|
||||
Line 5: T2 Buy Limit strategy, zone_low, zone_high, tp, sl
|
||||
Line 6: T3 Sell Stop strategy, zone_low, zone_high, tp, sl
|
||||
Line 7: T4 Sell Limit strategy, zone_low, zone_high, tp, sl
|
||||
```
|
||||
|
||||
Python creates `process_done_entry.txt` only after both `target_prices.txt` and `target_zones.txt` have been written. When split entries are disabled, the EA keeps using the legacy 13-line `target_prices.txt` path.
|
||||
|
||||
## 6. Entry Conditions
|
||||
|
||||
New entries are allowed only when all conditions below are satisfied:
|
||||
@@ -120,8 +146,9 @@ New entries are allowed only when all conditions below are satisfied:
|
||||
- The selected order type has valid `entry/tp/sl` values greater than `0.0`.
|
||||
- The order type is allowed by the H4 `market_state`.
|
||||
- The order-type price relationship and broker minimum distance rules are satisfied.
|
||||
- When `use_m15_entry_filter = true`, the M15 closed-bar timing confirmation is satisfied.
|
||||
- This EA's pending orders plus positions are below `POSITION_LIMIT`.
|
||||
- When `use_m15_entry_filter = true`, T2/T4 satisfy the M15 direction, rejection, and proximity checks. T1/T3 satisfy M15 impulse confirmation when `use_m15_imbalance_confirmation = true`.
|
||||
- This EA's pending orders plus positions are below `input_position_limit`.
|
||||
- When split entries are enabled, `target_zones.txt` has `res_chk = 1`, the predicted zone prices are valid, split lots fit `SYMBOL_VOLUME_MIN/MAX/STEP`, and no duplicate order or position exists for the same `candidate_id` + slot.
|
||||
|
||||
### market_state and Allowed Order Types
|
||||
|
||||
@@ -131,7 +158,7 @@ New entries are allowed only when all conditions below are satisfied:
|
||||
- `3 MARKET_HIGH_VOL_UP`: Allows T1 Buy Stop / T2 Buy Limit.
|
||||
- `4 MARKET_LOW_VOL_DOWN`: Allows T3 Sell Stop / T4 Sell Limit.
|
||||
- `5 MARKET_HIGH_VOL_DOWN`: Allows T3 Sell Stop / T4 Sell Limit.
|
||||
- `6 MARKET_ABNORMAL_VOL_STOP`: Blocks new entries.
|
||||
- `6 MARKET_TECHNICAL_ERROR_STOP`: Blocks new entries.
|
||||
|
||||
### Order-Type Price Rules
|
||||
|
||||
@@ -161,32 +188,50 @@ New entries are allowed only when all conditions below are satisfied:
|
||||
## 8. Risk Management
|
||||
|
||||
- Managed orders and positions are limited to matching `_Symbol` and `magic_number`.
|
||||
- `POSITION_LIMIT` counts only this EA's orders and positions, not the full account.
|
||||
- `input_position_limit` counts only this EA's orders and positions, not the full account. The hard internal limit is `POSITION_LIMIT`.
|
||||
- The EA selects the filling policy from `SYMBOL_FILLING_MODE`, preferring IOC, then FOK, then RETURN.
|
||||
- Pending orders receive server-side expiration when the broker supports it.
|
||||
- `OrderSend` return values and `MqlTradeResult.retcode` are checked. Failures are logged with `GetLastError()` or the retcode.
|
||||
- Split-entry order comments include `candidate_id` and slot number to prevent duplicate slot execution.
|
||||
- When `cancel_old_split_pending_on_new_zone = true`, a new valid `candidate_id` cancels older split pending orders, and an invalid or stopped `target_zones.txt` cancels all existing split pending orders for this EA/symbol/magic.
|
||||
- SLTP management only targets existing positions matching `_Symbol` and `magic_number`, and it preserves each position's current TP.
|
||||
- SL changes are sent only when the candidate improves protection relative to the current SL and satisfies broker stop-level and freeze-level constraints.
|
||||
|
||||
## 9. Error Handling
|
||||
|
||||
- If `trend_state.txt` is missing, unreadable, or outside `0..6`, the EA uses `MARKET_ABNORMAL_VOL_STOP`.
|
||||
- If `target_prices.txt` is missing, unreadable, or shorter than 13 lines, the EA uses `res_chk = 0`.
|
||||
- If `trend_state.txt` is missing, unreadable, not strictly parseable as an integer, or outside `0..6`, the EA uses `MARKET_TECHNICAL_ERROR_STOP`.
|
||||
- If `target_prices.txt` is missing, unreadable, shorter than 13 lines, or contains a non-strict numeric line, the EA uses `res_chk = 0`.
|
||||
- When split entries are enabled, missing `target_zones.txt`, schema mismatch, fewer than 7 lines, `res_chk != 1`, or non-strict numeric values stop new split orders.
|
||||
- If a Python process exits with a non-zero code, the code is logged and the next trigger may retry.
|
||||
- If only a stale running marker remains, the EA attempts PID recovery. If recovery fails and the marker is timed out, it removes the stale marker.
|
||||
|
||||
## 10. Changelog
|
||||
|
||||
### 2026-05-30
|
||||
|
||||
- Added the `HIT_<symbol>_<magic_number>` linkage-file prefix contract on both the MT5 and Python sides to avoid collisions across multiple EAs or symbols in the same terminal.
|
||||
- Updated T1/T3 trend-following candidates so `use_m15_imbalance_confirmation = true` requires M15 impulse confirmation.
|
||||
- Added strict numeric parsing requirements for `trend_state.txt`, `target_prices.txt`, and `target_zones.txt`, with invalid content handled as a safe stop state.
|
||||
- Added stale split-pending cancellation behavior when `target_zones.txt` is invalid or stopped.
|
||||
- Synchronized current defaults for `input_entry_max_candidate_age_minutes`, `ENTRY_H1_LIMIT`, SLTP buffers, and the Python entry-distance guard.
|
||||
|
||||
### 2026-05-27
|
||||
|
||||
- Moved the Python helper application specification from `C:\ea_py` to `MQL5\python_for_ea` under the MT5 data folder.
|
||||
- Updated the EA startup path model so batch paths are built from `TerminalInfoString(TERMINAL_DATA_PATH)`, and the external process working directory is derived from the batch-file location.
|
||||
- Updated Python path discovery so the default MT5 linkage is the adjacent `MQL5\Files` directory, with `MT5_FILES_DIR` or `MT5_DATA_PATH` available for explicit overrides.
|
||||
|
||||
### 2026-05-24
|
||||
|
||||
- Added Python-side `target_zones.txt` output and made `process_done_entry.txt` appear only after both `target_prices.txt` and `target_zones.txt` are written.
|
||||
- Added `use_split_entry_zone`, `split_entry_count`, `split_lot_mode`, `split_total_lot_size`, `split_fixed_lot_size`, and `input_position_limit`.
|
||||
- Added split-zone pending order placement with total-lot or fixed-lot sizing.
|
||||
- Added `candidate_id` + slot identification to prevent duplicate split orders.
|
||||
|
||||
### 2026-05-13
|
||||
|
||||
- Added a Python-side H1 EATR distance guard that invalidates candidates farther than `max(H1 EATR * 0.65, 5.00)` from the current price before they are passed to MT5.
|
||||
- Added `input_entry_max_candidate_age_minutes = 45` on the EA side so stale H1 candidates are not executed when M15 confirmation arrives late.
|
||||
- Added a Python-side H1 EATR distance guard that invalidates candidates too far from the current price before they are passed to MT5.
|
||||
- Added `input_entry_max_candidate_age_minutes` on the EA side so stale H1 candidates are not executed when M15 confirmation arrives late.
|
||||
- Added H1 candidate age to entry skip logs to make delayed entries, M15 rejection, and price mismatch easier to diagnose.
|
||||
|
||||
### 2026-05-05
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
- 標準インジケータおよびカスタムインジケータは未使用。
|
||||
- OHLCは `CopyRates(_Symbol, timeframe, OHLC_START_SHIFT, HISTORY_BARS, rates)` で取得する。
|
||||
- M15エントリー確認は、直近確定足と1本前の確定足のローソク足形状、平均レンジ、候補価格との距離から判定する。
|
||||
- M15エントリー確認は、T2/T4では直近確定足と1本前の確定足のローソク足形状、平均レンジ、候補価格との距離から判定し、T1/T3では必要に応じてM15初動確認を行う。
|
||||
|
||||
## 3. パラメータ設定
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
- `m15_imbalance_sensitivity = 2.0`: M15初動確認で現在足実体が平均実体を上回る必要倍率。
|
||||
- `m15_imbalance_min_avg_body_points = 1.0`: M15平均実体の最小値(point)。
|
||||
- `use_m15_imbalance_debug_log = false`: M15初動確認の詳細ログを出すか。
|
||||
- `input_entry_max_candidate_age_minutes = 45`: H1候補価格を新規発注に使用できる最大経過分数。古い候補でM15条件が後から整った場合の遅延エントリーを抑止する。
|
||||
- `input_entry_max_candidate_age_minutes = 120`: H1候補価格を新規発注に使用できる最大経過分数。古い候補でM15条件が後から整った場合の遅延エントリーを抑止する。
|
||||
- `input_position_limit = 10`: 自EAの未約定注文 + ポジション数の実運用上限。内部上限 `POSITION_LIMIT` を超える指定は丸める。
|
||||
- `use_split_entry_zone = false`: H1予測ゾーンを使った分割エントリーを有効化するか。
|
||||
- `split_entry_count = 3`: 分割エントリー本数。1〜10に丸めて使用する。
|
||||
@@ -40,10 +40,10 @@
|
||||
- `input_sltp_show_panel = true`: チャート上にSLTP操作パネルを表示するか。
|
||||
- `input_sltp_use_breakeven = false`: 通常ブレークイーブンを有効化するか。
|
||||
- `input_sltp_breakeven_trigger_pips = 30.0`: 通常ブレークイーブンを開始する含み益pips。
|
||||
- `input_sltp_breakeven_buffer_pips = 0.0`: 通常ブレークイーブン時に建値から利益方向へずらすpips。
|
||||
- `input_sltp_breakeven_buffer_pips = 3.0`: 通常ブレークイーブン時に建値から利益方向へずらすpips。
|
||||
- `input_sltp_use_elapsed_breakeven = false`: 保有時間ベースのブレークイーブンを有効化するか。
|
||||
- `input_sltp_elapsed_breakeven_hours = 4.0`: 保有時間ベースのブレークイーブンを許可するまでの保有時間。
|
||||
- `input_sltp_elapsed_breakeven_buffer_pips = 0.0`: 保有時間ベースのブレークイーブン時に建値から利益方向へずらすpips。
|
||||
- `input_sltp_elapsed_breakeven_buffer_pips = 3.0`: 保有時間ベースのブレークイーブン時に建値から利益方向へずらすpips。
|
||||
- `input_sltp_use_active_trailing = false`: アクティブトレーリングを有効化するか。
|
||||
- `input_sltp_active_breakeven_pips = 30.0`: アクティブトレーリング開始pips。
|
||||
- `input_sltp_active_stop_loss_offset_pips = 5.0`: 開始時に建値から固定する利益pips。
|
||||
@@ -57,7 +57,7 @@
|
||||
### 主要定数
|
||||
|
||||
- `POSITION_LIMIT = 48`: 自EAの未約定注文 + ポジション数の上限。
|
||||
- `ENTRY_H1_LIMIT = 1`: 未約定注文の有効期限(H1本数)。
|
||||
- `ENTRY_H1_LIMIT = 2`: 未約定注文の有効期限(H1本数)。
|
||||
- `CLOSE_H1_LIMIT = 12`: ポジションの時間制限クローズ(H1本数)。
|
||||
- `HISTORY_BARS = 72`: Pythonへ渡すOHLC本数。
|
||||
- `OHLC_START_SHIFT = 1`: 確定足からOHLCを取得するためのシフト。
|
||||
@@ -71,7 +71,7 @@
|
||||
### Python側エントリー候補ガード
|
||||
|
||||
- H1候補価格生成後、Python側で現在価格から遠すぎる `entry` を無効化する。
|
||||
- 距離上限は `max(H1 EATR * 0.65, 5.00)` とし、上限を超えた戦略は `0.00,0.00,0.00` に補正する。
|
||||
- 距離上限は戦略別に計算し、T1/T3のStop系は `max(H1 EATR * 1.50, 5.00)`、T2/T4のLimit系は `max(H1 EATR * 1.00, 5.00)` とする。上限を超えた戦略は `0.00,0.00,0.00` に補正する。
|
||||
- このガードは、深い指値や遠いブレイク待ちがM15確認後に遅れて発注されることを抑えるための後処理である。
|
||||
|
||||
## 4. ファイル構成
|
||||
@@ -87,20 +87,24 @@
|
||||
|
||||
## 5. Python連携ファイル
|
||||
|
||||
EAは `OnInit()` で `_Symbol` と `magic_number` から `HIT_<sanitized symbol>_<magic_number>` 形式の接頭辞を作り、MT5 `Files` 配下の連携ファイル名へ付与する。例: `HIT_GOLD_10001_ohlc_H4.csv`。batには同じ接頭辞を第1引数で渡し、bat側が `MT5_EA_FILE_PREFIX` としてPythonへ引き継ぐ。
|
||||
|
||||
手動実行などで接頭辞が指定されない場合、Pythonは従来どおり `ohlc_H4.csv` などの旧ファイル名を使う。
|
||||
|
||||
### H4トレンド判定
|
||||
|
||||
- MQL5出力: `ohlc_H4.csv`
|
||||
- Python出力: `trend_state.txt`
|
||||
- 完了フラグ: `process_done_trend.txt`
|
||||
- 実行中フラグ: `process_running_trend.txt`
|
||||
- MQL5出力: `<prefix>_ohlc_H4.csv`
|
||||
- Python出力: `<prefix>_trend_state.txt`
|
||||
- 完了フラグ: `<prefix>_process_done_trend.txt`
|
||||
- 実行中フラグ: `<prefix>_process_running_trend.txt`
|
||||
- 起動バッチ: `<TerminalDataPath>\MQL5\python_for_ea\bat\get_trend_reply.bat`
|
||||
|
||||
### H1エントリー価格生成
|
||||
|
||||
- MQL5出力: `ohlc_H1.csv`
|
||||
- Python出力: `target_prices.txt`, `target_zones.txt`
|
||||
- 完了フラグ: `process_done_entry.txt`
|
||||
- 実行中フラグ: `process_running_entry.txt`
|
||||
- MQL5出力: `<prefix>_ohlc_H1.csv`
|
||||
- Python出力: `<prefix>_target_prices.txt`, `<prefix>_target_zones.txt`
|
||||
- 完了フラグ: `<prefix>_process_done_entry.txt`
|
||||
- 実行中フラグ: `<prefix>_process_running_entry.txt`
|
||||
- 起動バッチ: `<TerminalDataPath>\MQL5\python_for_ea\bat\get_entry_reply.bat`
|
||||
|
||||
EAは `OnInit()` で `TerminalInfoString(TERMINAL_DATA_PATH)` から `MQL5\python_for_ea` を解決し、各batファイルの絶対パスを組み立てる。batファイルは自身の位置からPythonプロジェクトルートを解決するため、`C:\ea_py` には依存しない。
|
||||
@@ -142,7 +146,7 @@ Pythonは `target_prices.txt` と `target_zones.txt` の両方を書き終えて
|
||||
- 対象注文タイプの `entry/tp/sl` がすべて `0.0` より大きい。
|
||||
- H4 `market_state` に対して注文タイプが許可されている。
|
||||
- 注文タイプごとの価格整合条件とブローカー最小距離制約を満たす。
|
||||
- `use_m15_entry_filter = true` の場合、M15確定足の方向・反発・接近条件を満たす。
|
||||
- `use_m15_entry_filter = true` の場合、T2/T4はM15確定足の方向・反発・接近条件を満たす。T1/T3は `use_m15_imbalance_confirmation = true` の場合にM15初動確認を満たす。
|
||||
- 自EAの注文 + ポジション数が `input_position_limit` 未満。
|
||||
- 分割エントリー有効時は `target_zones.txt` の `res_chk = 1`、予測ゾーンの価格整合、分割ロットの `SYMBOL_VOLUME_MIN/MAX/STEP` 適合、同一 `candidate_id` + slot の重複注文/ポジション不存在を満たす。
|
||||
|
||||
@@ -154,7 +158,7 @@ Pythonは `target_prices.txt` と `target_zones.txt` の両方を書き終えて
|
||||
- `3 MARKET_HIGH_VOL_UP`: T1 Buy Stop / T2 Buy Limit を許可。
|
||||
- `4 MARKET_LOW_VOL_DOWN`: T3 Sell Stop / T4 Sell Limit を許可。
|
||||
- `5 MARKET_HIGH_VOL_DOWN`: T3 Sell Stop / T4 Sell Limit を許可。
|
||||
- `6 MARKET_ABNORMAL_VOL_STOP`: 新規注文を停止。
|
||||
- `6 MARKET_TECHNICAL_ERROR_STOP`: 新規注文を停止。
|
||||
|
||||
### 注文タイプごとの価格整合条件
|
||||
|
||||
@@ -189,19 +193,28 @@ Pythonは `target_prices.txt` と `target_zones.txt` の両方を書き終えて
|
||||
- ペンディング注文には、ブローカーが対応する場合にサーバー側の期限を設定する。
|
||||
- `OrderSend` の戻り値と `MqlTradeResult.retcode` を確認し、失敗時は `GetLastError()` またはretcodeをログへ出力する。
|
||||
- 分割エントリーの注文コメントには `candidate_id` とslot番号を入れ、同一slotの二重発注を抑止する。
|
||||
- `cancel_old_split_pending_on_new_zone = true` の場合、新しい有効 `candidate_id` を読んだ時は旧candidateの分割pending注文を取消し、`target_zones.txt` が無効または停止値の場合は既存の分割pending注文をすべて取消する。
|
||||
- SLTP管理は `_Symbol` と `magic_number` が一致する既存ポジションのみを対象とし、TPは既存値を維持する。
|
||||
- SL変更は既存SLより利益保護方向へ改善する場合だけ実行し、ブローカーのstop level / freeze levelを満たさない候補は送信しない。
|
||||
|
||||
## 9. 異常系の扱い
|
||||
|
||||
- `trend_state.txt` が存在しない、読み込めない、または `0..6` 以外の場合は `MARKET_ABNORMAL_VOL_STOP` として扱う。
|
||||
- `target_prices.txt` が存在しない、読み込めない、または13行未満の場合は `res_chk = 0` として扱う。
|
||||
- 分割エントリー有効時に `target_zones.txt` が存在しない、schema不一致、7行未満、または `res_chk != 1` の場合は新規注文を停止する。
|
||||
- `trend_state.txt` が存在しない、読み込めない、整数として厳格にパースできない、または `0..6` 以外の場合は `MARKET_TECHNICAL_ERROR_STOP` として扱う。
|
||||
- `target_prices.txt` が存在しない、読み込めない、13行未満、またはいずれかの行が数値として厳格にパースできない場合は `res_chk = 0` として扱う。
|
||||
- 分割エントリー有効時に `target_zones.txt` が存在しない、schema不一致、7行未満、`res_chk != 1`、またはいずれかの数値行を厳格にパースできない場合は新規注文を停止する。
|
||||
- Pythonプロセスが異常終了した場合、終了コードをログへ出力し、次回トリガーで再実行できる状態に戻す。
|
||||
- `running` ファイルだけが残っている場合は、PIDからプロセス復元を試みる。復元できずタイムアウト済みなら古いマーカーとして削除する。
|
||||
|
||||
## 10. 変更履歴
|
||||
|
||||
### 2026-05-30
|
||||
|
||||
- 同一Terminal内の複数EA/複数シンボルでPython連携ファイルが衝突しないよう、`HIT_<symbol>_<magic_number>` 接頭辞をMT5/Python双方のファイル名へ適用する仕様に更新した。
|
||||
- T1/T3の順張り候補でも `use_m15_imbalance_confirmation = true` の場合はM15初動確認を必須とする仕様に更新した。
|
||||
- `trend_state.txt`、`target_prices.txt`、`target_zones.txt` の数値読込を厳格化し、不正値は安全側の停止値として扱う仕様を追加した。
|
||||
- `target_zones.txt` が無効または停止値の場合に、古い分割pending注文を全取消できる仕様を追加した。
|
||||
- 現行コードに合わせて、`input_entry_max_candidate_age_minutes`、`ENTRY_H1_LIMIT`、SLTPバッファ、Python側距離ガードの既定値を修正した。
|
||||
|
||||
### 2026-05-27
|
||||
|
||||
- Python補助アプリの配置を `C:\ea_py` からMT5データフォルダ配下の `MQL5\python_for_ea` へ移行する仕様に変更した。
|
||||
@@ -217,8 +230,8 @@ Pythonは `target_prices.txt` と `target_zones.txt` の両方を書き終えて
|
||||
|
||||
### 2026-05-13
|
||||
|
||||
- Python側にH1 EATRベースの候補距離ガードを追加し、現在価格から `max(H1 EATR * 0.65, 5.00)` を超える候補をMT5へ渡す前に無効化する仕様を追加。
|
||||
- EA側に `input_entry_max_candidate_age_minutes = 45` を追加し、M15確認が遅れて整った古いH1候補で新規発注しないようにした。
|
||||
- Python側にH1 EATRベースの候補距離ガードを追加し、現在価格から遠すぎる候補をMT5へ渡す前に無効化する仕様を追加。
|
||||
- EA側に `input_entry_max_candidate_age_minutes` を追加し、M15確認が遅れて整った古いH1候補で新規発注しないようにした。
|
||||
- エントリー見送りログへH1候補の経過秒数を追加し、遅延・M15未確認・価格不整合の原因を追跡しやすくした。
|
||||
|
||||
### 2026-05-05
|
||||
|
||||
Reference in New Issue
Block a user