# Current Close Control Flow Map

Static source basis:
- KOUCHA_GOLD_KIWAMI_SURVIVAL_TICK.mq5 SHA256: 30490B2D7AAC6C0197CC65B326A7728E82A8E62759E7E9202741EF851430CA9B
- No mqh dependency was found in the inspected source set.

Important order:
1. OnTick reads positions and computes `hardStop = IsHardStopTriggeredByBasis(ps, marginLevel)` at line 2136.
2. Diagnostic stage traces at lines 2137-2163 pass `hardStop=false` intentionally for pre-HardStop stage labeling.
3. The disabled-by-default S2 pre-HardStop helper is called at lines 2164-2171.
4. Normal existing close flow continues: global retry, reactive/market-close control, `CheckBasketRecoveryClose`, BasketClose, other exits, then HardStop side-effect gate.
5. `CheckBasketRecoveryClose` computes a local `hardStopNow` at line 11264 before current posthedge runtime exit gate, so CW8/B2/L1/RF-style runtime exits placed there are structurally late for pre-HardStop rescue.
6. The actual HardStop order-send gate is lines 2405-2424.
7. All actual closes eventually pass through `CloseAllEaPositions` lines 11366-11495.

Design implication:
- A real TA9 emergency close would need a structural slot before the HardStop side-effect gate.
- The only source-anchored candidate is inside OnTick after the pre-HardStop stage trace and before the disabled S2 helper call.
- Shadow logging can be added there without behavior change.
- Actual order sending from that location remains a future, explicit priority/order design decision.

See current_close_control_flow_map.csv for per-path line ranges and side effects.
