🐛 Root cause — 3 bugs phát hiện
AlamoCurrentDDPct dùng sumNeg / equityAnchor (anchor frozen tại L1 fire).
L2/L3 fire ở account DD ~12-13% thay vì 20%/30%. Spec đúng: (balance−equity)/balance×100,
đồng nhất UI Row 2.
checkAbove = (lnType==SELL). SS spec: BUY dom (L1=SELL) → đếm BELOW
L1. Đúng phải là (lnType==BUY). Bug này ảnh hưởng cả Count2CondOrders + Sum2CondLots.
🔒 SS Directives (locked)
- DD trigger only — DD chỉ dùng để TRIGGER fire L1/L2/L3, KHÔNG dùng cho tracking/positioning/close logic. (SS 18:03)
- Tracking price-based — Tracking + positioning dùng vị trí lệnh với anchor ticket, KHÔNG đụng DD. (SS 18:03)
- Account DD formula —
(balance − equity) / balance × 100, dùng liveAccountInfoDouble(ACCOUNT_BALANCE). (SS 18:03) - Con1 cho L1 fire — Giữ full grid all-negative check cho L1 (cần xác định dominant chắc chắn). Drop cho L_n+1. (SS 19:25)
- Con2 fix → đo Account DD live thay vì
sumNeg/anchor. (SS 18:03) multpattern — Option A confirmed (giữ DRY). 1 hàmAlamoCon2Met(mult)cho 4 trigger points (S1=0.5, L1=1, L2=2, L3=3). (SS 18:35)- Offset 2.5 → 5.0%
→ REVOKED (SS 19:04). Simplify bỏ luôn offset, xoá
AlamoS3MonitorOffsetinput. - Activation Single Responsibility —
AlamoCon1AllNegative()check all-âm,AlamoCon2Met()check DD threshold. Caller combine, KHÔNG gộp vào 1 hàm. (SS 18:35) - Position direction — Interpretation A — "Dominant" = main grid majority side. BUY dom → L1=SELL → đếm BELOW L1. SELL dom → L1=BUY → đếm ABOVE L1. (SS 18:40)
- Anchor = prevLn (relative) — REVERSE Hotfix3 L1-fixed. L2 anchor=L1, L3 anchor=L2, ... Snowball/blow-up chấp nhận như chiến lược chủ động. (SS 18:45)
- State machine simplify — Sau Ln-1 fire → S1 của Ln+1 kích hoạt ngay (continuous monitor). Bỏ offset entry zone. CPU tradeoff negligible. (SS 19:04)
- prevLn snapshot cache — Struct
g_alamoPrevCachelưu metadata, populate mỗiAlamoFiresuccess. Clear CHỈ khiAlamoResetCycle()(PosMan close full loop). KHÔNG invalidate khi individual close hay stale ticket. (SS 19:10) - L_n+1 fire = Array List all-neg — Fire khi DD ≥ N×Thr AND tất cả lệnh trong Array List của Ln có lỗ hết. Drop full-grid Con1 cho L_n+1. Recursive cho L3, L4... (SS 19:25)
📋 6 Phases
| # | Title | Effort | Deps | Scope |
|---|---|---|---|---|
| 01 | Account DD Trigger Fix | 2h | — | AlamoCurrentDDPct + AlamoCon2Met + fire log + UI sync |
| 02 | 2-Cond Direction Fix + Overload | 2h | — | Flip checkAbove + add (price, type) overload (cache path) |
| 03 | prevLn Anchor + Snapshot Cache | 3h | 2 | Struct AlamoPrevLnCache + populate/read/clear (only on AlamoResetCycle) |
| 04 | State Machine Simplify | 2h | 3 | Ln fire → S1 của Ln+1 ngay; remove AlamoS3MonitorOffset input |
| 05 | Fire Condition Refactor (Array List) | 3h | 2, 3, 4 | Drop full-grid Con1 cho L_n+1; fire = DD ≥ N×Thr + Array List all-neg |
| 06 | EA Copy + Compile + Backtest | 3h | 1-5 | New EA (Hotfix5-AccountDD).mq5 + backtest 2 datasets |
🔧 Key code changes
1. AlamoCurrentDDPct — Account DD formula
double AlamoCurrentDDPct()
{
if(g_alamoEquityAnchor <= 0) return 0.0;
double sumNeg = 0.0;
for(int i=0; i<PositionsTotal(); i++) {
... // iterate main grid neg PnL
}
return (MathAbs(sumNeg)
/ g_alamoEquityAnchor) * 100.0;
}
double AlamoCurrentDDPct()
{
double balance = AccountInfoDouble(
ACCOUNT_BALANCE);
double equity = AccountInfoDouble(
ACCOUNT_EQUITY);
if(balance <= 0) return 0.0;
double dd = ((balance - equity) /
balance) * 100.0;
return MathMax(dd, 0.0);
}
2. checkAbove direction — flip per SS dominant spec
// L1=SELL → ABOVE; L1=BUY → BELOW bool checkAbove = (lnType == POSITION_TYPE_SELL);
// BUY dom (L1=SELL) → BELOW // SELL dom (L1=BUY) → ABOVE bool checkAbove = (lnType == POSITION_TYPE_BUY);
3. Fire condition — Array List model
case ALAMO_S3_MONITOR:
{
if(!AlamoCon1AllNegative(...))
{ fall back to S2; } // full grid
if(ddNow < fireGate) return;
double lotSum =
AlamoSum2CondLots(L1_ticket);
if(lotSum <= 0) return;
AlamoFire(opp, lotSum, ...);
}
case ALAMO_S3_MONITOR:
{
if(!g_alamoPrevCache.valid) return;
if(ddNow < fireGate) return;
int qualCount = AlamoCount2CondOrders(
cache.priceOpen, cache.type);
if(qualCount <= 0) return;
// Array List by construction all-neg
double lotSum = AlamoSum2CondLots(...);
AlamoFire(opp, lotSum, ...);
}
🔄 State machine — simplified
📦 Array List of Ln — fire flow
Khi Ln-1 fire, ALAMO bắt đầu build Array List của Ln:
- Direction check: đo dominant side của main grid
- Anchor: prevLn (L1 cho L2, L2 cho L3, ...)
- Filter orders:
- BUY dom → orders BELOW prevLn (giá rớt thêm)
- SELL dom → orders ABOVE prevLn (giá tăng thêm)
- Symbol = current, Magic = main grid (123456), Volume > 0.01 (skip Skill 6), PnL < 0
- Index 0 của Array List = order đầu tiên trên/dưới prevLn theo direction
- Monitor loop mỗi tick:
- Nếu DD < N×Thr → continue (không fire)
- Nếu DD ≥ N×Thr AND
qualCount > 0→ fire Ln
- Recursive cho L3, L4... với prevLn anchor
feedback-accept-strategic-risk.
✅ Verify checklist (Phase 6 backtest)
- Init log:
FBot Hotfix5: AccountDD=true | balance=X | equity=Y | accountDD=Z% - L1 fire: account DD ≥ 10.00%
- L2 fire: account DD ≥ 20.00%
- L3 fire: account DD ≥ 30.00% (nếu reach)
- L2/L3 anchor = prevLn ticket (KHÔNG L1-fixed)
qualCount > 0trên mỗi fire event- UI Row 2 DD match ALAMO panel header DD trên screenshot
- No
AlamoS3MonitorOffsetreferences trong log/code
📁 Files touched (Hotfix5 scope)
| File | Changes |
|---|---|
Include/FBot/FBotAlamo.mqh |
Phase 1-5 majority (DD formula, checkAbove flip, cache populate, S3 refactor) |
Include/FBot/FBotGlobals.mqh |
Add AlamoPrevLnCache struct + global (Phase 3) |
Include/FBot/FBotInputs.mqh |
Remove AlamoS3MonitorOffset input (Phase 4) |
Include/FBot/FBotUI.mqh |
Sync ALAMO panel header to AlamoCurrentDDPct() (Phase 1) |
Experts/Advisors/FBot_v4.1_Alamo_Jun2026_(Hotfix5-AccountDD).mq5 |
NEW copy từ Hotfix4 (Phase 6) |
🔥 Hotfix lineage
| Hotfix | Status |
|---|---|
| 1 — PosManCloseAlamo | ✓ preserved |
| 2 — L2L3Fire (gate scale + N×Thr) | ✓ preserved |
| 3 — LotSnowball (L1-fixed anchor) | ✗ REVERTED (SS strategic) |
| 4 — Modular per-Ln + offset 2.5% | ⚠ partial (modular kept, offset removed) |
| 5 — AccountDD + Direction + Array List | 🚧 planning (6 phases) |