AI Trading: Lesson Learned #110: Trailing Stops Script Existed But Never Executed

Published: (January 7, 2026 at 05:03 PM EST)
2 min read
Source: Dev.to

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.py was created on Jan 7 2026 but never executed.
  • The daily-trading.yml workflow 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.yml workflow, 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

  1. Rule #1: Don’t lose money.
  2. 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_stops section exists in system_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

Back to Blog

Related posts

Read more »

AI SEO agencies Nordic

!Cover image for AI SEO agencies Nordichttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads...