An autonomous forex trading system that scans multiple currency pairs, analyzes market structure with Smart Money Concepts (SMC), detects market regimes, and routes each setup through one of five specialized strategies. Claude powers the decision layer; OANDA executes trades; Telegram and a live Streamlit dashboard keep you informed around the clock.
Live dashboard: http://198.199.80.67:8501
Deployed on a DigitalOcean Ubuntu server running 24/7.
Every 15 minutes the bot:
- Checks session timing, economic calendar, and news sentiment
- Scans active pairs across multiple timeframes (M15, H1, H4, D)
- Runs technical indicators, SMC analysis, and regime detection
- Selects the best strategy for current conditions
- Asks Claude for a structured BUY / SELL / HOLD decision
- Validates the signal against risk rules and strategy constraints
- Places trades via OANDA with dynamic position sizing
- Manages open trades (partial take-profit, breakeven stops)
- Logs everything to SQLite and sends Telegram alerts
- Runs a self-learning feedback loop on closed trades
The strategy library automatically switches based on regime, SMC bias, macro filters, and volatility:
| Strategy | Best For | Approach |
|---|---|---|
| Trend Following | Strong trends (ADX > 30) | Buy pullbacks in uptrends, sell rallies in downtrends |
| Mean Reversion | Ranging / weak-trend markets | Trade from range extremes back to the mean |
| Breakout | Compression & volatility expansion | Enter on confirmed breakouts with wider stops |
| SMC Institutional | Order blocks & liquidity sweeps | Enter at institutional zones after stop hunts |
| News Fade | Post-news spikes | Fade overreactions after high-impact events |
- Dynamic risk management — position size scales with account balance and current drawdown
- Tiered position sizing — smaller accounts use higher risk %; large accounts cap at 1%
- Max 3 open trades — hard limit enforced every cycle
- 1:2 R:R minimum — every trade targets at least 2× the stop distance
- Daily loss limit — stops trading and closes positions at −3% daily drawdown
- Drawdown protection — reduces size at −10%, halts at −15% from peak
- Correlation filter — avoids stacking correlated pairs (e.g. EUR/USD + GBP/USD)
- Telegram alerts — trade opens/closes, daily summaries, errors, kill-switch events
- Self-learning loop — Claude reviews closed trades and updates trading rules
- Backtesting engine — test strategy logic on historical data without API calls
- Live Streamlit dashboard — balance, open trades, performance stats, news feed
| Layer | Technology |
|---|---|
| Language | Python 3.11+ |
| Broker | OANDA REST API v20 |
| AI Brain | Anthropic Claude API |
| Dashboard | Streamlit + Plotly |
| Data | pandas, ta (Technical Analysis library), yfinance |
| Database | SQLite |
| Alerts | Telegram Bot API |
| Hosting | DigitalOcean Ubuntu (24/7 systemd service) |
trading_ai/
├── main.py # Standard autonomous loop
├── main_advanced.py # Full v4 system (5 strategies + SMC + regime)
├── scheduler.py # Cron-style job scheduler
├── daily_review.py # End-of-day performance review
│
├── broker/ # OANDA connection & order management
├── data/ # Price feed, indicators, SMC, regime, macro
├── brain/ # Claude decisions, risk, execution, strategies
├── intelligence/ # News, calendar, sentiment, sessions, COT
├── learning/ # Trade journal & self-learning feedback
├── dashboard/ # Streamlit app & Telegram alerts
├── backtest/ # Historical backtesting engine
└── database/ # SQLite (gitignored — created at runtime)
git clone https://github.com/Abdrakib/forex-trading-bot.git
cd forex-trading-botpython -m venv venv
source venv/bin/activate # Linux / macOS
# venv\Scripts\activate # Windows
pip install -r requirements.txtImportant:
.envis excluded from this repository and must never be committed. Copy the example file and fill in your own keys:
cp .env.example .envEdit .env with your credentials:
OANDA_API_KEY=your_oanda_api_key_here
OANDA_ACCOUNT_ID=your_account_id_here
OANDA_ENVIRONMENT=practice
OANDA_BASE_URL=https://api-fxpractice.oanda.com
ANTHROPIC_API_KEY=your_anthropic_api_key_here
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
TELEGRAM_CHAT_ID=your_telegram_chat_id_here| Variable | Description |
|---|---|
OANDA_API_KEY |
OANDA v20 API token |
OANDA_ACCOUNT_ID |
OANDA account ID (e.g. 101-001-1234567-001) |
OANDA_ENVIRONMENT |
practice or live |
OANDA_BASE_URL |
https://api-fxpractice.oanda.com (practice) or https://api-fxtrade.oanda.com (live) |
ANTHROPIC_API_KEY |
Anthropic API key for Claude |
TELEGRAM_BOT_TOKEN |
Bot token from @BotFather |
TELEGRAM_CHAT_ID |
Your Telegram chat ID for alerts |
The database is created automatically on first run:
python main_advanced.pystreamlit run dashboard/app.py --server.port 8501# Full advanced system (recommended)
python main_advanced.py
# Standard multi-pair scanner
python main.py
# Backtest on historical data
python backtest/engine.py
# Generate HTML performance report
python backtest/report.pyThe production instance runs on an Ubuntu droplet as a systemd service:
# Example service unit
sudo systemctl enable trading-ai
sudo systemctl start trading-ai
# Dashboard
sudo systemctl enable trading-dashboard
sudo systemctl start trading-dashboardThe bot loops every 15 minutes, scans session-appropriate pairs, and manages trades autonomously. Monitor via the live dashboard or Telegram alerts.
This software is for educational and research purposes. Forex trading carries substantial risk of loss. Past backtest performance does not guarantee future results. Always start on an OANDA practice account before using real capital. The authors are not responsible for any financial losses incurred through use of this software.
MIT — use at your own risk.