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.
npx skills add https://github.com/staskh/trading_skills --skill ib-trailing-stop
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.
TWS or IB Gateway must be running locally with API enabled:
IB_PORT env var — default port when --port is omitted (e.g. IB_PORT=4001 for a Gateway container). Precedence: --port flag > IB_PORT > built-in default. Set it in the shell or a .env file.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.
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
Format JSON output as a markdown report with three sections:
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).
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 — --forced is on; existing TS_ will be cancelled and replacedPer-position result with order_id and order_ref.
action: place_new (these are about to get a new TRAIL).preserve_existing separately so user knows nothing changed.trail_stop_price) so user knows where IB has trailed to.| 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) |
{
"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
}
}
]
}
max(current_price, avg_cost) — locks in profit when above cost, never starts below entry.current_price as the reference (can place an initial stop below entry, useful when re-arming after a drawdown).--forced to deliberately reset.ib-stop-loss for those.TS_{SYM}_{STRIKE}_{EXPIRY}_{RIGHT} — naked LEAPS TRAIL orders (right is C or P so calls and puts on the same strike/expiry don't collide)TS_{SYM}_STK — stock TRAIL ordersAll 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_price if 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 manualData 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 typeAutomatically organizes invoices and receipts for tax preparation by reading messy files, extracting key information, renaming them consistently, and sorting them into logical folders. Turns hours of manual bookkeeping into minutes of automated organization.
Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.
This skill calculates key financial ratios and metrics from financial statement data for investment analysis
This skill provides an advanced financial modeling suite with DCF analysis, sensitivity testing, Monte Carlo simulations, and scenario planning for investment decisions
This skill retrieves upcoming earnings announcements for US stocks using the Financial Modeling Prep (FMP) API. Use this when the user requests earnings calendar data, wants to know which companies are reporting earnings in the upcoming week, or needs a weekly earnings review. The skill focuses on mid-cap and above companies (over $2B market cap) that have significant market impact, organizing the data by date and timing in a clean markdown table format. Supports multiple environments (CLI, Desktop, Web) with flexible API key management.
Crypto wallet operations via the awal CLI — sign in, check balances, send USDC/ETH/POL/SOL, trade tokens, fund the wallet, and use the x402 payment protocol to discover paid services, pay for API calls, monetize an API, or query onchain data. Use whenever the user mentions signing in, login, authentication, wallet status, balance, address, sending money, paying someone, transferring tokens, ENS names, swapping/trading/converting tokens, funding/topping up/onramp, USDC, ETH, POL, SOL, the x402 bazaar, paid APIs, monetizing an endpoint, or querying onchain data on Base.
Access real-time and historical stock market data, forex rates, cryptocurrency prices, commodities, economic indicators, and 50+ technical indicators via the Alpha Vantage API. Use when fetching stock prices (OHLCV), company fundamentals (income statement, balance sheet, cash flow), earnings, options data, market news/sentiment, insider transactions, GDP, CPI, treasury yields, gold/silver/oil prices, Bitcoin/crypto prices, forex exchange rates, or calculating technical indicators (SMA, EMA, MACD, RSI, Bollinger Bands). Requires a free API key from alphavantage.co.
Braintree Automation: manage payment processing via Stripe-compatible tools for customers, subscriptions, payment methods, and transactions
Take staskh/ib-trailing-stop from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.