Claude
Skills
Sign in
Back

build-trading-strategies

Included with Lifetime
$97 forever

AI-powered generation of complete trading strategy code. Uses create_strategy and create_prediction_market_strategy to transform requirements into production-ready Python code. Most expensive AI tool ($1.00-$4.50 per generation). Generates complete Jesse framework strategies with entry/exit logic, position sizing, and risk management. Use after exploring data and optionally generating ideas. ALWAYS test with test-trading-strategies before deploying.

Code Review

What this skill does


# Build Trading Strategies

## Quick Start

This skill generates complete, production-ready strategy code using AI. This is the **most expensive tool** in Robonet ($1-$4.50 per generation).

**Load the tools first**:
```
Use MCPSearch to select: mcp__workbench__create_strategy
Use MCPSearch to select: mcp__workbench__create_prediction_market_strategy
```

**Basic usage**:
```
create_strategy(
    strategy_name="RSIMeanReversion_M",
    description="Buy when RSI(14) < 30 and price at lower Bollinger Band (20,2).
                 Sell when RSI > 70 or price at middle Bollinger Band.
                 Stop loss at 2% below entry. Position size 90% of available margin."
)
```

Returns complete Python strategy code ready for backtesting.

**When to use this skill**:
- You have a clear strategy concept and want working code
- You've explored data and know what indicators/symbols to use
- You're ready to commit to expensive development ($1-$4.50)

**When NOT to use this skill**:
- You're still exploring ideas → Use `design-trading-strategies` first ($0.05-$1.00)
- You have existing code to improve → Use `improve-trading-strategies` ($0.50-$3.00)
- You haven't checked data availability → Use `browse-robonet-data` first (free-$0.001)

## Available Tools (2)

### create_strategy

**Purpose**: Generate complete crypto trading strategy code with AI

**Parameters**:
- `strategy_name` (required, string): Name following pattern `{Name}_{RiskLevel}[_suffix]`
  - Risk levels: H (high), M (medium), L (low)
  - Examples: "RSIMeanReversion_M", "MomentumBreakout_H_v2"
- `description` (required, string): Detailed requirements including:
  - Entry conditions (specific indicator values and thresholds)
  - Exit conditions (stop loss, take profit, trailing stops)
  - Position sizing (percentage of margin to use)
  - Risk management (max loss per trade)
  - Indicators to use (exact names from browse-robonet-data)
  - Timeframe context (5m scalping vs 1h swing trading)

**Returns**: Complete Python strategy code with:
- `should_long()` - Check if conditions met for long entry
- `should_short()` - Check if conditions met for short entry
- `go_long()` - Execute long entry with position sizing
- `go_short()` - Execute short entry with position sizing
- Optional methods: `on_open_position()`, `update_position()`, `should_cancel_entry()`

**Pricing**: Real LLM cost + margin (max $4.50)
- Typical cost: $1.00-$3.00 depending on complexity
- Most expensive tool in Robonet

**Execution Time**: ~30-60 seconds

**Use when**:
- Building new crypto perpetual trading strategy
- You have clear, detailed requirements
- You've verified indicators/symbols available (browse-robonet-data)
- Ready to commit to expensive operation

### create_prediction_market_strategy

**Purpose**: Generate Polymarket strategy code with YES/NO token trading logic

**Parameters**:
- `strategy_name` (required, string): Name following same pattern as create_strategy
- `description` (required, string): Detailed requirements for YES/NO token logic:
  - Conditions for buying YES tokens (probability thresholds)
  - Conditions for buying NO tokens
  - Exit criteria (profit targets, time-based exits)
  - Position sizing (percentage per market)
  - Market selection criteria (categories, liquidity requirements)

**Returns**: Complete Python strategy code with:
- `should_buy_yes()` - Check if conditions met for YES token entry
- `should_buy_no()` - Check if conditions met for NO token entry
- `go_yes()` - Execute YES token purchase with sizing
- `go_no()` - Execute NO token purchase with sizing
- Optional methods: `should_sell_yes()`, `should_sell_no()`, `on_market_resolution()`

**Pricing**: Real LLM cost + margin (max $4.50)
- Typical cost: $1.00-$3.00

