/add-strategy
Create a new trading strategy for the ai-trader backtesting framework. Handles file creation, registration, docstrings, and backtest scaffolding.
$ npx -y skills add whchien/ai-trader --skill add-strategy --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/add-strategy
Context preview
The summary Claude sees to decide when to auto-load this skill.
Create a new trading strategy for the ai-trader backtesting framework. Handles file creation, registration, docstrings, and backtest scaffolding.
SKILL.md
add-strategy.SKILL.mdname: add-strategy
description: Create a new trading strategy for the ai-trader backtesting framework. Handles file creation, registration, docstrings, and backtest scaffolding.
disable-model-invocation: true
argument-hint: "[strategy-type: classic|portfolio]"
allowed-tools: "Read, Write, Edit, Glob, Grep, Bash"
add-strategy Skill
Create a new trading strategy for the ai-trader backtesting framework with automatic file generation, registration, and validation.
Overview
This skill automates the creation of trading strategies following established patterns in the ai-trader project. It handles:
- File creation with proper naming conventions (PascalCase class → snake_case filename)
- Comprehensive docstrings (module and class level)
- Parameter validation and defaults
- Automatic registration in `__init__.py` files
- Standalone backtest scaffolding
- Pre-flight validation for name conflicts and custom indicators
Two strategy types are supported:
- **Classic**: Single-stock strategies (e.g., DoubleTopStrategy, BBandsStrategy)
- **Portfolio**: Multi-asset rotation strategies (e.g., ROCRotationStrategy, MultiBBandsRotationStrategy)
Interactive Workflow
The skill guides you through the following steps:
Step 1: Strategy Type
Confirm whether this is a classic (single-stock) or portfolio (multi-asset) strategy.
Step 2: Name & Description
- Provide the strategy name in PascalCase (e.g., "MACDBBands")
- Provide a 1-2 sentence description
- The skill automatically converts to snake_case for the filename (macd_bbands.py)
Step 3: Parameters
Define parameters as comma-separated `name=value` pairs:
- Example: `fast=12, slow=26, signal=9, bb_period=20`
- All parameters must have default values
- Parameter names must be valid Python identifiers
Step 4: Entry & Exit Logic
- Describe the entry condition (buy signal)
- Describe the exit condition (sell signal)
- For portfolio strategies, describe rotation/rebalancing logic
Step 5: Custom Indicators (Optional)
If your strategy uses custom indicators from `indicators.py`, list them:
- Available: DoubleTop, RSRS, NormRSRS, RecentHigh, TripleRSI, etc.
- The skill verifies they exist and generates the import statement
Step 6: Preview & Confirmation
Review the generated file structure before creation:
- Target file path
- Class name and type
- Parameters
- Files to be modified (__init__.py imports and __all__)
Step 7: Creation & Verification
The skill creates:
- Strategy file with complete structure
- Updates imports and __all__ list in __init__.py
- Validates syntax by attempting import
- Shows git status for verification
Usage Examples
Creating a Classic Strategy
$ /add-strategy classic
Creating a classic single-stock strategy.
What should we name this strategy? (e.g., "BollingerBreakout")
> MACDBBands
Brief description (1-2 sentences)?
> Combines MACD for trend and Bollinger Bands for entry timing
Parameters with defaults? (e.g., "fast=12, slow=26, signal=9, bb_period=20")
> fast=12, slow=26, signal=9, bb_period=20, bb_dev=2
Entry condition (buy signal)?
> MACD crosses above signal line AND price below lower Bollinger Band
Exit condition (sell signal)?
> MACD crosses below signal line OR price above upper Bollinger Band
Any custom indicators from indicators.py? (e.g., DoubleTop, RSRS)
> No
[Preview shown]
Proceed with creation? (yes/no)
> yes
✓ Created macd_bbands.py
✓ Updated classic/__init__.py (added import)
✓ Updated classic/__init__.py (added to __all__)
✓ Verified file is importable
Next steps:
1. Test standalone: python ai_trader/backtesting/strategies/classic/macd_bbands.py
2. Review generated code and refine logic
3. Test via CLI: ai-trader quick MACDBBandsStrategy your_data.csv
4. Check changes: git diff
5. Commit when ready
Creating a Portfolio Strategy
$ /add-strategy portfolio
Creating a portfolio multi-asset strategy.
What should we name this strategy? (e.g., "MomentumRotation")
> TripleEMARotation
Brief description?
> Rotates portfolio to assets with strongest triple EMA alignment
Parameters?
> short_ema=10, med_ema=20, long_ema=50, top_k=5
Rotation/Rebalancing logic?
> Rotate monthly to top-5 assets where all three EMAs are bullishly aligned
Custom indicators?
> No
[Preview shown]
Proceed with creation? (yes/no)
> yes
✓ Created triple_ema_rotation.py
✓ Updated portfolio/__init__.py (added import)
✓ Updated portfolio/__init__.py (added to __all__)
✓ Verified file is importable
File Templates
Classic Strategy Template
"""
[Strategy Name]
[1-2 sentence description of what the strategy does and the market conditions it targets.]
"""
import backtrader as bt
from ai_trader.backtesting.strategies.base import BaseStrategy
# [Add custom indicator imports if needed]
# from ai_trader.backtesting.strategies.indicators import CustomIndicator
class [StrategyName]Strategy(BaseStrategy):
"""
[Strategy Name] - [One-line tagline describing the core approach].
[Detailed description paragraph explaining the trading logic, market conditions,
and why this strategy works in those conditions.]
Entry Logic (Buy):
- Condition 1
- Condition 2
Exit Logic (Sell):
- Condition 1
- Condition 2
Parameters:
- param_name (type): Description [default: value]
Notes:
- Insight 1
- Insight 2
"""
params = dict(param1=value1, param2=value2)
def __init__(self):
"""Initialize indicators and signals."""
super().__init__()
# Initialize indicators here
# self.indicator = bt.indicators.SMA(self.data)
def next(self):
"""Execute trading logic each bar."""
if self.position.size == 0:
# Check buy signal and enter
pass
else:
# Check exit signal and close
pass
if __name__ == "__main__":
from ai_trader.utils.backtest import run_backtest
# Run backtest with [StratRead more
name: add-strategy description: Create a new trading strategy for the ai-trader backtesting framework. Handles file creation, registration, docstrings, and backtest scaffolding. disable-model-invocation: true argument-hint: "[strategy-type: classic|portfolio]" allowed-tools: "Read, Write, Edit, Glob, Grep, Bash"
add-strategy Skill
Create a new trading strategy for the ai-trader backtesting framework with automatic file generation, registration, and validation.
Overview
This skill automates the creation of trading strategies following established patterns in the ai-trader project. It handles:
- File creation with proper naming conventions (PascalCase class → snake_case filename)
- Comprehensive docstrings (module and class level)
- Parameter validation and defaults
- Automatic registration in `__init__.py` files
- Standalone backtest scaffolding
- Pre-flight validation for name conflicts and custom indicators
Two strategy types are supported:
- **Classic**: Single-stock strategies (e.g., DoubleTopStrategy, BBandsStrategy)
- **Portfolio**: Multi-asset rotation strategies (e.g., ROCRotationStrategy, MultiBBandsRotationStrategy)
Interactive Workflow
The skill guides you through the following steps:
Step 1: Strategy Type
Confirm whether this is a classic (single-stock) or portfolio (multi-asset) strategy.
Step 2: Name & Description
- Provide the strategy name in PascalCase (e.g., "MACDBBands")
- Provide a 1-2 sentence description
- The skill automatically converts to snake_case for the filename (macd_bbands.py)
Step 3: Parameters
Define parameters as comma-separated `name=value` pairs:
- Example: `fast=12, slow=26, signal=9, bb_period=20`
- All parameters must have default values
- Parameter names must be valid Python identifiers
Step 4: Entry & Exit Logic
- Describe the entry condition (buy signal)
- Describe the exit condition (sell signal)
- For portfolio strategies, describe rotation/rebalancing logic
Step 5: Custom Indicators (Optional)
If your strategy uses custom indicators from `indicators.py`, list them:
- Available: DoubleTop, RSRS, NormRSRS, RecentHigh, TripleRSI, etc.
- The skill verifies they exist and generates the import statement
Step 6: Preview & Confirmation
Review the generated file structure before creation:
- Target file path
- Class name and type
- Parameters
- Files to be modified (__init__.py imports and __all__)
Step 7: Creation & Verification
The skill creates:
- Strategy file with complete structure
- Updates imports and __all__ list in __init__.py
- Validates syntax by attempting import
- Shows git status for verification
Usage Examples
Creating a Classic Strategy
$ /add-strategy classic Creating a classic single-stock strategy. What should we name this strategy? (e.g., "BollingerBreakout") > MACDBBands Brief description (1-2 sentences)? > Combines MACD for trend and Bollinger Bands for entry timing Parameters with defaults? (e.g., "fast=12, slow=26, signal=9, bb_period=20") > fast=12, slow=26, signal=9, bb_period=20, bb_dev=2 Entry condition (buy signal)? > MACD crosses above signal line AND price below lower Bollinger Band Exit condition (sell signal)? > MACD crosses below signal line OR price above upper Bollinger Band Any custom indicators from indicators.py? (e.g., DoubleTop, RSRS) > No [Preview shown] Proceed with creation? (yes/no) > yes ✓ Created macd_bbands.py ✓ Updated classic/__init__.py (added import) ✓ Updated classic/__init__.py (added to __all__) ✓ Verified file is importable Next steps: 1. Test standalone: python ai_trader/backtesting/strategies/classic/macd_bbands.py 2. Review generated code and refine logic 3. Test via CLI: ai-trader quick MACDBBandsStrategy your_data.csv 4. Check changes: git diff 5. Commit when ready
Creating a Portfolio Strategy
$ /add-strategy portfolio Creating a portfolio multi-asset strategy. What should we name this strategy? (e.g., "MomentumRotation") > TripleEMARotation Brief description? > Rotates portfolio to assets with strongest triple EMA alignment Parameters? > short_ema=10, med_ema=20, long_ema=50, top_k=5 Rotation/Rebalancing logic? > Rotate monthly to top-5 assets where all three EMAs are bullishly aligned Custom indicators? > No [Preview shown] Proceed with creation? (yes/no) > yes ✓ Created triple_ema_rotation.py ✓ Updated portfolio/__init__.py (added import) ✓ Updated portfolio/__init__.py (added to __all__) ✓ Verified file is importable
File Templates
Classic Strategy Template
"""
[Strategy Name]
[1-2 sentence description of what the strategy does and the market conditions it targets.]
"""
import backtrader as bt
from ai_trader.backtesting.strategies.base import BaseStrategy
# [Add custom indicator imports if needed]
# from ai_trader.backtesting.strategies.indicators import CustomIndicator
class [StrategyName]Strategy(BaseStrategy):
"""
[Strategy Name] - [One-line tagline describing the core approach].
[Detailed description paragraph explaining the trading logic, market conditions,
and why this strategy works in those conditions.]
Entry Logic (Buy):
- Condition 1
- Condition 2
Exit Logic (Sell):
- Condition 1
- Condition 2
Parameters:
- param_name (type): Description [default: value]
Notes:
- Insight 1
- Insight 2
"""
params = dict(param1=value1, param2=value2)
def __init__(self):
"""Initialize indicators and signals."""
super().__init__()
# Initialize indicators here
# self.indicator = bt.indicators.SMA(self.data)
def next(self):
"""Execute trading logic each bar."""
if self.position.size == 0:
# Check buy signal and enter
pass
else:
# Check exit signal and close
pass
if __name__ == "__main__":
from ai_trader.utils.backtest import run_backtest
# Run backtest with [StratA professional, config-driven backtesting framework for algorithmic trading, built on Backtrader. Seamlessly test, optimize, and integrate trading strategies with Large Language Models (LLMs) across stocks, crypto, and forex markets.

