A production-ready AI-powered algorithmic trading system that combines machine learning models with MetaTrader 5 for automated trading execution.
- Multi-Model AI Engine: LSTM, XGBoost, LightGBM, and TCN models for market prediction
- Real-time Trading: Direct integration with MetaTrader 5 for live trading
- Advanced Risk Management: Position sizing, drawdown control, and exposure limits
- Comprehensive Feature Engineering: 50+ technical indicators and market features
- Auto-Retraining System: Automatic model updates based on performance metrics
- Real-time Monitoring: Streamlit dashboard and Telegram alerts
- Backtesting Framework: Walk-forward analysis and strategy optimization
- Docker Deployment: Containerized microservices architecture
- Architecture
- Installation
- Configuration
- Usage
- Components
- API Reference
- Testing
- Deployment
- Monitoring
- Contributing
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Trading System β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β MT5 EA ββββββ Bridge ββββββ Signal β β
β β (MQL5) β β (Socket/File)β β Generator β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β² β
β β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Data βββββΊβ Feature βββββΊβ Model β β
β β Manager β β Engineering β β Training β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Risk β β Monitoring β β Backtest β β
β β Management β β Dashboard β β Framework β β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Python 3.9+
- MetaTrader 5 Terminal
- Docker and Docker Compose (for containerized deployment)
- PostgreSQL (optional, for production deployment)
- Clone the repository:
git clone https://github.com/yourusername/ai-trading-system.git
cd ai-trading-system- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
make install
# Or manually: pip install -r requirements.txt- Copy environment variables:
cp .env.example .env
# Edit .env with your credentials# Build and start all services
make deploy
# Or step by step:
docker-compose build
docker-compose up -d
make init-dbsystem:
name: "AI Trading System"
version: "1.0.0"
environment: "production"
data:
mt5:
login: ${MT5_LOGIN}
password: ${MT5_PASSWORD}
server: ${MT5_SERVER}
collection:
symbols: ["EURUSD", "GBPUSD", "USDJPY"]
timeframe: "H1"
history_days: 365
models:
types: ["lstm", "xgboost", "lightgbm"]
ensemble:
enabled: true
voting: "soft"
risk:
max_positions: 5
max_risk_per_trade: 0.02 # 2%
max_daily_loss: 0.05 # 5%
max_exposure: 0.2 # 20%# MT5 Credentials
MT5_LOGIN=your_mt5_login
MT5_PASSWORD=your_mt5_password
MT5_SERVER=your_mt5_server
# Telegram Bot
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Database
POSTGRES_USER=trading_user
POSTGRES_PASSWORD=secure_password
POSTGRES_DB=ai_trading_db# Train models for all configured symbols
python scripts/train_models.py --config config/main_config.yaml
# Train for specific symbol
python scripts/train_models.py --symbol EURUSD
# Train specific model type
python scripts/train_models.py --model-type lstm# Start all services
make up
# View logs
make logs
# Stop services
make down# Terminal 1: Run main trading system
python src/main.py
# Terminal 2: Run monitoring dashboard
streamlit run src/monitoring/dashboard.py
# Terminal 3: Run auto-retrain system
python scripts/run_auto_retrain.py# Run backtest
python scripts/run_backtest.py \
--start-date 2023-01-01 \
--end-date 2023-12-31 \
--symbol EURUSD
# Walk-forward analysis
python scripts/run_walk_forward.py \
--window-size 180 \
--step-size 30Handles data collection from MT5 and external sources:
from src.data import DataManager
manager = DataManager(config)
data = manager.load_data(
symbol='EURUSD',
source='mt5',
start_date=datetime(2023, 1, 1),
end_date=datetime(2023, 12, 31)
)Creates 50+ technical indicators and market features:
from src.features import TradingFeatureEngineer
engineer = TradingFeatureEngineer(config)
features = engineer.create_features(data)Generates trading signals using trained models:
from src.signals import SignalGenerator
generator = SignalGenerator(config)
generator.load_model('models/trained/EURUSD_lstm.pkl', 'lstm')
signal = generator.generate_signal('EURUSD', 'lstm')Manages position sizing and risk limits:
from src.risk import RiskManager
risk_manager = RiskManager(config)
position_size = risk_manager.calculate_position_size(
symbol='EURUSD',
account_info=account_info,
symbol_info=symbol_info,
stop_loss_pips=50
)Access the monitoring dashboard at http://localhost:8501
Features:
- Real-time performance metrics
- Active trades monitoring
- Signal history
- Risk metrics visualization
- System logs
Configure Telegram bot to receive:
- Trade signals
- Trade executions
- Risk warnings
- System errors
- Daily performance summaries
# Run all tests
make test
# Run unit tests only
python tests/run_tests.py --type unit
# Run integration tests
python tests/run_tests.py --type integration
# Run with coverage
pytest tests/ --cov=src --cov-report=html- Environment Setup:
# Copy and configure environment
cp .env.example .env
# Edit .env with production credentials- Deploy with Docker:
# Deploy all services
./scripts/deploy.sh
# Or use make
make deploy- Health Check:
# Check system health
python scripts/health_check.py
# Or use make
make health-check# Create backup
make backup
# Restore from backup
make restore BACKUP_FILE=backup_20240115_120000.tar.gz{
"symbol": "EURUSD",
"signal": "BUY",
"confidence": 0.85,
"timestamp": "2024-01-15T10:30:00",
"price": 1.0850,
"features": {
"rsi": 35.2,
"macd": 0.0012,
"volume_ratio": 1.2
}
}- Host: 0.0.0.0
- Port: 5555
- Protocol: JSON over TCP
- Signal file: /shared/signals.json
- Command file: /shared/commands.json
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and research purposes only. Trading carries substantial risk and you should not trade with money you cannot afford to lose. Past performance is not indicative of future results.
- MetaTrader 5 for trading platform integration
- TensorFlow/Keras for deep learning models
- XGBoost and LightGBM teams
- Streamlit for dashboard framework
π€ Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com