ALAMO Hotfix4🚧 PLANNING

Branch: feat/alamo-hedge · Date: 2026-05-14 · Status: pending MV3 + SS approval

Hotfix4 chuyển ALAMO từ monolithic state machine sang per-Ln mini-module (L1...L10 độc lập), strip sạch main grid khỏi EA, và tinh chỉnh pre-fire offset 2.0% → 2.5%. Hotfix1/2/3 vẫn được preserve nguyên vẹn.

▶ 4 GOALS
Modular per-Ln · Strip main grid · Tweak pre-fire · UI tracker

GUARD Main grid placement sau flag AlamoOnly=true (Scope A) — block placement, giữ infrastructure. Verified bug: 2,951 stray LOT_CALC/sell stop lines trong log Hotfix3 dù ArcherEnabled=false.
NEW Per-Ln mini-module — AlamoLevel g_levels[10] với state riêng từng level.
TWEAK Pre-fire offset 2.0% → 2.5% (SS spec).
NEW UI panel ALAMO tracker — replace "Phòng thủ Phản công".
KEEP Hotfix1 (PosMan redundancy), Hotfix2 (gate scale N×Thr), Hotfix3 (L1-fixed lot anchor), Smart Close, all includes & inputs.

1. Per-Ln State Machine

IDLE MONITOR (S1) ACTIVE (S2)
FromToTrigger
IDLEMONITORDD ≥ (N × L1Thr − 2.5%) AND Con1 all-âm
MONITORIDLECon1 broken OR DD < (N × L1Thr − 2.5%)
MONITORACTIVEDD ≥ N × L1Thr AND Con1 + cooldown OK → FIRE
ACTIVEIDLESelf-close (profit ≥ threshold) OR Combined close OR Redundancy CloseAll

SS spec verbatim: "L2 vào S1 khi drawdown đạt (2x L1 − 2.5%), false return thì ngồi chơi, yes return thì bắt đầu đếm như cũ. >= 2x L1 thì S2 activate."

2. Level Threshold Map

L1Thr = 10%, MaxLevels = 10, monOffset = 2.5%

L1

fire ≥ 10.0%
mon ≥ 5.0% (S1Mult)

L2

fire ≥ 20.0%
mon ≥ 17.5%

L3

fire ≥ 30.0%
mon ≥ 27.5%

L4

fire ≥ 40.0%
mon ≥ 37.5%

L5

fire ≥ 50.0%
mon ≥ 47.5%

L6

fire ≥ 60.0%
mon ≥ 57.5%

L7

fire ≥ 70.0%
mon ≥ 67.5% ⚠ danger

L8

fire ≥ 80.0%
mon ≥ 77.5% ☠ critical

L9

fire ≥ 90.0%
mon ≥ 87.5%

L10

fire ≥ 100.0%
mon ≥ 97.5% (cap)

3. Module Architecture

struct AlamoLevel {
   int       idx;            // 1..10
   double    fireThr;        // N × L1Thr
   double    monThr;         // fireThr − 2.5
   ENUM      state;          // IDLE | MONITOR | ACTIVE
   ulong     ticket;
   double    lot;
   datetime  monitorStart;
   datetime  fireTime;
};

AlamoLevel g_levels[10];

void AlamoOnTick() {
   bool con1 = AlamoCon1AllNegative();   // CACHE 1× per tick
   double ddNow = AlamoCurrentDDPct();
   datetime now = TimeCurrent();

   AlamoProcessL1(con1, ddNow, now);     // L1 special

   for(int i=1; i<AlamoMaxLevels; i++) {
      if(g_levels[i-1].state != ACTIVE) break;   // short-circuit
      AlamoProcessLevel(g_levels[i], con1, ddNow, now);
   }

   AlamoCheckCloseTriggers();   // combined close + redundancy
   AlamoUIRender();             // panel update
}

4. Close Logic Split

TypeOwnerStatus
Per-level self-close (profit ≥ threshold)Mini-module L_nNEW
Combined close (sumProfit ≥ threshold)PosMan overrideKEEP
Redundancy CloseAll (9 sites)Hotfix1KEEP

5. Guard Target — Scope A (.mq5)

Add input:

input bool AlamoOnly = true;   // Test mode: only ALAMO runs, main grid placement gated

Guard với if(!AlamoOnly):

KEEP intact:

Future re-enable: set AlamoOnly=false → main grid + ALAMO chạy song song như Hotfix3

6. Hotfix Lineage

HotfixBug fixedHotfix4 status
Hotfix1 — PosManCloseAlamo (05-13 22:24)Orphan Ln on close-all (5 sites missing AlamoCloseAll)✓ preserved (9 sites intact)
Hotfix2 — L2L3Fire (05-13 23:12)Gate location + N×Thr scaling✓ preserved (fireGate = N×Thr)
Hotfix3 — LotSnowball (05-14 07:58)Lot cascade fix + cooldown 10s✓ preserved (L1-fixed anchor)
Hotfix4 — Modular (05-14 13:47)Strip main grid + per-Ln modular + offset 2.0→2.5🚧 planning

7. UI Panel Mockup

┌─ ALAMO TRACKER ────────────────────┐
│ Stage: ACTIVE   | Next: L3         │
│ DD: 24.32%      | EqAnchor: 277081 │
│ ────────────────────────────────── │
│ L1  ✓ ACTIVE   10%  t=509  +$120   │
│ L2  ✓ ACTIVE   20%  t=512  -$45    │
│ L3  ⏳ MONITOR 30%  pre-arm 27.5%  │
│ L4  ○ IDLE     40%                 │
│ L5  ○ IDLE     50%                 │
│ L6  ○ IDLE     60%                 │
│ (L7-L10 collapsed if IDLE)         │
└────────────────────────────────────┘

8. Verify Datasets

SourceSymbolPeriod
Tester/Agent-127.0.0.1-3000/logs/20260514-Feb18-Feb26.zipXAUUSD.s M502.18 – 02.26
Tester/Agent-127.0.0.1-3000/logs/20260514-Mar18-Mar26.zipXAUUSD.s M503.18 – 03.26
~/Downloads/20260514.logXAUUSD.s M1502.18 – 02.26 (Hotfix2 ref)

9. Phase Breakdown

#PhasePriorityStatus
1Guard main grid with AlamoOnly flag (Scope A)P0TODO
2Refactor FBotAlamo.mqh → per-Ln arrayP0TODO
3State machine IDLE → MONITOR → ACTIVEP0TODO
4Per-level close + global redundancyP0TODO
5UI panel ALAMO trackerP1TODO
6Compile + tester verifyP0TODO

10. Decisions Locked (2026-05-14 14:13)

All decisions locked — ready for implementation.