Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Add a Custom Strategy

Scan logic is fully isolated in app/strategies/ — adding a new strategy requires no changes to app/bot.py.

Step 1 — Create app/strategies/my_strategy.py

import pandas as pd
from app.strategies.base import BaseStrategy
from app.config import cfg

class MyStrategy(BaseStrategy):
    name = "my_strategy"

    def scan(self, df: pd.DataFrame, symbol: str, bot_name: str) -> dict:
        bbot = cfg.bot(bot_name)
        # ... analysis logic ...
        return {
            "symbol"   : symbol,
            "bot"      : bot_name,
            "direction": "buy",          # "buy" | "sell" | "skip"
            "price"    : float(df.iloc[-1]["c"]),
            "checklist": [{"name": "Condition X", "pass": True, "detail": "..."}],
            "passed"   : 1,
            "total"    : 1,
            "ask_coo"  : True,
            "sl_pct"   : bbot.stop_loss_pct,
            "tp_pct"   : bbot.take_profit_pct,
        }

Step 2 — Register in app/strategies/__init__.py

from app.strategies.my_strategy import MyStrategy
# ...
_registry = {
    ...
    MyStrategy.name: MyStrategy,   # ← add this line
}

Step 3 — Activate in config.toml

[strategy]
default = "my_strategy"