A restart silently disabled our trailing stop — and the crash fix is what hid it
Description and use
On restart the bot failed to carry over the stop‑loss distance, causing trailing stops never to arm and ladder rules to cut positions. The fix retrieves the original distance from the trade ledger and adds safeguards.
Problem
When the bot restarts, it rebuilds positions without the stop‑loss distance, causing trailing stops never to arm and ladder rules to incorrectly cut positions.
Outcome
The bot now correctly arms trailing stops after 2R profit and no longer cuts recovered positions as dead weight; the silent failure is eliminated.
Workflow
- 1. Bot restarts and runs recovery code.
- 2. Recovery code builds position objects from broker data, missing sl_dist field.
- 3. Default sl_dist becomes 0, leading to divide‑by‑zero guard skipping trailing stop and ladder rule.
- 4. Guard silently suppresses errors, no log output.
- 5. Issue discovered when analyzing trade performance and noticing missing 2R gains.
- 6. Fix implemented: lookup sl_dist from ledger and pass it during recovery.
- 7. Additional safeguards added: safe defaults, hit counters, and audit logs.
Evidence
When our bot restarts, it takes back ownership of positions that are already open. To do that it rebuilds its internal picture of each position — and it forgot to carry over one number: the distance to the stop‑loss.
The guard is the interesting bit. Someone — correctly — noticed that dividing by zero would crash the bot, so they wrote: if the distance is zero or less, skip the trailing stop.
On restart the bot now looks the original stop distance up in its own trade ledger by ticket number and passes it in, along with the position size.
- Record date: 2026-10-09T22:55:50.315Z