This is a comprehensive MetaTrader 5 (MT5) trading bot system designed for both demo and real trading environments. The project demonstrates advanced Python development, financial technology integration, web interface development, and process management.
mt5-trading-bot/
โโโ demo-trading/ # Demo trading environment (safe for testing)
โ โโโ main.py # Demo bot implementation
โ โโโ config.py # Demo configuration
โ โโโ .env # Demo credentials (gitignored)
โโโ real-trading/ # Real trading environment (protected)
โ โโโ main.py # Real bot implementation
โ โโโ config.py # Real configuration
โ โโโ .env # Real credentials (gitignored)
โโโ web-interface/ # Flask web dashboard
โ โโโ app.py # Main Flask application
โ โโโ templates/ # HTML templates
โ โโโ static/ # CSS/JS assets
โโโ bot_manager.py # Process-based bot management
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
- Demo Trading: Safe environment for testing strategies without financial risk
- Real Trading: Protected environment with real money trading capabilities
- Web Interface: Centralized control and monitoring dashboard
- Bot Manager: Process-based management to avoid threading issues
- Real trading credentials are gitignored and protected
- Demo environment isolated from real trading
- Environment-specific configurations
- Process isolation for safety
- Backend: Python 3.x with MT5 integration
- Web Framework: Flask for dashboard
- Process Management: Subprocess for bot isolation
- Real-time Communication: WebSocket-like updates via file monitoring
# Key MT5 functions used:
mt5.initialize() # Initialize MT5 connection
mt5.login() # Authenticate with broker
mt5.symbol_info() # Get symbol information
mt5.order_send() # Execute trades
mt5.account_info() # Get account details
- Why Process-Based?: Avoids Python's GIL limitations and threading issues
- Benefits:
- True parallel execution
- Isolated memory spaces
- Crash isolation
- Better resource management
- Real-time Monitoring: Live account balance and trade updates
- Bot Control: Start/stop bots remotely
- Manual Trading: Execute trades through web interface
- Log Viewing: Real-time log monitoring
- Responsive Design: Works on desktop and mobile
- Python 3.8+
- MetaTrader 5 terminal
- Broker account (demo or real)
# Clone the repository
git clone <repository-url>
cd mt5-trading-bot
# Install dependencies
pip install -r requirements.txt
# Set up environment files
cp demo-trading/.env.example demo-trading/.env
cp real-trading/.env.example real-trading/.env
-
Demo Trading Setup:
cd demo-trading # Edit .env with demo account credentials
-
Real Trading Setup:
cd real-trading # Edit .env with real account credentials # โ ๏ธ WARNING: Real money trading
# Demo bot
python demo-trading/main.py
# Real bot (requires confirmation)
python real-trading/main.py
# Start the web dashboard
python web-interface/app.py
# Access at http://localhost:5000
# Start the process-based bot manager
python bot_manager.py
# Features:
# - Start/stop bots
# - Monitor multiple bots
# - Process isolation
# - Crash recovery
- Technical Analysis: RSI, Moving Averages, MACD
- Risk Management: Stop-loss, take-profit, position sizing
- Market Analysis: Real-time price monitoring
- Order Management: Market and limit orders
- Demo/Real Separation: Complete isolation between environments
- Confirmation Dialogs: Real trading requires explicit confirmation
- Error Handling: Comprehensive exception handling
- Logging: Detailed logging for debugging and auditing
- Real-time Updates: Live account and trade monitoring
- Bot Control: Remote start/stop functionality
- Manual Trading: Web-based trade execution
- Log Monitoring: Real-time log viewing
- Responsive UI: Mobile-friendly interface
# .gitignore entries
real-trading/.env
demo-trading/.env
*.log
__pycache__/
- Separate configurations for demo and real trading
- Process-based isolation prevents cross-contamination
- Environment-specific error handling
- Demo environment for strategy testing
- Real trading requires explicit confirmation
- Comprehensive error handling and logging
- Safe for testing strategies
- No financial risk
- Identical functionality to real trading
- Perfect for development and learning
- Requires careful testing in demo first
- Real money trading capabilities
- Enhanced safety measures
- Professional-grade error handling
- Win Rate: Percentage of profitable trades
- Profit Factor: Ratio of gross profit to gross loss
- Drawdown: Maximum peak-to-trough decline
- Sharpe Ratio: Risk-adjusted returns
- Comprehensive logging system
- Real-time log monitoring via web interface
- Error tracking and reporting
- Performance analytics
- Python Development: Advanced Python programming
- Financial Technology: MT5 API integration
- Web Development: Flask web application
- Process Management: Subprocess handling
- Real-time Systems: Live data processing
- Security: Credential management and isolation
- Separation of Concerns: Clear module boundaries
- Error Handling: Comprehensive exception management
- Logging: Detailed audit trails
- Configuration Management: Environment-specific settings
- Process Isolation: Safety through separation
- Trading Concepts: Technical analysis, risk management
- Market Understanding: Real-time data processing
- Broker Integration: MT5 platform knowledge
- Risk Management: Position sizing, stop-losses
- Flask web server for local access
- Process-based bot management
- Real-time monitoring capabilities
- VPS or cloud server recommended
- Process management with systemd
- Reverse proxy (nginx) for web interface
- SSL certificates for security
- "I designed a process-based architecture to avoid Python's GIL limitations"
- "Implemented complete separation between demo and real trading environments"
- "Created a web interface for real-time monitoring and control"
- "All real trading credentials are gitignored and protected"
- "Process isolation prevents cross-contamination between environments"
- "Real trading requires explicit user confirmation"
- "Resolved threading issues by using subprocess management"
- "Implemented comprehensive error handling for financial applications"
- "Created a responsive web interface for mobile and desktop access"
- "Started with basic MT5 integration and evolved to a full trading system"
- "Learned about financial technology and real-time data processing"
- "Gained experience with web development and process management"
- Machine Learning: AI-powered trading strategies
- Multi-Broker Support: Integration with other platforms
- Advanced Analytics: Performance dashboards
- Mobile App: Native mobile application
- Cloud Deployment: AWS/Azure integration
- Database Integration: PostgreSQL for trade history
- Message Queues: Redis for real-time updates
- Microservices: Service-oriented architecture
- Containerization: Docker deployment
For questions about this project:
- Review the code comments for implementation details
- Check the logs for debugging information
- Test thoroughly in demo environment before real trading