The Trading Skills: /validate-trades and /execute-trades
Two skills that close the loop between LLM-generated trading theses and live market execution. /validate-trades runs eight deterministic technical analysis checks against every thesis in a file — no LLM involved, pure Python rules against a local signals database. /execute-trades builds GTC bracket orders from the theses that pass validation and submits them to Alpaca, dry-run by default.
A trading thesis generated by the harness contains structured fields — entry price, target, stop, position size — alongside a [THESIS:direction:ticker:rationale:date] citation anchor. These structured fields are machine-parseable. /validate-trades uses them to run deterministic checks before any capital is committed. /execute-trades consumes the same file, reads the validation status, and skips any thesis that carries a FLAG.
/validate-trades: deterministic TA checks
/validate-trades is a post_wiggum skill that auto-activates on trading thesis keywords — "long thesis", "trade setup", "alpaca", and similar. It runs after the Wiggum loop has already scored the thesis for quality; validation checks technical consistency separately from prose quality.
The parser extracts each thesis block using ## Thesis N: headers and reads structured fields via regex:
_FIELD = {
"direction": re.compile(r"\*\*Direction\*\*:\s*(Long|Short)", re.IGNORECASE),
"ticker": re.compile(r"\*\*Ticker\*\*:\s*([A-Z]{1,6})\b"),
"entry": re.compile(r"\*\*Entry\*\*[^$]*\$([0-9]+(?:\.[0-9]+)?)"),
"target": re.compile(r"\*\*Target\*\*[^$]*\$([0-9]+(?:\.[0-9]+)?)"),
"stop": re.compile(r"\*\*Stop\*\*[^$]*\$([0-9]+(?:\.[0-9]+)?)"),
"position_pct": re.compile(r"\*\*Suggested position size\*\*:\s*([0-9]+(?:\.[0-9]+)?)\s*%"),
"stated_price": re.compile(r"(?:Current\s+)?Price[:\-]\s*\$\s*([0-9,]+(?:\.[0-9]+)?)"),
}
After parsing, the validator loads the latest signal row per ticker from data/trending-tickers-unified.db and runs eight rule-based checks:
| Check | Signal field | FLAG condition |
|---|---|---|
| Momentum rank | momentum_rank | Long with rank < 0.4; Short with rank > 0.6 |
| Hurst exponent | hurst_exp | WARN only — H < 0.5 means mean-reverting |
| BB z-score | bb_zscore | WARN only — entry in overbought/oversold band |
| SMA cross | sma_cross, sma_20, sma_50 | Long with death cross; Short with golden cross |
| Volatility | vol_30d | vol > 120% annualized |
| R/R ratio | entry, target, stop | R/R < 1.5 for Long; > -1.5 for Short |
| Position sizing | position_pct | > 20% single position; total > 100% |
| Price anchoring | stated_price vs yfinance | Model price deviates > 5% from live price |
Overall status is the worst individual check result: one FLAG makes the thesis FLAG, one WARN makes it WARN, otherwise PASS. The validator appends a ## Trade Validation section to the thesis file and returns the path.
The price anchoring check catches the most common failure mode in LLM-generated theses: the model writes entry/target/stop prices based on its training data or on a stale context block rather than the live price injected by the [YF:ticker:snapshot:date] context. A thesis where the "current price" is 5% off the live yfinance price is using stale data.
/execute-trades: bracket orders to Alpaca
# Dry-run (default) — prints order params without submitting
python agent.py "/execute-trades path/to/thesis.md"
# Live mode — submits bracket orders to Alpaca paper trading
python agent.py "/execute-trades path/to/thesis.md --live"
The skill calls execute_from_thesis_file() from alpaca_orders.py which uses the same parser as /validate-trades. It then:
- Fetches account state (portfolio value, buying power) — returns early if Alpaca is unavailable
- Loads existing positions to avoid doubling into held names
- For each thesis, checks the validation status — theses with FLAG are skipped by default
- Builds a bracket order spec: entry (limit or market), take_profit (limit), stop_loss (stop)
- Validates bracket invariants: for Long,
take_profit > stop_loss; for Short,take_profit < stop_loss - In dry-run mode, prints the order params. In live mode, posts to
POST /v2/orders - Appends an
## Orderssection to the thesis file with the results
All orders use GTC (Good Till Cancelled) time-in-force with whole-share quantities. Fractional shares are not used because Alpaca's bracket order class requires integer quantities with GTC.
/execute-trades has no auto-activation predicate and is explicitly listed as "never auto-execute trades" in its registry entry. It is always explicit-only. Even in live mode, any thesis carrying a FLAG validation status is skipped by default — override with the skip_flagged=False argument if you want to submit flagged theses, but this is not exposed via the CLI flag by design.
The full workflow: run a trading thesis task to generate the file, /validate-trades auto-fires as a post_wiggum skill and appends the validation section, then run /execute-trades thesis.md to dry-run the orders and review them before adding --live. The thesis file accumulates all three sections (thesis body, validation, orders) in one document that serves as the complete audit trail.