Claude
Skills
Sign in
Back

improve-trading-strategies

Included with Lifetime
$97 forever

Iterative refinement, parameter optimization, and ML enhancement of existing trading strategies. Provides 3 tools: refine_strategy (targeted code changes, $0.50-$3.00), optimize_strategy (parameter tuning, $2-$4), enhance_with_allora (ML integration, $1-$2.50). More cost-effective than regenerating from scratch. Use when you have working strategies that need improvement. Always test improvements with test-trading-strategies before deploying.

Code Review

What this skill does


# Improve Trading Strategies

## Quick Start

This skill provides tools to improve existing strategies through refinement, optimization, and ML enhancement.

**Load the tools first**:
```
Use MCPSearch to select: mcp__workbench__refine_strategy
Use MCPSearch to select: mcp__workbench__optimize_strategy
Use MCPSearch to select: mcp__workbench__enhance_with_allora
```

**Quick improvement pattern**:
```
1. Get existing code:
   (use browse-robonet-data) get_strategy_code(strategy_name="MyStrategy")

2. Make targeted changes:
   refine_strategy(
       strategy_name="MyStrategy",
       changes_description="Add trailing stop at 1% below peak profit",
       mode="new"
   )

3. Test improvement:
   (use test-trading-strategies) run_backtest(strategy_name="MyStrategy_refined")
```

**When to use this skill**:
- Have existing strategy that needs improvement
- Want to add features without rewriting from scratch
- Need to tune parameters for better performance
- Want to integrate ML predictions (Allora Network)
- Cheaper than regenerating with `build-trading-strategies`

## Available Tools (3)

### refine_strategy

**Purpose**: Make targeted code changes with AI editing

**Parameters**:
- `strategy_name` (required): Strategy to refine (any version)
- `changes_description` (required): Specific changes you want
- `mode` (required): "new" (create new version, safe) or "replace" (overwrite existing)

**Returns**: Refined strategy code with automatic validation and safety checks

**Pricing**: Real LLM cost + margin (max $3.00)
- Typical: $0.50-$1.50 depending on change complexity

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

**Use when**:
- Making specific code changes (add indicator, change threshold, fix bug)
- Adding features (trailing stop, new exit condition)
- Cheaper than regenerating with create_strategy ($0.50-$3.00 vs $1-$4.50)

**Best practice**: Always use `mode="new"` to preserve original (can compare before/after)

### optimize_strategy

**Purpose**: Tune numeric parameters using backtesting data and AI

**Parameters**:
- `strategy_name` (required): Strategy to optimize
- `start_date` (required): Start date (YYYY-MM-DD)
- `end_date` (required): End date (YYYY-MM-DD)
- `symbol` (required): Trading pair (e.g., "BTC-USDT")
- `timeframe` (required): Timeframe (1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d)

**Returns**: Optimized strategy version with improved parameters + performance comparison (before vs after)

**Pricing**: Real LLM cost + margin (max $4.00)
- Typical: $2.00-$3.50 (most expensive improvement tool)

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

**Use when**:
- Strategy logic is good but parameters need tuning
- Want AI to search parameter space
- Have sufficient backtest data (6+ months recommended)

**Warning**: Can lead to overfitting. Use walk-forward validation.

### enhance_with_allora

**Purpose**: Add Allora Network ML price predictions to strategy logic

**Parameters**:
- `strategy_name` (required): Strategy to enhance
- `symbol` (required): Trading pair
- `timeframe` (required): Timeframe
- `start_date` (required): Start date for comparison backtest
- `end_date` (required): End date for comparison backtest

**Returns**: Enhanced strategy version with ML signals integrated + before/after performance comparison

**Pricing**: Real LLM cost + margin (max $2.50)
- Typical: $1.00-$2.00

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

**Use when**:
- Strategy is profitable but could use ML signals
- Trading BTC, ETH, SOL, or NEAR (Allora coverage)
- Want to combine technical analysis with ML predictions

**Note**: Requires Allora topics available for your symbol/timeframe (check with browse-robonet-data)

## Core Concepts

### Iterative Improvement Pattern

**Recommended improvement sequence**:

