|
| 1 | +--- |
| 2 | +name: decode |
| 3 | +description: Reverse-engineer trading strategies from external signal history. Decode, formalize, backtest, and register. |
| 4 | +user_invocable: true |
| 5 | +--- |
| 6 | + |
| 7 | +# /decode — Strategy Decoder Session |
| 8 | + |
| 9 | +## Purpose |
| 10 | + |
| 11 | +Reverse-engineer a trading strategy from raw trade signals. Turn someone |
| 12 | +else's track record into a systematic, backtestable strategy definition. |
| 13 | + |
| 14 | +## Workflow |
| 15 | + |
| 16 | +### Step 0: Read Context |
| 17 | +- Read `.claude/memory/strategy_registry.md` — avoid decoding what we already have |
| 18 | +- Read `.claude/memory/workshop_lessons.md` — known pitfalls apply here too |
| 19 | + |
| 20 | +### Step 1: Ingest Raw Signals |
| 21 | +Accept signals from one of: |
| 22 | +- **Manual paste:** user provides a list of trades |
| 23 | +- **File upload:** CSV/JSON with trade history |
| 24 | +- **`decode_from_trades`:** analyze our own closed_trades or fills |
| 25 | + |
| 26 | +Each signal must have: `symbol`, `direction`, `entry_time`, `entry_price`, |
| 27 | +`exit_time`, `exit_price`. Optional: `size`, `notes`. |
| 28 | + |
| 29 | +### Step 2: Clean and Normalize |
| 30 | +- Validate required fields are present |
| 31 | +- Parse timestamps (supports multiple formats) |
| 32 | +- Flag and report missing/invalid data |
| 33 | +- Minimum 20 signals recommended; warn if fewer |
| 34 | + |
| 35 | +### Step 3: Decode via MCP |
| 36 | +Call `decode_strategy(signals, source_name)`. |
| 37 | + |
| 38 | +Review the output: |
| 39 | +- **entry_trigger**: What timing and conditions drive entries? |
| 40 | +- **exit_trigger**: Time-based or target-based exits? |
| 41 | +- **timing_pattern**: Morning, midday, afternoon, or all-day? |
| 42 | +- **style**: Scalper, intraday, swing, or position? |
| 43 | +- **regime_affinity**: Which regimes favor this strategy? |
| 44 | +- **edge_hypothesis**: The one-sentence thesis |
| 45 | + |
| 46 | +### Step 4: Evaluate the Decoded Strategy |
| 47 | +Ask yourself: |
| 48 | +- Does the edge hypothesis make sense from a market microstructure perspective? |
| 49 | +- Is the timing pattern exploitable systematically (or just coincidence)? |
| 50 | +- Is the win rate sustainable, or is it likely overstated by survivorship bias? |
| 51 | +- Is the sample size sufficient (>50 signals ideal)? |
| 52 | + |
| 53 | +### Step 5: Formalize into StrategyDefinition |
| 54 | +Translate the decoded patterns into formal entry/exit rules: |
| 55 | +```json |
| 56 | +{ |
| 57 | + "entry_rules": [ |
| 58 | + {"indicator": "<indicator from decoded entry_trigger>", |
| 59 | + "condition": "<condition>", "value": <threshold>, "direction": "long"} |
| 60 | + ], |
| 61 | + "exit_rules": [ |
| 62 | + {"indicator": "<exit trigger indicator>", |
| 63 | + "condition": "<condition>", "value": <threshold>} |
| 64 | + ], |
| 65 | + "parameters": {"<relevant indicator params>": <values>}, |
| 66 | + "risk_params": {"stop_loss_atr": 2.0, "position_pct": 0.03} |
| 67 | +} |
| 68 | +``` |
| 69 | +Set conservative risk params initially — decoded strategies have |
| 70 | +higher uncertainty than workshop strategies. |
| 71 | + |
| 72 | +### Step 6: Register |
| 73 | +Call `register_strategy` with `source="decoded"`, `status="draft"`. |
| 74 | + |
| 75 | +### Step 7: Backtest |
| 76 | +Call `run_backtest(strategy_id, symbol)`. |
| 77 | +Apply the same criteria as /workshop: |
| 78 | +- Sharpe > 1.0? |
| 79 | +- Max drawdown < 15%? |
| 80 | +- Total trades > 50? |
| 81 | + |
| 82 | +### Step 8: Validate or Reject |
| 83 | +If backtest passes → `run_walkforward` → if passes: |
| 84 | + `update_strategy(status="forward_testing")` |
| 85 | +If fails → `update_strategy(status="failed")` |
| 86 | + |
| 87 | +### Step 9: Update Memory |
| 88 | +- `.claude/memory/strategy_registry.md` — add decoded strategy |
| 89 | +- `.claude/memory/workshop_lessons.md` — new patterns discovered |
| 90 | +- `.claude/memory/session_handoffs.md` — notify /meta and /trade |
| 91 | + |
| 92 | +## Notes |
| 93 | +- Decoded strategies should be treated with MORE skepticism than workshop |
| 94 | + strategies. The original trader may have had information we don't have. |
| 95 | +- Always check: is the edge in the timing, the signal, or the risk management? |
| 96 | + Timing edges are hardest to systematize. |
| 97 | +- Sample size matters enormously. 20 trades is the absolute minimum. |
| 98 | + 50+ is preferred. 100+ is high confidence. |
0 commit comments