June 1, 2026 • 6 min read • Agentic Harness Engineering

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:

CheckSignal fieldFLAG condition
Momentum rankmomentum_rankLong with rank < 0.4; Short with rank > 0.6
Hurst exponenthurst_expWARN only — H < 0.5 means mean-reverting
BB z-scorebb_zscoreWARN only — entry in overbought/oversold band
SMA crosssma_cross, sma_20, sma_50Long with death cross; Short with golden cross
Volatilityvol_30dvol > 120% annualized
R/R ratioentry, target, stopR/R < 1.5 for Long; > -1.5 for Short
Position sizingposition_pct> 20% single position; total > 100%
Price anchoringstated_price vs yfinanceModel 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:

  1. Fetches account state (portfolio value, buying power) — returns early if Alpaca is unavailable
  2. Loads existing positions to avoid doubling into held names
  3. For each thesis, checks the validation status — theses with FLAG are skipped by default
  4. Builds a bracket order spec: entry (limit or market), take_profit (limit), stop_loss (stop)
  5. Validates bracket invariants: for Long, take_profit > stop_loss; for Short, take_profit < stop_loss
  6. In dry-run mode, prints the order params. In live mode, posts to POST /v2/orders
  7. Appends an ## Orders section 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.