From 7f68c868464e3c81f278cdab772ff9a73335a397 Mon Sep 17 00:00:00 2001 From: Bell Date: Sun, 17 May 2026 23:23:44 +0700 Subject: [PATCH] Readme and Comments --- Experts/HyperICT.mq5 | 23 ++- Experts/HyperICT_compile.log | Bin 8848 -> 8850 bytes Include/HyperICT/Classifier.mqh | 19 +- Include/HyperICT/Config.mqh | 27 ++- Include/HyperICT/Draw.mqh | 13 +- Include/HyperICT/FibValidator.mqh | 12 +- Include/HyperICT/KeyLevels.mqh | 18 +- Include/HyperICT/Panel.mqh | 6 +- Include/HyperICT/README.md | 311 ++++++++++++++++++++++++++++++ Include/HyperICT/StateMachine.mqh | 17 +- Include/HyperICT/SwingEngine.mqh | 21 +- Include/HyperICT/Types.mqh | 47 +++-- Include/HyperICT/UpdateEngine.mqh | 20 +- Profiles/Charts/Default/order.wnd | Bin 106 -> 366 bytes 14 files changed, 487 insertions(+), 47 deletions(-) create mode 100644 Include/HyperICT/README.md diff --git a/Experts/HyperICT.mq5 b/Experts/HyperICT.mq5 index 59958d4..cde8bcf 100644 --- a/Experts/HyperICT.mq5 +++ b/Experts/HyperICT.mq5 @@ -1,6 +1,20 @@ //+------------------------------------------------------------------+ //| HyperICT.mq5 | -//| HTF structure: swings, Key LV, CHoCH / Continue (modular) | +//| EA đọc cấu trúc HTF — không giao dịch | +//| Docs: Include/HyperICT/README.md | +//| Mở folder workspace: .../MQL5 (không mở riêng Include/HyperICT)| +//+------------------------------------------------------------------+ +//| MAP SPEC → MODULE: | +//| § tiên quyết Fib + HH-HL → FibValidator, SwingEngine | +//| §1.1 trạng thái trend → Classifier, Panel | +//| §1.2 Key LV + OB → KeyLevels, Draw | +//| §1.3 vẽ label/rect → Draw | +//| §1.4 CHoCH/Continue → UpdateEngine, SwingEngine roll | +//| Pipeline → StateMachine | +//| Input HTF/swing/fib → Config | +//| Kiểu dữ liệu → Types | +//| | +//| CHƯA CÓ TRONG DỰ ÁN: đặt lệnh, LTF, session, alert | //+------------------------------------------------------------------+ #property copyright "HyperICT" #property version "0.11" @@ -14,6 +28,8 @@ HtfContext g_ctx; +//+------------------------------------------------------------------+ +//| Khóa snapshot swing HTF + vẽ lần đầu | //+------------------------------------------------------------------+ int OnInit() { @@ -41,6 +57,9 @@ void OnDeinit(const int reason) ChartRedraw(); } +//+------------------------------------------------------------------+ +//| Mỗi tick: logic HTF chỉ trên nến HTF mới (StateMachine) | +//| Vẽ rectangle kéo dài mỗi tick | //+------------------------------------------------------------------+ void OnTick() { @@ -49,6 +68,8 @@ void OnTick() CPanel::Render(g_ctx); } +//+------------------------------------------------------------------+ +//| API cho EA/script khác đọc state | //+------------------------------------------------------------------+ ENUM_HTF_STATE HyperICT_GetState() { return g_ctx.state; } diff --git a/Experts/HyperICT_compile.log b/Experts/HyperICT_compile.log index 6d25b152952bde0168bdfdac09b774f5109ced89..c1c57a439f8a616a82a3d7379d4b37cb2b49c079 100644 GIT binary patch delta 22 dcmbQ>I>~iIlsK~?gT>}(@sC`LW|MuDoB>po2G#%o delta 20 bcmbQ_I>B{AlsKc==2-EMT#N>j{gs>nOcMs5 diff --git a/Include/HyperICT/Classifier.mqh b/Include/HyperICT/Classifier.mqh index ebacfdc..52e145a 100644 --- a/Include/HyperICT/Classifier.mqh +++ b/Include/HyperICT/Classifier.mqh @@ -1,5 +1,16 @@ //+------------------------------------------------------------------+ -//| Classifier.mqh — 7+ trạng thái §1.1 (bar đóng shift 1) | +//| Classifier.mqh | +//| Phân loại trạng thái HTF §1.1 (bar HTF đóng, shift 1) | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • Bull Pullback: Fib OK + giá (mid body) giữa L0–H0 | +//| • Bull CHoCH: body phá dưới L0 HOẶC đang update.phase CHoCH | +//| • Bull Continue: body phá trên H0 HOẶC đang update Continue | +//| • Bear: đối xứng (phá H0 / phá L0) | +//| • Neutral: không đủ 4 swing hoặc cấu trúc không HH-HL/LH-LL | +//| • Fib fail → BULL/BEAR_INCOMPLETE (sóng chưa kết thúc) | +//| ƯU TIÊN: nếu đang §1.4 update → hiển thị CHoCH/Continue trước | +//| CHƯA: phân tầng ưu tiên phức tạp khi nhiều tín hiệu cùng bar | //+------------------------------------------------------------------+ #ifndef HYPERICT_CLASSIFIER_MQH #define HYPERICT_CLASSIFIER_MQH @@ -9,7 +20,6 @@ #include #include -//+------------------------------------------------------------------+ class CClassifier { public: @@ -21,10 +31,11 @@ public: if(ctx.structBias == STRUCT_NONE) return HTF_NEUTRAL; - const int sh = 1; + const int sh = 1; // bar HTF vừa đóng const double bodyMid = (iClose(ctx.symbol, ctx.htf, sh) + iOpen(ctx.symbol, ctx.htf, sh)) * 0.5; + //--- Đang trong §1.4 → state CHoCH / Continue theo event if(ctx.update.phase != UPD_PHASE_IDLE) { if(ctx.structBias == STRUCT_BULL) @@ -43,6 +54,7 @@ public: } } + //--- § tiên quyết Fib: fail ≠ Neutral if(!ctx.fibOk) { if(ctx.structBias == STRUCT_BULL) @@ -51,6 +63,7 @@ public: return HTF_BEAR_INCOMPLETE; } + //--- §1.1 trạng thái khi snapshot idle (chưa hoặc đã xong update) if(ctx.structBias == STRUCT_BULL) { if(CKeyLevels::BodyBreakBelow(ctx.symbol, ctx.htf, sh, ctx.keyLv1.price)) diff --git a/Include/HyperICT/Config.mqh b/Include/HyperICT/Config.mqh index 3bbc840..3f28407 100644 --- a/Include/HyperICT/Config.mqh +++ b/Include/HyperICT/Config.mqh @@ -1,5 +1,14 @@ //+------------------------------------------------------------------+ -//| Config.mqh — inputs & hằng số | +//| Config.mqh | +//| Tham số input map spec → runtime | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • InpHtf = H1 mặc định (§ HTF trend) | +//| • InpSwingRange — pivot §1.4 P2 & xác nhận đỉnh/đáy sau phá Key | +//| • InpFibMinRatio = 0.382 — chỉ tiên quyết trend (§ đầu) | +//| • InpSwingLookback — quét đủ H0–L1 lúc lock snapshot | +//| • Màu / alpha — §1.3 vẽ vùng cung-cầu | +//| CHƯA CÓ: trading, session, LTF | //+------------------------------------------------------------------+ #ifndef HYPERICT_CONFIG_MQH #define HYPERICT_CONFIG_MQH @@ -7,22 +16,22 @@ #include input group "══ HTF Structure ══" -input ENUM_TIMEFRAMES InpHtf = PERIOD_H1; -input int InpSwingRange = 3; -input int InpSwingLookback = 400; -input double InpFibMinRatio = 0.382; +input ENUM_TIMEFRAMES InpHtf = PERIOD_H1; // §1: timeframe cấu trúc HTF +input int InpSwingRange = 3; // §1.4: số nến mỗi bên pivot (confirm đỉnh/đáy) +input int InpSwingLookback = 400; // quét swing lúc lock ban đầu +input double InpFibMinRatio = 0.382; // § tiên quyết: H1→L0 vs L1→H1 (chỉ lúc lock trend) input group "══ Hiển thị ══" -input bool InpDrawSwings = true; -input bool InpDrawZones = true; +input bool InpDrawSwings = true; // §1.3 label H0–L1 +input bool InpDrawZones = true; // §1.3 rectangle Key LV1/L2 input bool InpDrawPanel = true; input uchar InpZoneFillAlpha = 72; input color InpClrBullHi = clrDodgerBlue; input color InpClrBullLo = clrDeepSkyBlue; input color InpClrBearHi = clrOrangeRed; input color InpClrBearLo = clrGold; -input color InpClrSupply = C'140,50,55'; -input color InpClrDemand = C'35,110,55'; +input color InpClrSupply = C'140,50,55'; // vùng cung @ L0 +input color InpClrDemand = C'35,110,55'; // vùng cầu @ H0 input int InpLabelFontSize = 9; input int InpPanelX = 12; input int InpPanelY = 28; diff --git a/Include/HyperICT/Draw.mqh b/Include/HyperICT/Draw.mqh index fd305d0..81d848b 100644 --- a/Include/HyperICT/Draw.mqh +++ b/Include/HyperICT/Draw.mqh @@ -1,5 +1,13 @@ //+------------------------------------------------------------------+ -//| Draw.mqh — labels H0–L1, vùng Key LV1/L2 | +//| Draw.mqh | +//| Vẽ chart §1.3 | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • Label H0, H1, L0, L1 tại pivot đã khóa | +//| • Label newH0, newL0, newL02 khi đang §1.4 update | +//| • Rectangle Key LV1 & LV2: swing → hết OB (kéo tới bar hiện tại)| +//| • Màu supply/demand theo Config | +//| CHƯA: vẽ trên chart HTF khác chart đang mở (luôn ChartID hiện tại)| //+------------------------------------------------------------------+ #ifndef HYPERICT_DRAW_MQH #define HYPERICT_DRAW_MQH @@ -8,7 +16,6 @@ #include #include -//+------------------------------------------------------------------+ class CDraw { static long Chart() { return ChartID(); } @@ -45,6 +52,7 @@ class CDraw ObjectSetInteger(ch, id, OBJPROP_SELECTABLE, false); } + //--- §1.3: chiều cao rect = từ swing tới biên OB static void DrawZoneRect(const string id, const datetime t1, const double top, const double bottom, const color fillClr, const string tip) @@ -77,6 +85,7 @@ public: const string p = HICT_OBJ_PFX; + //--- §1.3 labels swing khóa if(InpDrawSwings && ctx.swings.IsComplete()) { DrawSwingLabel(p + "H0", "H0", ctx.swings.h0.time, ctx.swings.h0.price, true, InpClrBullHi); diff --git a/Include/HyperICT/FibValidator.mqh b/Include/HyperICT/FibValidator.mqh index 617c6ce..358afa1 100644 --- a/Include/HyperICT/FibValidator.mqh +++ b/Include/HyperICT/FibValidator.mqh @@ -1,5 +1,13 @@ //+------------------------------------------------------------------+ -//| FibValidator.mqh — Fib 0.382 chỉ cho tiên quyết trend ban đầu | +//| FibValidator.mqh | +//| Điều kiện tiên quyết Fibonacci (§ đầu spec) | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • Bull HH-HL & Bear LH-LL: kiểm tra ở SwingEngine.Classify | +//| • Sóng hồi H1→L0 >= 0.382 × sóng L1→H1 (bull & bear cùng công thức) | +//| • Fib fail → HTF_BULL/BEAR_INCOMPLETE (không Neutral) | +//| KHÔNG DÙNG FIB TRONG: | +//| • §1.4 CHoCH / Continue — xác nhận đỉnh/đáy = InpSwingRange | //+------------------------------------------------------------------+ #ifndef HYPERICT_FIBVALIDATOR_MQH #define HYPERICT_FIBVALIDATOR_MQH @@ -15,7 +23,7 @@ public: return MathAbs(to - from); } - // Sóng hồi H1→L0 >= ratio × sóng L1→H1 (bull & bear, chỉ lúc lock trend) + // § tiên quyết: pullback H1→L0 đủ sâu so với impulse L1→H1 static bool IsPullbackValid(const SwingSet &sw, const double ratio) { if(!sw.IsComplete()) diff --git a/Include/HyperICT/KeyLevels.mqh b/Include/HyperICT/KeyLevels.mqh index 4a43246..ea72651 100644 --- a/Include/HyperICT/KeyLevels.mqh +++ b/Include/HyperICT/KeyLevels.mqh @@ -1,5 +1,14 @@ //+------------------------------------------------------------------+ -//| KeyLevels.mqh — Key LV1/L2, supply/demand OB (body break) | +//| KeyLevels.mqh | +//| Key LV1/L2, vùng cung-cầu OB, phá level bằng body (§1.2) | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • Bull Key LV1=L0, Key LV2=H0 (đỉnh cao nhất L0→H0 = H0) | +//| • Bear Key LV1=H0, Key LV2=L0 | +//| • Vùng cung: L0 → high nến đỏ OB | Vùng cầu: H0 → low nến xanh | +//| • Phá Key = body close (shift 1), không dùng wick | +//| • Giá Pullback giữa L0–H0 / H0–L0 — PriceBetween | +//| CHƯA: OB mitigation filter đầy đủ ICT | //+------------------------------------------------------------------+ #ifndef HYPERICT_KEYLEVELS_MQH #define HYPERICT_KEYLEVELS_MQH @@ -7,10 +16,10 @@ #include #include -//+------------------------------------------------------------------+ class CKeyLevels { public: + //--- Thân nến (§: phá Key LV bằng body, không wick) static double BodyTop(const string sym, const ENUM_TIMEFRAMES tf, const int shift) { return MathMax(iOpen(sym, tf, shift), iClose(sym, tf, shift)); @@ -31,7 +40,7 @@ public: return iClose(sym, tf, shift) > iOpen(sym, tf, shift); } - // Nến đỏ cuối cùng trước/at swing low (supply @ L0) + //--- §1.2.3 vùng cung @ L0: nến đỏ cuối cùng gần đáy Key LV1 static bool FindSupplyOB(const string sym, const ENUM_TIMEFRAMES tf, const SwingPoint &swingLow, OrderBlockZone &out) @@ -60,7 +69,7 @@ public: return false; } - // Nến xanh cuối cùng tại swing high (demand @ H0) + //--- §1.2.4 vùng cầu @ H0: nến xanh cuối cùng gần đỉnh Key LV2 (bull) static bool FindDemandOB(const string sym, const ENUM_TIMEFRAMES tf, const SwingPoint &swingHigh, OrderBlockZone &out) @@ -89,6 +98,7 @@ public: return false; } + //--- Gán Key LV1/L2 + zone OB theo bias bull/bear static void BuildKeyLevels(const string sym, const ENUM_TIMEFRAMES tf, const ENUM_STRUCT_BIAS bias, const SwingSet &sw, diff --git a/Include/HyperICT/Panel.mqh b/Include/HyperICT/Panel.mqh index 28ea96e..27bd63a 100644 --- a/Include/HyperICT/Panel.mqh +++ b/Include/HyperICT/Panel.mqh @@ -1,5 +1,8 @@ //+------------------------------------------------------------------+ -//| Panel.mqh — nhãn trạng thái góc chart | +//| Panel.mqh | +//| Panel trạng thái HTF (đọc nhanh §1.1) | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: hiển thị structure, Fib, state, Key LV, phase §1.4 | //+------------------------------------------------------------------+ #ifndef HYPERICT_PANEL_MQH #define HYPERICT_PANEL_MQH @@ -8,7 +11,6 @@ #include #include -//+------------------------------------------------------------------+ class CPanel { public: diff --git a/Include/HyperICT/README.md b/Include/HyperICT/README.md new file mode 100644 index 0000000..ab15acd --- /dev/null +++ b/Include/HyperICT/README.md @@ -0,0 +1,311 @@ +# HyperICT + +Expert Advisor **chỉ đọc cấu trúc thị trường HTF** (Higher Timeframe): swing H0–L1, Key Level, vùng cung/cầu (Order Block), trạng thái Pullback / CHoCH / Continue. **Không đặt lệnh.** + +Phiên bản hiện tại: **0.11** + +--- + +## Mục lục + + + +1. [Cấu trúc thư mục](#folder-structure) +2. [Logic nghiệp vụ](#business-logic) +3. [Mô tả từng file](#file-reference) +4. [Luồng chạy (pipeline)](#pipeline) +5. [Cài đặt & sử dụng](#installation) +6. [Tham số input](#inputs) +7. [Trạng thái hiển thị](#display-states) +8. [API mở rộng](#api) +9. [Giới hạn & hướng phát triển](#roadmap) +10. [Map spec → module](#spec-map) + +--- + + + +## Cấu trúc thư mục + +``` +MQL5/ +├── Experts/ +│ └── HyperICT.mq5 ← EA chính (OnInit / OnTick) +│ +└── Include/ + └── HyperICT/ + ├── README.md ← tài liệu này + ├── Types.mqh ← enum, struct + ├── Config.mqh ← input + ├── FibValidator.mqh ← Fib 0.382 (chỉ tiên quyết) + ├── SwingEngine.mqh ← pivot, snapshot, roll swing + ├── KeyLevels.mqh ← Key LV1/L2, OB, body break + ├── Classifier.mqh ← 7+ trạng thái trend + ├── UpdateEngine.mqh ← §1.4 CHoCH / Continue + ├── StateMachine.mqh ← pipeline điều phối + ├── Draw.mqh ← vẽ chart + └── Panel.mqh ← panel góc chart +``` + +**Include trong code:** `#include ` + +--- + + + +## Logic nghiệp vụ + +### Điều kiện tiên quyết (chỉ lúc xác định trend) + +| Xu hướng | Cấu trúc | Fib | +|----------|---------|-----| +| **Bull** | HH-HL (`H0>H1` và `L0>L1`) | Sóng hồi **H1→L0** ≥ **38.2%** sóng **L1→H1** | +| **Bear** | LH-LL | Cùng công thức Fib | + +- **Fib fail** → state `BULL/BEAR (Fib pending)` — *không* coi là Neutral. +- **Neutral** chỉ khi không đủ 4 swing hoặc cấu trúc không HH-HL / LH-LL. + +### Swing H0, H1, L0, L1 + +- Đếm từ **giá hiện tại về trước** trên HTF (mặc định H1). +- **H0 / L0** = đỉnh/đáy gần nhất; **H1 / L1** = đỉnh/đáy trước đó. +- **Khóa snapshot** khi bot chạy (`OnInit`) — **không** đổi mỗi nến mới. + +### Key Level (§1.2) + +| Bias | Key LV1 | Key LV2 | Vùng cung | Vùng cầu | +|------|---------|---------|-----------|----------| +| Bull | **L0** | **H0** (= đỉnh cao nhất L0→H0) | L0 → high nến đỏ OB | H0 → low nến xanh OB | +| Bear | **H0** | **L0** | (đối xứng) | (đối xứng) | + +- **Phá Key** = thân nến (`max/min` open–close) trên bar HTF **đã đóng** (shift 1). +- Phá **Key LV1** → tín hiệu **CHoCH**. +- Phá **Key LV2** → tín hiệu **Trend Continue**. + +### Trạng thái trend (§1.1) + +| State | Điều kiện chính | +|-------|-----------------| +| **Bull Pullback** | Fib OK + giá giữa L0–H0 | +| **Bull CHoCH** | Body phá dưới L0, hoặc đang xử lý §1.4 CHoCH | +| **Bull Continue** | Body phá trên H0 / đang tạo newH0 | +| **Bear Pullback / CHoCH / Continue** | Đối xứng | +| **Neutral** | Không phân loại được cấu trúc | + +### Cập nhật sau phá Key (§1.4) — không quét lại full history + +**Xác nhận đỉnh/đáy mới:** dùng `InpSwingRange` (pivot đủ N nến mỗi bên). **Không** dùng Fib trong giai đoạn này. + +#### Bull Continue (phá H0) + +1. **P1:** Body phá H0 → track `newH0` (nến xanh, high cao hơn), `newL0` (đáy impulse). +2. **P2:** Hồi đủ → `IsConfirmedSwingHigh(newH0)` → roll: `H0→H1`, `L0→L1`, `newH0→H0`, `newL0→L0`. + +#### Bull CHoCH (phá L0) + +1. **P1:** Track `newL0` (low thấp hơn). +2. **P2:** `IsConfirmedSwingLow(newL0)` → vào phase 3. +3. **P3 case 1:** Phá lên H0 → `newH0` confirm → roll bull (`L1` giữ). +4. **P3 case 2:** Phá xuống `newL0` → `newH0` + `newL02` confirm → roll bear. + +Bear Continue / CHoCH: **đối xứng** với bull. + +--- + + + +## Mô tả từng file + +### `Experts/HyperICT.mq5` + +- Entry point: khởi tạo `HtfContext`, gọi `StateMachine`, `Draw`, `Panel`. +- `OnTick`: logic HTF chỉ khi **nến HTF mới**; vẽ rectangle cập nhật mỗi tick. +- Export: `HyperICT_GetState()` cho EA khác. + +### `Types.mqh` + +- `ENUM_STRUCT_BIAS`, `ENUM_HTF_STATE`, `ENUM_UPDATE_EVENT`, `ENUM_UPDATE_PHASE`. +- `SwingPoint`, `SwingSet`, `OrderBlockZone`, `KeyLevelPair`, `UpdateContext`, `HtfContext`. +- Không chứa logic tính toán. + +### `Config.mqh` + +- Toàn bộ `input`: HTF, swing range, lookback, Fib ratio, màu vẽ, debug. +- Prefix object chart: `HICT_`. + +### `FibValidator.mqh` + +- `IsPullbackValid()` — H1→L0 vs L1→H1 × `InpFibMinRatio`. +- **Chỉ** dùng cho tiên quyết trend (và tính lại sau roll swing). + +### `SwingEngine.mqh` + +- `IsSwingHigh` / `IsSwingLow`, `CollectSwings`, `PickLastTwo`. +- `LockInitialSnapshot`, `ClassifyStructure` (HH-HL / LH-LL). +- `IsConfirmedSwingHigh/Low` — xác nhận pivot sau phá Key. +- `RollBullContinue`, `RollBullChochCase1/2`, `RollBearContinue`, … + +### `KeyLevels.mqh` + +- Body break above/below. +- `FindSupplyOB` / `FindDemandOB`. +- `BuildKeyLevels`, `PriceBetween` (Pullback zone). + +### `Classifier.mqh` + +- `Evaluate()` → một trong các `ENUM_HTF_STATE`. +- Ưu tiên: đang `update.phase` → CHoCH/Continue; sau đó Fib pending; sau đó Pullback/break. + +### `UpdateEngine.mqh` + +- `DetectBreakEvents` — phá Key LV1/L2. +- `ProcessBullContinueBuild`, `ProcessBullChochBuild`, `ProcessBullChochResolve`, … +- `OnHtfBarClose` — gọi mỗi nến HTF mới. + +### `StateMachine.mqh` + +- `Init()` → lock snapshot + `RefreshDerived`. +- `OnChartEvent()` → `IsNewHtfBar` → `UpdateEngine` → Fib + Key + Classifier. + +### `Draw.mqh` + +- Label H0–L1, newH0/newL0/newL02. +- Rectangle Key LV1/L2 (kéo tới thời điểm hiện tại). + +### `Panel.mqh` + +- Label góc trái: structure, Fib, state, Key prices, phase update. + +--- + + + +## Luồng chạy (pipeline) + +```mermaid +flowchart TD + A[OnInit] --> B[SwingEngine.LockInitialSnapshot] + B --> C[RefreshDerived: Fib + Key + Classify] + C --> D[Draw + Panel] + + E[OnTick] --> F{Nến HTF mới?} + F -->|Không| G[Draw refresh rect] + F -->|Có| H[UpdateEngine.OnHtfBarClose] + H --> I[RefreshDerived] + I --> G + G --> J[Panel update] +``` + +--- + + + +## Cài đặt & sử dụng + +1. Copy `Experts/HyperICT.mq5` và thư mục `Include/HyperICT/` vào terminal MT5. +2. MetaEditor → mở `HyperICT.mq5` → **F7** compile. +3. Kéo EA lên chart (symbol cần đủ lịch sử HTF). +4. Khuyến nghị: mở chart **cùng symbol**; HTF logic đọc `InpHtf` (mặc định H1) dù chart có thể M15/M5. +5. Bật `InpDebug = true` để xem log `[HyperICT]` và `[HyperICT/Update]` trong tab Experts. + +### Gợi ý tinh chỉnh + +| Triệu chứng | Thử | +|-------------|-----| +| Init fail / không đủ swing | Giảm `InpSwingRange` hoặc tăng `InpSwingLookback` | +| Pivot confirm chậm | Giảm `InpSwingRange` | +| Pivot nhiễu | Tăng `InpSwingRange` | +| Fib mãi pending | Kiểm tra sóng H1→L0 trên chart H1 | + +--- + + + +## Tham số input + +| Input | Mặc định | Ý nghĩa | +|-------|----------|---------| +| `InpHtf` | H1 | Timeframe cấu trúc | +| `InpSwingRange` | 3 | Nến mỗi bên pivot; confirm đỉnh/đáy §1.4 | +| `InpSwingLookback` | 400 | Số nến quét lúc lock ban đầu | +| `InpFibMinRatio` | 0.382 | Tiên quyết pullback (chỉ lúc lock trend) | +| `InpDrawSwings` | true | Label H0–L1 | +| `InpDrawZones` | true | Rectangle Key LV | +| `InpDrawPanel` | true | Panel trạng thái | +| `InpDebug` | false | Log chi tiết | + +--- + + + +## Trạng thái hiển thị + +| Panel text | Ý nghĩa | +|------------|---------| +| `BULL PULLBACK` | Bull hợp lệ, giá trong L0–H0 | +| `BULL (Fib pending)` | HH-HL nhưng hồi chưa đủ 38.2% | +| `BULL CHoCH` | Phá L0 hoặc đang update CHoCH | +| `BULL CONTINUE` | Phá H0 / đang tạo đỉnh mới | +| `BEAR …` | Đối xứng | +| `NEUTRAL` | Cấu trúc không rõ | + +Khi đang update: dòng `Update: evt=… phase=… | swingR=…`. + +--- + + + +## API mở rộng + +```cpp +// Trong HyperICT.mq5 — có thể #include Types từ EA khác nếu cần enum +ENUM_HTF_STATE HyperICT_GetState(); +``` + +Trả về `ctx.state` hiện tại. EA khác có thể đọc sau khi HyperICT chạy trên cùng chart (cần thiết kế thêm export nếu muốn đọc swing/Key từ bên ngoài). + +--- + + + +## Giới hạn & hướng phát triển + +### Đã có + +- HTF structure, Key LV, OB đơn giản, 7+ states, snapshot lock, §1.4 incremental update với swing confirm. + +### Chưa có + +- Đặt lệnh, quản lý risk, session filter. +- LTF entry (MSS, FVG, …). +- OB mitigation filter chuẩn ICT. +- Vẽ trên chart HTF tách biệt (hiện dùng `ChartID()` đang mở). +- Alert / push notification. + +### Hướng phát triển gợi ý + +1. Test & harden `UpdateEngine` trên lịch sử (Strategy Tester visual). +2. Module `LTF` tách riêng, đọc `HyperICT_GetState()`. +3. Cải thiện `FindSupplyOB` / `FindDemandOB`. +4. Export struct `HtfContext` qua global hoặc file cho indicator. + +--- + + + +## Map spec → module (tóm tắt) + +| Spec | Module | +|------|--------| +| Tiên quyết Fib + HH-HL | `FibValidator`, `SwingEngine` | +| §1.1 States | `Classifier`, `Panel` | +| §1.2 Key + OB | `KeyLevels`, `Draw` | +| §1.3 Vẽ | `Draw` | +| §1.4 CHoCH/Continue | `UpdateEngine`, `SwingEngine` | +| Pipeline | `StateMachine` | +| Input | `Config` | +| Data model | `Types` | + +--- + +*Tài liệu đồng bộ với HyperICT v0.11. Khi đổi logic, cập nhật comment đầu từng file `.mqh` và README này.* diff --git a/Include/HyperICT/StateMachine.mqh b/Include/HyperICT/StateMachine.mqh index e7daba5..dfd9e4e 100644 --- a/Include/HyperICT/StateMachine.mqh +++ b/Include/HyperICT/StateMachine.mqh @@ -1,5 +1,13 @@ //+------------------------------------------------------------------+ -//| StateMachine.mqh — pipeline đánh giá HTF mỗi bar | +//| StateMachine.mqh | +//| Pipeline: Init → mỗi nến HTF → Update → Fib/Key → Classify | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • OnInit: LockInitialSnapshot (swing cố định từ lúc bot chạy) | +//| • Mỗi nến HTF mới: UpdateEngine → RefreshDerived → state | +//| • RefreshDerived: Fib tiên quyết + KeyLevels + Classifier | +//| • Sau roll swing: tính lại structBias, fibOk, key, state | +//| KHÔNG: trading logic, OnTimer intrabar cho update | //+------------------------------------------------------------------+ #ifndef HYPERICT_STATEMACHINE_MQH #define HYPERICT_STATEMACHINE_MQH @@ -12,7 +20,6 @@ #include #include -//+------------------------------------------------------------------+ class CStateMachine { static void Dbg(const string msg) @@ -23,7 +30,7 @@ class CStateMachine static void RefreshDerived(HtfContext &ctx) { - // Fib 0.382 chỉ kiểm tra tiên quyết trên bộ swing hiện tại (không dùng trong §1.4) + // Fib 0.382: chỉ ý nghĩa tiên quyết pullback trên bộ swing hiện tại ctx.fibOk = CFibValidator::IsPullbackValid(ctx.swings, InpFibMinRatio); CKeyLevels::BuildKeyLevels(ctx.symbol, ctx.htf, ctx.structBias, ctx.swings, ctx.keyLv1, ctx.keyLv2); @@ -58,8 +65,8 @@ public: if(newBar) { ctx.lastHtfBar = iTime(ctx.symbol, ctx.htf, 0); - CUpdateEngine::OnHtfBarClose(ctx); - RefreshDerived(ctx); + CUpdateEngine::OnHtfBarClose(ctx); // §1.4 trước + RefreshDerived(ctx); // §1.1 + §1.2 sau if(InpDebug) Dbg("HTF bar → " + CClassifier::StateText(ctx.state)); } diff --git a/Include/HyperICT/SwingEngine.mqh b/Include/HyperICT/SwingEngine.mqh index 93b3678..94f59bb 100644 --- a/Include/HyperICT/SwingEngine.mqh +++ b/Include/HyperICT/SwingEngine.mqh @@ -1,5 +1,14 @@ //+------------------------------------------------------------------+ -//| SwingEngine.mqh — pivot, H0–L1, snapshot khóa | +//| SwingEngine.mqh | +//| Pivot HTF, H0–L1, khóa snapshot, roll swing §1.4 | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • §1: H0,H1,L0,L1 từ giá hiện tại về trước (2 high + 2 low) | +//| • HH-HL / LH-LL — ClassifyStructure | +//| • Khóa swing lúc bot chạy — LockInitialSnapshot (không đổi mỗi nến) | +//| • §1.4 roll: Continue, CHoCH case1 (L1 giữ), CHoCH case2 bear | +//| • Xác nhận pivot sau phá Key — IsConfirmedSwingHigh/Low + range | +//| CHƯA TỐI ƯU: quét OB chất lượng ICT (mitigation) | //+------------------------------------------------------------------+ #ifndef HYPERICT_SWINGENGINE_MQH #define HYPERICT_SWINGENGINE_MQH @@ -7,10 +16,10 @@ #include #include -//+------------------------------------------------------------------+ class CSwingEngine { public: + //--- Pivot chuẩn: `range` nến mỗi phía (dùng cho §1.4 confirm đỉnh/đáy) static bool IsSwingHigh(const string sym, const ENUM_TIMEFRAMES tf, const int shift, const int range) { @@ -144,6 +153,7 @@ public: has1 = true; } + //--- §1.1 tiên quyết đặc điểm 1: HH-HL hoặc LH-LL static ENUM_STRUCT_BIAS ClassifyStructure(const SwingSet &sw) { if(!sw.IsComplete()) @@ -167,6 +177,7 @@ public: return out.IsComplete(); } + //--- § chú ý: snapshot HTF cố định từ khi bot chạy (chỉ đổi qua UpdateEngine) static bool LockInitialSnapshot(HtfContext &ctx) { ctx.swings.Clear(); @@ -178,6 +189,7 @@ public: return true; } + //--- §1.4a Bull Continue P2: H0→H1, L0→L1, newH0→H0, newL0→L0 static void RollBullContinue(SwingSet &sw, const SwingPoint &newH0, const SwingPoint &newL0) { sw.h1 = sw.h0; @@ -190,17 +202,19 @@ public: sw.hasL0 = true; } + //--- §1.4b Bull CHoCH P3 case1: H0→H1, L1 giữ, newL0→L0, newH0→H0 static void RollBullChochCase1(SwingSet &sw, const SwingPoint &newH0, const SwingPoint &newL0) { sw.h1 = sw.h0; sw.hasH1 = sw.hasH0; - // L1 giữ nguyên (spec) + // L1 giữ nguyên theo spec sw.l0 = newL0; sw.hasL0 = true; sw.h0 = newH0; sw.hasH0 = true; } + //--- §1.4b Bull CHoCH P3 case2: confirm bear — H0→H1, newH0→H0, newL0→L1, newL02→L0 static void RollBullChochCase2(SwingSet &sw, const SwingPoint &newH0, const SwingPoint &newL0, @@ -216,6 +230,7 @@ public: sw.hasL0 = true; } + //--- §1.4c Bear Continue (đối xứng bull continue) static void RollBearContinue(SwingSet &sw, const SwingPoint &newH0, const SwingPoint &newL0) { sw.l1 = sw.l0; diff --git a/Include/HyperICT/Types.mqh b/Include/HyperICT/Types.mqh index c149bd9..c49f38b 100644 --- a/Include/HyperICT/Types.mqh +++ b/Include/HyperICT/Types.mqh @@ -1,9 +1,19 @@ //+------------------------------------------------------------------+ -//| Types.mqh — enums & structs (spec §1–1.4) | +//| Types.mqh | +//| Mô hình dữ liệu cho toàn bộ HyperICT (map trực tiếp spec §1–1.4) | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT (ánh xạ spec → code): | +//| • H0,H1,L0,L1 — SwingSet + SwingPoint | +//| • §1.1 trạng thái: ENUM_HTF_STATE (Pullback/CHoCH/Continue/…) | +//| • §1.2 Key LV1/L2 + vùng OB — KeyLevelPair, OrderBlockZone | +//| • §1.4 update tăng dần — UpdateContext (newH0, newL0, newL02) | +//| • Khóa snapshot HTF — HtfContext.snapshotReady, lockedAt | +//| CHƯA CÓ TRONG FILE NÀY: logic tính toán (nằm ở module khác) | //+------------------------------------------------------------------+ #ifndef HYPERICT_TYPES_MQH #define HYPERICT_TYPES_MQH +//--- §1.1 tiên quyết cấu trúc: HH-HL (bull) / LH-LL (bear) enum ENUM_STRUCT_BIAS { STRUCT_NONE = 0, @@ -11,31 +21,34 @@ enum ENUM_STRUCT_BIAS STRUCT_BEAR = -1 }; +//--- §1.1 các trạng thái trend HTF (+ Fib pending, không phải Neutral) enum ENUM_HTF_STATE { - HTF_NEUTRAL = 0, - HTF_BULL_INCOMPLETE = 1, + HTF_NEUTRAL = 0, // không phân loại được 4 swing / cấu trúc lẫn lộn + HTF_BULL_INCOMPLETE = 1, // HH-HL nhưng Fib hồi H1→L0 chưa đủ (§ tiên quyết) HTF_BEAR_INCOMPLETE = 2, - HTF_BULL_PULLBACK = 3, - HTF_BULL_CHOCH = 4, - HTF_BULL_CONTINUE = 5, + HTF_BULL_PULLBACK = 3, // Fib OK + giá giữa L0–H0 + HTF_BULL_CHOCH = 4, // body phá L0 (Key LV1) hoặc đang phase CHoCH + HTF_BULL_CONTINUE = 5, // body phá H0 (Key LV2) hoặc đang phase Continue HTF_BEAR_PULLBACK = 6, HTF_BEAR_CHOCH = 7, HTF_BEAR_CONTINUE = 8 }; +//--- §1.2 / §1.4: sự kiện phá Key level (body close trên bar HTF đóng) enum ENUM_UPDATE_EVENT { UPD_NONE = 0, - UPD_CHOCH = 1, - UPD_CONTINUE = 2 + UPD_CHOCH = 1, // phá Key LV1 → Change of Character + UPD_CONTINUE = 2 // phá Key LV2 → tiếp diễn xu hướng }; +//--- §1.4 các giai đoạn sau khi phá Key (không quét lại full lookback) enum ENUM_UPDATE_PHASE { UPD_PHASE_IDLE = 0, - UPD_PHASE_BUILD = 1, - UPD_PHASE_CHOCH_RESOLVE = 2 + UPD_PHASE_BUILD = 1, // P1: track newH0/newL0; P2 CHoCH: xác nhận pivot + UPD_PHASE_CHOCH_RESOLVE = 2 // CHoCH P3: case1 về bull / case2 confirm bear }; enum ENUM_CHOCH_BRANCH @@ -45,6 +58,7 @@ enum ENUM_CHOCH_BRANCH CHOCH_BRANCH_CONFIRM_BEAR = 2 }; +//--- Đỉnh/đáy pivot (từ hiện tại về trước: H0/L0 mới nhất) struct SwingPoint { double price; @@ -59,6 +73,7 @@ struct SwingPoint bool Valid() const { return shift >= 0 && price > 0.0; } }; +//--- §1.2 vùng cung/cầu: swing → biên OB (nến đỏ @ L0 / nến xanh @ H0) struct OrderBlockZone { double swingPrice; @@ -76,12 +91,14 @@ struct OrderBlockZone } }; +//--- §1.2 Key LV1 / Key LV2 (giá + zone vẽ rectangle) struct KeyLevelPair { double price; OrderBlockZone zone; }; +//--- Bộ swing khóa: H0,H1,L0,L1 struct SwingSet { SwingPoint h0, h1, l0, l1; @@ -97,6 +114,7 @@ struct SwingSet } }; +//--- §1.4 ngữ cảnh cập nhật incremental (newH0/newL0/newL02, khóa khi pivot confirm) struct UpdateContext { ENUM_UPDATE_EVENT event; @@ -104,10 +122,10 @@ struct UpdateContext ENUM_CHOCH_BRANCH chochBranch; SwingPoint newH0; SwingPoint newL0; - SwingPoint newL02; - bool newH0Locked; + SwingPoint newL02; // CHoCH bull case2 → roll thành L0 + bool newH0Locked; // ngừng track high khi swing confirm bool newLLocked; - bool case1TrackingH0; + bool case1TrackingH0; // CHoCH P3 case1: đang tạo đỉnh mới void Clear() { event = UPD_NONE; @@ -119,13 +137,14 @@ struct UpdateContext } }; +//--- Trạng thái runtime toàn EA (một snapshot HTF tại thời điểm bot chạy / sau roll) struct HtfContext { string symbol; ENUM_TIMEFRAMES htf; SwingSet swings; ENUM_STRUCT_BIAS structBias; - bool fibOk; + bool fibOk; // § tiên quyết Fib (chỉ ý nghĩa pullback hợp lệ) KeyLevelPair keyLv1; KeyLevelPair keyLv2; ENUM_HTF_STATE state; diff --git a/Include/HyperICT/UpdateEngine.mqh b/Include/HyperICT/UpdateEngine.mqh index 7c2a20f..ea24296 100644 --- a/Include/HyperICT/UpdateEngine.mqh +++ b/Include/HyperICT/UpdateEngine.mqh @@ -1,6 +1,18 @@ //+------------------------------------------------------------------+ -//| UpdateEngine.mqh — §1.4: xác nhận đỉnh/đáy bằng InpSwingRange | -//| (Fib chỉ dùng lúc lock trend ban đầu — xem FibValidator) | +//| UpdateEngine.mqh | +//| §1.4 CHoCH & Trend Continue — cập nhật incremental | +//+------------------------------------------------------------------+ +//| ĐÃ GIẢI QUYẾT: | +//| • Chỉ chạy khi nến HTF mới đóng; không quét lại full lookback | +//| • Phá Key LV1 (body) → CHoCH | Phá Key LV2 → Continue | +//| • §1.4a Bull Continue P1: track newH0 (nến xanh), newL0 (đáy) | +//| • §1.4a P2: IsConfirmedSwingHigh(newH0) → roll, khóa newH0 | +//| • §1.4b Bull CHoCH P1–2: track newL0 → swing low confirm → P3 | +//| • §1.4b P3 case1: phá H0 → newH0 confirm → roll (L1 giữ) | +//| • §1.4b P3 case2: phá newL0 → newH0+newL02 confirm → bear roll| +//| • §1.4c/d Bear: đối xứng Continue & CHoCH | +//| • Xác nhận đỉnh/đáy = InpSwingRange (KHÔNG dùng Fib ở đây) | +//| CHƯA TỐI ƯU: gắn OB chính xác cho newL0 mỗi leg; edge case đa tín hiệu | //+------------------------------------------------------------------+ #ifndef HYPERICT_UPDATEENGINE_MQH #define HYPERICT_UPDATEENGINE_MQH @@ -66,6 +78,7 @@ public: return t0 != 0 && t0 != ctx.lastHtfBar; } + //--- Phát hiện body phá Key LV1/L2 lần đầu → bật BUILD static void DetectBreakEvents(HtfContext &ctx) { if(ctx.update.phase != UPD_PHASE_IDLE) @@ -118,6 +131,7 @@ public: } } + //--- §1.4a Bull Continue — P1 track + P2 swing high confirm → roll static void ProcessBullContinueBuild(HtfContext &ctx, const int sh) { if(CKeyLevels::IsBullCandle(ctx.symbol, ctx.htf, sh)) @@ -160,6 +174,7 @@ public: Dbg("Bear Continue — swing low confirmed, rolled"); } + //--- §1.4b Bull CHoCH — P1 track newL0, P2 swing low confirm → CHOCH_RESOLVE static void ProcessBullChochBuild(HtfContext &ctx, const int sh) { TrackNewLow(ctx.symbol, ctx.htf, sh, ctx.update.newL0, ctx.update.newLLocked); @@ -192,6 +207,7 @@ public: Dbg("Bear CHoCH — newH0 swing confirmed → phase 3"); } + //--- §1.4b Bull CHoCH P3 — case1 về bull / case2 confirm bear static void ProcessBullChochResolve(HtfContext &ctx, const int sh) { if(CKeyLevels::BodyBreakAbove(ctx.symbol, ctx.htf, sh, ctx.swings.h0.price)) diff --git a/Profiles/Charts/Default/order.wnd b/Profiles/Charts/Default/order.wnd index b8497edb4ea7fdefc7f979106a454f1f8026ab85..c5cfb5268c3f2242826a5ba1809d8703b004ae47 100644 GIT binary patch delta 81 zcmd0L$Hesi-^2i^i82lo`J@<4C-O@&nt=#&5Mco#EGP1dGaE7(04YYpiM*0P!ch_^ ZU