Skip to content

Creating a Trading Strategy

Step-by-step guide to creating a new trading strategy with TradAI.

Quick Start

Create a new strategy with a single command:

tradai strategy new MyMomentumStrategy

This creates a complete strategy package in the current directory with: - Strategy implementation (src/my_momentum_strategy/strategy.py) - Configuration files (configs/backtest.json, tradai.yaml) - Tests (tests/) - Dockerfile for deployment

Strategy Creation Options

Basic Options

# Create strategy with specific timeframe and category
tradai strategy new MyStrategy --timeframe 4h --category momentum

# Create scalping strategy with short positions
tradai strategy new ScalpBot --category scalping --timeframe 5m --can-short

# Create ML-powered strategy
tradai strategy new MLStrategy --ml freqai

# Skip test generation
tradai strategy new QuickTest --no-tests

Configuration Options

Customize initial configuration during creation:

tradai strategy new MyStrategy \
  --exchange bybit \
  --trading-mode futures \
  --stake-currency USDT \
  --symbols "BTC/USDT:USDT,ETH/USDT:USDT" \
  --max-trades 5 \
  --stake-amount 1000 \
  --stoploss -0.05 \
  --trailing-stop

Non-Interactive Mode

Skip all prompts with -y:

tradai strategy new MyStrategy -y --category trend-following

Interactive Wizard

For guided strategy creation with recommendations:

tradai strategy wizard

The wizard walks you through: 1. Strategy Name - Your strategy identifier 2. Category Selection - Trading style with descriptions 3. Timeframe - Candle interval with category-based recommendations 4. Exchange - Target exchange (Binance, Bybit, OKX, etc.) 5. Trading Mode - Spot or futures 6. Risk Settings - Stoploss, stake amount 7. Summary - Review before creation

Strategy Categories

Category Best For Recommended Timeframe
trend-following Capturing directional moves 1h, 4h, 1d
momentum Riding strong movements 15m, 1h
mean-reversion Fading extreme moves 1h, 4h
breakout Trading range expansions 15m, 1h
scalping Quick small trades 1m, 5m
grid-trading Range-bound markets 15m, 1h
dca Dollar-cost averaging 4h, 1d
arbitrage Price discrepancies 1m

Generated Strategy Structure

my_momentum_strategy/
├── src/
│   └── my_momentum_strategy/
│       ├── __init__.py
│       ├── strategy.py      # Main strategy logic
│       └── py.typed
├── tests/
│   ├── __init__.py
│   └── test_strategy.py     # Unit tests
├── configs/
│   ├── backtest.json        # Backtest configuration
│   └── tradai.yaml          # TradAI settings
├── Dockerfile               # Container build
├── pyproject.toml           # Package definition
└── README.md                # Strategy documentation

Implementing Your Strategy

Edit src/my_momentum_strategy/strategy.py:

from freqtrade.strategy import IStrategy
import talib as ta

class MyMomentumStrategy(IStrategy):
    # Strategy parameters
    timeframe = "1h"
    startup_candle_count = 50  # Required for indicator warmup

    def populate_indicators(self, dataframe, metadata):
        """Add indicators to the dataframe."""
        dataframe["rsi"] = ta.RSI(dataframe["close"], timeperiod=14)
        dataframe["ema_fast"] = ta.EMA(dataframe["close"], timeperiod=12)
        dataframe["ema_slow"] = ta.EMA(dataframe["close"], timeperiod=26)
        return dataframe

    def populate_entry_trend(self, dataframe, metadata):
        """Define entry conditions."""
        dataframe.loc[
            (dataframe["rsi"] < 30) &
            (dataframe["ema_fast"] > dataframe["ema_slow"]),
            "enter_long"
        ] = 1
        return dataframe

    def populate_exit_trend(self, dataframe, metadata):
        """Define exit conditions."""
        dataframe.loc[
            (dataframe["rsi"] > 70),
            "exit_long"
        ] = 1
        return dataframe

Testing Your Strategy

Lint for Common Issues

tradai strategy lint MyMomentumStrategy

Checks for: - Look-ahead bias (using future data) - Missing startup_candle_count - Repainting indicators - Invalid parameter combinations

Run Unit Tests

just test-package strategies/my_momentum_strategy

Test Indicator Logic

Before backtesting, validate your indicators work:

tradai indicator test "ta.RSI(df['close'], 14)" --symbol BTC/USDT:USDT

Next Steps

After creating your strategy:

  1. Edit Strategy Logic - Implement your trading rules
  2. Test Indicators - Validate with tradai indicator test
  3. Lint Strategy - Check for issues with tradai strategy lint
  4. Run Backtest - Test with historical data (see Backtesting Guide)

Listing Strategies

View all available strategies:

tradai strategy list

Get detailed info about a specific strategy:

tradai strategy info MyMomentumStrategy

Quick Reference

Command Description
tradai strategy new NAME Create new strategy
tradai strategy wizard Interactive creation
tradai strategy list List all strategies
tradai strategy info NAME Strategy details
tradai strategy lint NAME Check for issues