```
1. START: Working strategy (tested, decent performance)
   Sharpe: 0.8, Drawdown: 15%, Win rate: 48%

2. REFINE: Fix obvious issues ($0.50-$1.50)
   - Add missing stop loss
   - Fix indicator parameter typo
   - Add position sizing limit
   → New Sharpe: 1.1, Drawdown: 12%

3. TEST: Validate improvement
   - Compare metrics before/after
   - Ensure improvement is real, not noise

4. OPTIMIZE: Tune parameters ($2-$4)
   - Search parameter space for RSI threshold
   - Find optimal Bollinger Band period
   → New Sharpe: 1.4, Drawdown: 10%

5. TEST: Validate optimization
   - Test on out-of-sample data
   - Check for overfitting

6. ENHANCE: Add ML predictions ($1-$2)
   - Integrate Allora Network signals
   - Use ML as confirmation filter
   → New Sharpe: 1.7, Drawdown: 9%

7. TEST: Final validation
   - Compare all metrics end-to-end
   - Decide if ready for deployment

TOTAL COST: ~$4-7 (much cheaper than regenerating 3-4 times at $2.50 each = $7.50-$10)
```

### Optimization Best Practices

**Avoiding overfitting**:

**What is overfitting?**
- Parameters tuned to past data perform poorly on new data
- Strategy "memorizes" historical noise instead of learning patterns
- Common with excessive optimization

**How to avoid**:

**1. Use sufficient data** (6+ months minimum):
```
optimize_strategy(
    strategy_name="MyStrategy",
    start_date="2024-01-01",
    end_date="2024-12-31",  # 12 months
    symbol="BTC-USDT",
    timeframe="1h"
)
```

**2. Walk-forward validation**:
```
# Train on first 8 months
optimize_strategy(..., start_date="2024-01-01", end_date="2024-08-31")

# Test on last 4 months (use test-trading-strategies)
run_backtest(..., start_date="2024-09-01", end_date="2024-12-31")

# Performance should be similar on test period
# If much worse → overfitted
```

**3. Limit optimization iterations**:
- 1st optimization: Often yields 20-30% improvement
- 2nd optimization: Yields 10-15% improvement
- 3rd optimization: Yields <5% improvement (diminishing returns)
- 4th+ optimization: Often makes performance worse (overfitting)

**Stop after 2-3 optimization rounds**

**4. Compare multiple metrics** (not just one):
```
Before optimization: Sharpe 1.0, Drawdown 15%, Win rate 52%
After optimization: Sharpe 1.3, Drawdown 14%, Win rate 54%

✓ Multiple metrics improved consistently → Good
✗ Sharpe jumped to 3.0 but drawdown 40% → Overfitted/risky
```

**5. Keep parameter ranges reasonable**:
- RSI: 10-20 (not 2-100)
- Moving average: 20-200 (not 1-1000)
- Stop loss: 1-5% (not 0.1-50%)

### Allora Network ML Integration

**What Allora provides**:
- ML-powered price predictions
- Multiple horizons: 5m, 8h, 24h, 1 week
- Assets: BTC, ETH, SOL, NEAR
- Networks: Mainnet (production) + Testnet (experimental)

**How to use ML predictions**:

**Pattern 1: ML as confirmation filter**
```
Original strategy: Buy when RSI < 30
Enhanced strategy: Buy when RSI < 30 AND Allora predicts price increase

→ Reduces false signals, improves win rate
```

**Pattern 2: ML as primary signal**
```
Original strategy: Trend following with EMA
Enhanced strategy: Buy when Allora predicts strong upward movement + EMA confirms

→ ML catches moves early, EMA confirms trend
```

**Pattern 3: ML for position sizing**
```
Original strategy: Fixed 90% margin position size
Enhanced strategy:
- 95% margin when Allora confidence high
- 85% margin when Allora confidence medium
- 70% margin when Allora confidence low

→ Adaptive sizing based on prediction confidence
```

**Before using enhance_with_allora**:

```
1. Check Allora topic availability (use browse-robonet-data):
   get_allora_topics()
   → Verify your symbol has predictions

2. Match prediction horizon to strategy timeframe:
   - 5m scalping strategy → Use 5m predictions
   - 1h swing strategy → Use 8h predictions
   - 4h daily strategy → Use 24h predictions

3. Test before/after:
   - enhance_with_allora automatically runs comparison backtest
   - Check improvement metrics
   - ML should improve Sharpe by 10-30% (not 200%—that's unrealistic)
```

**Realistic ML improvement expectations**:
- **10-30% Sharpe improvement**: Good, realistic
- **30-50% improvement**: Excellent (verify it's real, not overfitting)
- **>50% improvement**: Suspicious, li

Related in Code Review