Create a New Strategy¶
Build a trading strategy in 5 minutes.
graph TD
Root["MyStrategy.py<br/><i>Freqtrade entry point</i>"] --> Src["src/mystrategy/strategy.py<br/><i>Main logic</i>"]
Src --> Entities["entities.py<br/><i>Pydantic models</i>"]
Src --> Constants["constants.py<br/><i>Config values</i>"]
Src --> TradAI["tradai-strategy<br/><i>Base class + metadata</i>"]
Config["configs/<br/>backtest.json<br/>freqai_training.json"] -.-> Root
Tests["tests/<br/>test_strategy.py"] -.->|validates| Src Quick Start¶
Important: Run this command from the
tradairepository root. If running from elsewhere, setTRADAI_ROOT=/path/to/tradai.
# Interactive wizard (recommended)
tradai strategy wizard
# Or one-liner
tradai strategy new MyMomentumStrategy \
--category momentum --timeframe 1h --can-short -y
This generates a complete strategy package:
Note: The strategy is created in your current directory. Use
-o /path/to/dirto specify a different output location.
mymomentstrategy/
├── MyMomentumStrategy.py # Root-level strategy (Freqtrade discovery)
├── Dockerfile # Container build
├── README.md
├── .pre-commit-config.yaml
├── pyproject.toml
├── tradai.yaml # Strategy configuration
├── configs/
│ ├── backtest.json # Backtest configuration
│ └── freqai_training.json # FreqAI training config
├── src/mymomentumstrategy/
│ ├── __init__.py
│ ├── strategy.py # Main strategy implementation
│ ├── constants.py
│ ├── entities.py
│ └── exceptions.py
└── tests/
├── __init__.py
├── conftest.py
└── test_strategy.py
Implement¶
Edit strategy.py — implement three required methods:
from tradai.strategy import TradAIStrategy, StrategyMetadata, StrategyCategory
class MyMomentumStrategy(TradAIStrategy):
timeframe = "1h"
can_short = True
stoploss = -0.05
def get_metadata(self) -> StrategyMetadata:
return StrategyMetadata(
name="MyMomentumStrategy", version="1.0.0",
description="Momentum-based trading strategy",
category=StrategyCategory.MOMENTUM, timeframe=self.timeframe,
)
def populate_indicators(self, dataframe, metadata):
# Add your indicators here
return dataframe
def populate_entry_trend(self, dataframe, metadata):
# Set enter_long=1 / enter_short=1 signals
return dataframe
def populate_exit_trend(self, dataframe, metadata):
# Set exit_long=1 / exit_short=1 signals
return dataframe
Test and Backtest¶
# Run tests
cd mymomentstrategy && uv run pytest tests/ -v
# Quick backtest
tradai backtest quick MyMomentumStrategy --local --period 30d
Next Steps¶
- Full Strategy Creation Guide — Hyperopt parameters, modular structure, LoggerMixin, testing patterns
- Your First Backtest — Analyze backtest results
- Strategy Templates — Ready-to-use templates