AI Trading: Lesson Learned #110: Trailing Stops Script Existed But Never Executed
Source: Dev.to
Problem
A paper account held $1,113 in unrealized profits that were unprotected because the trailing‑stop script was never run.
scripts/set_trailing_stops.pywas created on Jan 7 2026 but never executed.- The
daily-trading.ymlworkflow contained no step to set trailing stops.
Unprotected Positions (excerpt from data/system_state.json)
{
"symbol": "INTC260109P00035000",
"unrealized_pl": 151.0
},
{
"symbol": "SOFI260123P00024000",
"unrealized_pl": 56.0
},
{
"symbol": "AMD260116P00200000",
"unrealized_pl": 457.0
},
{
"symbol": "SPY260123P00660000",
"unrealized_pl": 449.0
}
Total at risk: $1,113 in profits.
Why the Script Was Not Used
- The script existed as a standalone file:
scripts/set_trailing_stops.py. - It was referenced only in
claude-agent-utility.yml(manual trigger). - It was absent from the
daily-trading.ymlworkflow, meaning:- Positions were never automatically protected.
- Manual execution was required each run.
- A single market gap could erase all profits.
Fix Implemented
Added an automatic step to daily-trading.yml:
- name: Set Trailing Stop-Loss Orders (Phil Town Rule 1)
if: success()
env:
ALPACA_API_KEY: ${{ secrets.ALPACA_PAPER_KEY }}
ALPACA_SECRET_KEY: ${{ secrets.ALPACA_PAPER_SECRET }}
run: |
python3 scripts/set_trailing_stops.py
Core Rules Reinforced
- Rule #1: Don’t lose money.
- Rule #2: Don’t forget Rule #1.
Our system was violating both by:
- Holding profits without protection.
- Relying on hope instead of stop‑losses.
Lessons Learned
- A risk‑protection script is useless if it requires manual execution.
- Every risk‑management tool must be integrated into the automated CI/CD workflow immediately after creation.
- Add a verification step to confirm the
trailing_stopssection exists insystem_state.json.
Tags: trailing_stops, risk_management, phil_town, rule_1, automation_gap, ci_integration
This lesson was auto‑published from our AI Trading repository.
More lessons: rag_knowledge/lessons_learned