**Execution Time**: ~30-60 seconds

**Use when**:
- Building Polymarket prediction market strategies
- Trading on real-world events (politics, economics, sports)
- Want YES/NO token exposure based on probability analysis

## Core Concepts

### Jesse Framework Structure

**All crypto strategies must implement these required methods**:

```python
class MyStrategy(Strategy):
    def should_long(self) -> bool:
        """Check if all conditions are met for long entry"""
        # Return True to signal long entry opportunity
        # Called every candle

    def should_short(self) -> bool:
        """Check if all conditions are met for short entry"""
        # Return True to signal short entry opportunity
        # Called every candle

    def go_long(self):
        """Execute long entry with position sizing"""
        # Calculate position size (qty)
        # Place buy order
        # Set stop loss and take profit in on_open_position()

    def go_short(self):
        """Execute short entry with position sizing"""
        # Calculate position size (qty)
        # Place sell order
        # Set stop loss and take profit in on_open_position()
```

**Optional but recommended methods**:

```python
    def on_open_position(self, order):
        """Set stop loss and take profit after entry"""
        # Called when position opens
        # Set self.stop_loss and self.take_profit

    def update_position(self):
        """Update position (trailing stops, etc.)"""
        # Called every candle while in position
        # Modify stop loss for trailing stops

    def should_cancel_entry(self) -> bool:
        """Cancel unfilled entry orders"""
        # Return True to cancel pending entry order
```

### Strategy Naming Convention

**Follow this pattern**: `{Name}_{RiskLevel}[_suffix]`

**Risk Levels**:
- **H** (High): Aggressive strategies, high leverage, tight stops, >20% drawdown acceptable
- **M** (Medium): Balanced strategies, moderate leverage, standard stops, 10-20% drawdown
- **L** (Low): Conservative strategies, low leverage, wide stops, <10% drawdown

**Examples**:
- `RSIMeanReversion_M` - Base strategy, medium risk
- `MomentumBreakout_H_optimized` - After optimization, high risk
- `TrendFollower_L_allora` - With Allora ML enhancement, low risk
- `BollingerBands_M_v2` - Version 2 of strategy

**Why naming matters**:
- Helps organize strategies by risk profile
- Clear versioning (_v2, _v3) tracks evolution
- Suffixes (_optimized, _allora) indicate enhancements
- Consistent naming enables easy filtering and comparison

### Position Sizing Patterns

**Recommended position sizing**: 85-95% of available margin

**Common approaches**:

**1. Fixed percentage** (simple, predictable):
```python
def go_long(self):
    qty = utils.size_to_qty(self.balance * 0.90, self.price)
    self.buy = qty, self.price
```

**2. Volatility-based** (adaptive to market conditions):
```python
def go_long(self):
    atr = ta.atr(self.candles, period=14)
    # Reduce size in high volatility
    size_multiplier = 0.90 if atr < self.price * 0.02 else 0.70
    qty = utils.size_to_qty(self.balance * size_multiplier, self.price)
    self.buy = qty, self.price
```

**3. Risk-based** (size based on stop loss distance):
```python
def go_long(self):
    atr = ta.atr(self.candles, period=14)
    stop_distance = atr * 2  # Stop at 2× ATR
    # Risk 2% of balance per trade
    risk_amount = self.balance * 0.02
    qty = risk_amount / stop_distance
    self.buy = qty, self.price
```

**Best practice**: Specify position sizing approach in description when creating strategy

### Risk Management Requirements

**Every strategy should include**:

**1. Stop Loss** (mandatory):
```python
def on_open_position(self, order):
    atr = ta.atr(self.candles, period=14)
    # Stop at 2× ATR below entry (long) or above entry (short)
    self.stop_loss = qty, self.price - (atr * 2)  # Long
    # or
    self.stop_loss = qty, self.price + (atr * 2)  # Short
```

**2. Take Profit** (recommended):
```python
def on_open_position(self, order):
    atr = ta.atr(self.candles, period=14)
    # Target at 3× ATR (risk/reward = 1.5)
    self.take_profit = qty, self.price + (atr * 3)  # Long
```

**3. Position sizing** (see above)

**Red flags** (av

Related in Code Review