ib-trailing-stop
Server-side trailing stop management for stocks and naked LEAPS in IB. Places native TRAIL orders that auto-ratchet the stop as price climbs. Dry-run by default. Requires TWS or IB Gateway running locally.
Install / Use
npx skills add staskh/trading_skills --skill ib-trailing-stopInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Development & EngineeringSupported Platforms
Tags
Our assessment of ib-trailing-stop
ib-trailing-stop scores 89/100 on our quality scale, 1590th of 4,619 Development & Engineering skills we index (top 35%).
Its SKILL.md is 6.3 KB long, well organised into 14 sections with 4 code examples: a thorough specification that gives an agent plenty to work with.
It has 369 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated 17 days ago, so ib-trailing-stop is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands.
Automated pattern scan on 2026-10-05. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
ib-trailing-stop compared with similar skills
All 4 of these similar skills score higher than ib-trailing-stop; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| ib-trailing-stop (this skill)by staskh | 89 | 369 | 17d ago | SKILL.md |
| ai-job-searchby MadsLorentzen | 100 | 45.0k | 1d ago | CLAUDE.md |
| claude-howtoby luongnv89 | 100 | 41.7k | 4d ago | CLAUDE.md |
| algorithmic-artby anthropics | 100 | 177.9k | 12d ago | SKILL.md |
| pptxby anthropics | 100 | 177.9k | 12d ago | SKILL.md |
Frequently asked questions
- How do I install ib-trailing-stop?
- Run
npx skills add staskh/trading_skills --skill ib-trailing-stop. The install tabs above show the steps for each supported agent. - Which AI agents does ib-trailing-stop work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is ib-trailing-stop safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is ib-trailing-stop still maintained?
- The repository was last updated 17 days ago, so ib-trailing-stop is actively maintained.
Skill content
View source on GitHubname: ib-trailing-stop description: Server-side trailing stop management for stocks and naked LEAPS in IB. Places native TRAIL orders that auto-ratchet the stop as price climbs. Dry-run by default. Requires TWS or IB Gateway running locally. dependencies: ["trading-skills"]
IB Trailing Stop Manager
Places IB native TRAIL orders against stocks and naked LEAPS in the portfolio. IB auto-adjusts the stop trigger as the price climbs and locks it as price falls.
PMCC positions are intentionally excluded — use ib-stop-loss for those (a standalone
trailing stop on the PMCC long leg would break the hedge at trigger).
Default mode is dry-run — no orders are placed unless --execute is in the request.
IB Connection
TWS or IB Gateway must be running locally with API enabled:
- Paper trading — port 7497
- Live trading — port 7496
IB_PORTenv var — default port when--portis omitted (e.g.IB_PORT=4001for a Gateway container). Precedence:--portflag >IB_PORT> built-in default. Set it in the shell or a.envfile.
Port fallback: If the configured port fails, automatically retry on the other port. If the retry succeeds, save to memory which account type worked (live/paper) and reuse it for all IB skill calls in this and future sessions — until the user explicitly asks for the other account. If both ports fail, ask the user to verify that TWS or IB Gateway is running with API access enabled.
Instructions
Step 1: Run the script
Dry-run (default — no orders placed):
uv run python .claude/skills/ib-trailing-stop/scripts/trailing_stop.py --symbols JOBY --trail-pct 20
Execute (cancel orphan TS_ orders + place new TS_ TRAIL orders):
uv run python .claude/skills/ib-trailing-stop/scripts/trailing_stop.py --symbols JOBY --trail-pct 20 --execute
Execute forced (cancel + replace existing TS_ orders with current parameters):
uv run python .claude/skills/ib-trailing-stop/scripts/trailing_stop.py --execute --forced
Step 2: Format the report
Format JSON output as a markdown report with three sections:
Section 1: Existing TRAIL Orders
Show all_trail_orders.module (TS_ orders) and all_trail_orders.manual (manually placed).
If orphan_orders is non-empty, warn that these were cancelled (execute mode) or need manual cancellation (dry-run).
Section 2: Positions
For each entry in positions, show a table:
| Field | Value | |---|---| | Symbol | JOBY — stock (1000 shares) | | Spot | $7.50 | | Reference | $7.50 (max of current $7.50, avg cost $5.00) | | Trail params | 20% (initial stop $6.00) → action: place_new | | Existing trail | none |
For LEAPS rows, also show the option leg (strike/expiry) and current option mark.
action values:
place_new— no existing TS_ order; one will be created in execute modepreserve_existing— TS_ already in place; left alone (IB has been tracking the high)overwrite—--forcedis on; existing TS_ will be cancelled and replaced
Section 3: Order Results (execute mode only)
Per-position result with order_id and order_ref.
Step 3: Report to user
- State dry-run vs execute mode prominently.
- Lead with positions that have
action: place_new(these are about to get a new TRAIL). - Call out
preserve_existingseparately so user knows nothing changed. - Show existing trail details (current
trail_stop_price) so user knows where IB has trailed to.
Arguments
| Flag | Default | Description |
|------|---------|-------------|
| --port | 7497 | IB Gateway/TWS port |
| --account | all | Specific account ID |
| --symbols | all | Analyze only these symbols |
| --trail-pct | 20 | Trail amount as percentage of reference |
| --trail-amt | — | Trail amount in dollars (mutually exclusive with --trail-pct) |
| --price-mode | mid | Option pricing: mid or last (LEAPS only) |
| --execute | off | Cancel orphans + place TS_ TRAIL orders |
| --forced | off | Cancel and replace existing TS_ orders (requires --execute) |
JSON Output Structure
{
"generated_at": "2026-05-29 10:00 ET",
"data_delay": "real-time",
"dry_run": true,
"forced": false,
"trail_pct": 20.0,
"trail_amt": null,
"accounts": ["U1234567"],
"symbols_filter": ["JOBY"],
"all_trail_orders": {"module": [], "manual": []},
"orphan_orders": [],
"positions": [
{
"symbol": "JOBY",
"type": "stock",
"account": "U1234567",
"qty": 1000,
"underlying_price": 7.50,
"stock": {
"avg_cost": 5.00,
"current_price": 7.50
},
"trail_stop": {
"trail_pct": 20.0,
"trail_amt": null,
"reference": 7.50,
"initial_stop_price": 6.00,
"action": "place_new",
"existing_trail": null
}
}
]
}
Key Behaviors
- Reference price =
max(current_price, avg_cost)— locks in profit when above cost, never starts below entry. - Forced mode uses
current_priceas the reference (can place an initial stop below entry, useful when re-arming after a drawdown). - Existing TS_ orders are preserved by default because IB has been ratcheting the trail since placement — replacing would reset that tracked high. Use
--forcedto deliberately reset. - Scope: stocks + naked LEAPS only. PMCC positions are excluded; use
ib-stop-lossfor those.
Order Identification
TS_{SYM}_{STRIKE}_{EXPIRY}_{RIGHT}— naked LEAPS TRAIL orders (right isCorPso calls and puts on the same strike/expiry don't collide)TS_{SYM}_STK— stock TRAIL orders
Architecture
All analytics live in src/trading_skills/broker/trailing_stop.py:
Analytics (no IBKR — testable in isolation):
calc_trail_reference—max(current_price, avg_cost)normally;current_priceif forcedcalc_initial_trail_stop_price— reference × (1 − trail_pct/100) or reference − trail_amtidentify_trailable_positions— stocks + naked LEAPS; PMCC excludedbuild_trail_analysis— full per-position output dictdetect_orphan_trail_orders— TS_ TRAIL orders for gone positionssummarize_all_trail_orders— splits IB TRAIL orders into module vs manual
Data layer (IBKR):
get_trailing_stop_data— main entry point_cancel_orphan_orders— cancel stale TS_ orders_place_simple_trail_order— native TRAIL order on stock or option_execute_position_trail— dispatch per position type
Related Skills
ai-job-search
45.0kThe job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.
claude-howto
41.7kA visual, example-driven guide to Claude Code — from basic concepts to advanced agents, with copy-paste templates that bring immediate value.
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
pptx
177.9kUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an em…
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
