🚧 PLANNING — 6 PHASES READY

ALAMO Hotfix5 — Account DD + Array List Fire

feat/alamo-hedge · 2026-05-14 19:25 · SS spec locked 13 directives · ~15h effort

Hotfix5 thay đổi 3 things lớn trong ALAMO module: (1) DD metric đo Account DD live thay vì anchor-relative; (2) 2-Condition Filter direction flipped vì code Hotfix4 đếm sai chiều dominant; (3) Hotfix3 L1-fixed anchor reverted về prevLn (snowball chấp nhận như chiến lược). Cộng thêm state machine simplify (bỏ offset entry) + prevLn cache + Array List fire condition theo SS spec 19:25.

Bug 1 — DD metric
DD đo sai (anchor-relative)
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.
Bug 2 — checkAbove flipped
2-Cond direction đảo ngược
Code Hotfix4: 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.
Bug 3 — Anchor wrong direction
L1-fixed anchor trái chiến lược
Hotfix3 đã lock anchor = L1 fixed (prevent snowball). SS chỉ thị 18:45: revert về prevLn (relative). Snowball/blow-up = chiến lược chủ động, không phải bug.
13 directives chốt từ SS qua các session 2026-05-14 18:03 → 19:25. Mỗi item locked, không revisit unless SS explicitly override.
  1. DD trigger only — DD chỉ dùng để TRIGGER fire L1/L2/L3, KHÔNG dùng cho tracking/positioning/close logic. (SS 18:03)
  2. Tracking price-based — Tracking + positioning dùng vị trí lệnh với anchor ticket, KHÔNG đụng DD. (SS 18:03)
  3. Account DD formula(balance − equity) / balance × 100, dùng live AccountInfoDouble(ACCOUNT_BALANCE). (SS 18:03)
  4. 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)
  5. Con2 fix → đo Account DD live thay vì sumNeg/anchor. (SS 18:03)
  6. mult pattern — Option A confirmed (giữ DRY). 1 hàm AlamoCon2Met(mult) cho 4 trigger points (S1=0.5, L1=1, L2=2, L3=3). (SS 18:35)
  7. Offset 2.5 → 5.0% → REVOKED (SS 19:04). Simplify bỏ luôn offset, xoá AlamoS3MonitorOffset input.
  8. Activation Single ResponsibilityAlamoCon1AllNegative() check all-âm, AlamoCon2Met() check DD threshold. Caller combine, KHÔNG gộp vào 1 hàm. (SS 18:35)
  9. 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)
  10. 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)
  11. 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)
  12. prevLn snapshot cache — Struct g_alamoPrevCache lưu metadata, populate mỗi AlamoFire success. Clear CHỈ khi AlamoResetCycle() (PosMan close full loop). KHÔNG invalidate khi individual close hay stale ticket. (SS 19:10)
  13. 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)
# 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

1. AlamoCurrentDDPct — Account DD formula

BEFORE (Hotfix4)
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;
}
AFTER (Hotfix5)
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

BEFORE (Hotfix4 — sai)
// L1=SELL → ABOVE; L1=BUY → BELOW
bool checkAbove =
   (lnType == POSITION_TYPE_SELL);
AFTER (Hotfix5)
// BUY dom (L1=SELL) → BELOW
// SELL dom (L1=BUY) → ABOVE
bool checkAbove =
   (lnType == POSITION_TYPE_BUY);

3. Fire condition — Array List model

BEFORE (Hotfix4)
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, ...);
}
AFTER (Hotfix5)
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, ...);
}
STANDBY → DD ≥ 5% + Con1 → S1 của L1 → DD ≥ 10% + Con1 → FIRE L1 → S1 của L2
S1 của L2 → DD ≥ 20% + Array List all-neg → FIRE L2 → S1 của L3 → ... loop ...
S1 của Ln+1 ↕ Con1 broken pause S2_PAUSE → Con1 restored → resume
Mỗi Ln có S1 riêng. Sau Ln-1 fire → "S1 của Ln+1 kích hoạt" ngay, không chờ offset entry. Continuous monitor cho tới khi DD ≥ N×Thr AND Array List of Ln all-negative → fire.

Khi Ln-1 fire, ALAMO bắt đầu build Array List của Ln:

  1. Direction check: đo dominant side của main grid
  2. Anchor: prevLn (L1 cho L2, L2 cho L3, ...)
  3. 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
  4. Index 0 của Array List = order đầu tiên trên/dưới prevLn theo direction
  5. Monitor loop mỗi tick:
    • Nếu DD < N×Thr → continue (không fire)
    • Nếu DD ≥ N×Thr AND qualCount > 0fire Ln
  6. Recursive cho L3, L4... với prevLn anchor
SS strategic directive (2026-05-14 18:45): Anchor trượt theo prevLn (không L1-fixed) chấp nhận snowball/blow-up risk. "Blow up là một phần kế hoạch mà chúng ta cần có." Memory: feedback-accept-strategic-risk.
  • 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 > 0 trên mỗi fire event
  • UI Row 2 DD match ALAMO panel header DD trên screenshot
  • No AlamoS3MonitorOffset references trong log/code
FileChanges
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)
HotfixStatus
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)