A proof of concept that integrates the backtrader library with a modern web frontend. The goal was to build an intuitive UI with Streamlit and Plotly that puts trading tools—including backtesting, live alerts, and market data visualization—into a single, web application.
- Multiple Data Sources: Support for Yahoo Finance (stocks/crypto) and Binance (crypto)
- All Backtrader Indicators: Support for 30+ indicators including RSI, CCI, Bollinger Bands, MACD, SMA, EMA, and more
- Multi-Timeframe Analysis: Analyze multiple timeframes simultaneously (5m, 15m, 30m, 1h, 2h, 4h, 1d)
- Flexible Strategies:
- Simple Indicator Strategy: Single indicator with customizable entry/exit conditions
- RSI Crossover Strategy: Classic oversold/overbought strategy
- Multi-Indicator Strategy: Combine multiple indicators with complex conditions
- Multi-Timeframe Strategy: Cross-timeframe analysis and alerts
- Telegram Alerts: Real-time trade notifications via Telegram
- Streamlit GUI: Interactive web interface for backtesting and analysis
- CLI Support: Command-line interface for automated workflows
- Comprehensive Results: Detailed trade history, performance metrics, and visualizations
- Clone the repository:
git clone https://github.com/yourusername/backtraderalerts.git
cd backtraderalerts- Install dependencies:
pip install -r requirements.txt- Configure settings (optional):
cp config/config.yaml.example config/config.yaml
# Edit config/config.yaml with your settingsLaunch the Streamlit interface:
python main.py --mode guiOr directly:
streamlit run src/gui/streamlit_app.pyRun a backtest from the command line:
python main.py --mode backtest --symbol BTC-USD --interval 1d --start-date 2023-01-01-
Create a Telegram bot:
- Message @BotFather on Telegram
- Use
/newbotcommand - Save the bot token
-
Get your chat ID:
- Message your bot
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find your chat ID in the response
-
Add to configuration:
- In GUI: Enter in the sidebar
- In config file: Update
telegramsection
The system supports all major Backtrader indicators organized by category:
Momentum Indicators:
- RSI, CCI, Stochastic, Williams %R, ROC
Trend Indicators:
- SMA, EMA, WMA, DEMA, TEMA, ADX, MACD, Ichimoku
Volatility Indicators:
- Bollinger Bands, ATR, Standard Deviation, Keltner Channel, Donchian Channel
Volume Indicators:
- OBV, A/D, MFI, Chaikin Money Flow
Other Indicators:
- Parabolic SAR, Pivot Points, ZigZag
- Simple Indicator Strategy: Use any single indicator with customizable entry/exit rules
- RSI Crossover Strategy: Classic RSI oversold/overbought strategy
- Multi-Indicator Strategy: Combine multiple indicators with complex conditions (AND/OR logic, crossovers)
- Multi-Timeframe Strategy: Analyze multiple timeframes simultaneously with conditions like:
- "Buy when 1h close > SMA(200) AND 4h RSI < 30"
- "Sell when daily close crosses below EMA(50)"
- "Alert when 4h price crosses above $50,000"
backtraderalerts/
├── src/
│ ├── data/ # Data fetching modules
│ ├── strategies/ # Trading strategies
│ ├── alerts/ # Alert dispatchers
│ ├── engine/ # Backtrader engine
│ ├── gui/ # Streamlit interface
│ └── config/ # Configuration management
├── config/ # Configuration files
├── logs/ # Log files
├── main.py # Main entry point
├── requirements.txt # Python dependencies
└── README.md # This file
-
Configure Settings:
- Open sidebar
- Enter Telegram credentials (optional)
- Set trading parameters
-
Run Backtest:
- Select symbol and date range
- Configure strategy parameters
- Click "Run Backtest"
-
Analyze Results:
- View portfolio performance chart
- Check buy/sell signals on price chart
- Review trade history table
- Download results as CSV
Basic backtest:
python main.py --mode backtest --symbol AAPL --interval 1dWith custom parameters:
python main.py --mode backtest \
--symbol BTC-USD \
--interval 4h \
--start-date 2023-06-01 \
--end-date 2023-12-31 \
--rsi-period 21 \
--rsi-oversold 25 \
--rsi-overbought 75Using config file:
python main.py --mode backtest --config my_config.yaml --symbol ETH-USD- Create a new file in
src/strategies/ - Inherit from
backtrader.Strategy - Implement
__init__,next, and optional logging methods - Update GUI to include new strategy option
Example:
class MyStrategy(bt.Strategy):
params = (
('param1', 10),
('param2', 20),
)
def __init__(self):
# Initialize indicators
pass
def next(self):
# Trading logic
pass- Update
DataFetcherclass insrc/data/fetcher.py - Add new source to
fetch_datamethod - Update configuration options
-
"No module named 'backtrader'"
- Run:
pip install -r requirements.txt
- Run:
-
Telegram alerts not working
- Verify bot token and chat ID
- Check internet connection
- Ensure bot has messaged you first
-
Data fetch errors
- Check symbol format (e.g., BTC-USD for Yahoo Finance)
- Verify date range is valid
- Check internet connection
## Contributing
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request
## License
This project is licensed under the MIT License - see the LICENSE file for details.
## Acknowledgments
- [Backtrader](https://www.backtrader.com/) - Python backtesting library
- [Streamlit](https://streamlit.io/) - Web app framework
- [yfinance](https://github.com/ranaroussi/yfinance) - Yahoo Finance data
- [python-telegram-bot](https://python-telegram-bot.org/) - Telegram bot API