refactor: restructure repository and add README, CLAUDE.md, LICENSE

- Move utility scripts to scripts/ (check_market, check_positions, etc.)
- Move test files to tests/ (test_modules, test_mt5_connection, etc.)
- Move deprecated dashboards to archive/
- Move research files to docs/research/
- Add sys.path fix to all moved Python files
- Rewrite README.md with architecture diagram and badges
- Add CLAUDE.md project guide
- Add MIT LICENSE
- Update .gitignore with archive/ pattern

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
GifariKemal
2026-02-06 13:22:46 +07:00
co-authored by Claude Opus 4.6
parent 20dc1385c3
commit 0d25548ed5
25 changed files with 364 additions and 82 deletions
+179 -74
View File
@@ -1,19 +1,112 @@
# Smart Automatic Trading BOT + AI
# XAUBot AI
An intelligent automated trading system for XAUUSD (Gold) using Machine Learning and Smart Money Concepts (SMC).
**AI-powered XAUUSD (Gold) trading bot** with XGBoost ML, Smart Money Concepts (SMC), and HMM regime detection for MetaTrader 5.
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![MetaTrader 5](https://img.shields.io/badge/broker-MetaTrader%205-orange.svg)](https://www.metatrader5.com/)
---
## Features
- **ML-Powered Predictions**: XGBoost model with 37 features for market direction prediction
- **Smart Money Concepts (SMC)**: Order Blocks, Fair Value Gaps, Break of Structure, Change of Character
- **HMM Regime Detection**: Hidden Markov Model for market regime classification
- **Dynamic Risk Management**: ATR-based stop loss, position sizing, and smart exits
- **Session-Aware Trading**: Optimized for different market sessions (Sydney, London, NY)
- **Auto-Retraining**: Models automatically retrain based on market conditions
- **Telegram Notifications**: Real-time trade alerts and market updates
- **Web Dashboard**: Real-time monitoring interface
| Feature | Description |
|---------|-------------|
| **XGBoost ML Model** | 37-feature model predicting BUY/SELL/HOLD with calibrated confidence |
| **Smart Money Concepts** | Order Blocks, Fair Value Gaps, Break of Structure, Change of Character |
| **HMM Regime Detection** | 3-state Hidden Markov Model classifying trending/ranging/volatile markets |
| **Dynamic Risk Management** | ATR-based stop loss, Kelly criterion sizing, daily loss limits |
| **Session-Aware Trading** | Optimized for Sydney, London, and New York sessions |
| **Auto-Retraining** | Models automatically retrain when market conditions shift |
| **Telegram Alerts** | Real-time trade notifications and daily summaries |
| **Web Dashboard** | Next.js monitoring interface for live tracking |
## Performance (Backtest Jan 2025 - Feb 2026)
## Architecture
```
┌─────────────────┐
│ MetaTrader 5 │
│ (XAUUSD M15) │
└────────┬─────────┘
│ OHLCV
┌────────▼─────────┐
│ Data Pipeline │
│ (Polars Engine) │
└────────┬─────────┘
┌─────────────────┼─────────────────┐
│ │ │
┌────────▼───────┐ ┌──────▼───────┐ ┌───────▼──────┐
│ SMC Analyzer │ │ Feature Eng │ │ HMM Regime │
│ (OB/FVG/BOS) │ │ (37 features) │ │ Detector │
└────────┬───────┘ └──────┬───────┘ └───────┬──────┘
│ │ │
└─────────────────┼─────────────────┘
┌────────▼─────────┐
│ XGBoost Model │
│ (Signal + Conf) │
└────────┬─────────┘
┌─────────────────┼─────────────────┐
│ │ │
┌────────▼───────┐ ┌──────▼───────┐ ┌───────▼──────┐
│ 11 Entry │ │ Risk Engine │ │ Position │
│ Filters │ │ (ATR + Kelly)│ │ Manager │
└────────┬───────┘ └──────┬───────┘ └───────┬──────┘
│ │ │
└────────────────┼──────────────────┘
┌────────▼─────────┐
│ Trade Execution │
│ (MT5 + Logging) │
└───────────────────┘
```
## Project Structure
```
xaubot-ai/
├── main_live.py # Main async trading orchestrator
├── train_models.py # Model training script
├── src/ # Core modules
│ ├── config.py # Trading configuration & capital modes
│ ├── mt5_connector.py # MetaTrader 5 connection layer
│ ├── smc_polars.py # Smart Money Concepts analyzer
│ ├── ml_model.py # XGBoost trading model
│ ├── feature_eng.py # Feature engineering (37 features)
│ ├── regime_detector.py # HMM market regime detection
│ ├── risk_engine.py # Risk calculations & validation
│ ├── smart_risk_manager.py # Dynamic risk management
│ ├── session_filter.py # Session filter (Sydney/London/NY)
│ ├── position_manager.py # Open position management
│ ├── dynamic_confidence.py # Adaptive confidence thresholds
│ ├── auto_trainer.py # Auto-retraining pipeline
│ ├── news_agent.py # Economic news filtering
│ ├── telegram_notifier.py # Telegram alerts
│ ├── trade_logger.py # Trade logging to DB
│ └── utils.py # Utility functions
├── backtests/ # Backtesting
│ ├── backtest_live_sync.py # Main backtest (synced with live)
│ └── archive/ # Historical versions
├── scripts/ # Utility scripts
│ ├── check_market.py # Quick SMC market analysis
│ ├── check_positions.py # View open positions
│ ├── check_status.py # Account status check
│ ├── close_positions.py # Emergency close all
│ ├── modify_tp.py # Modify take-profit levels
│ └── get_trade_history.py # Pull trade history
├── tests/ # Tests
├── models/ # Trained models (.pkl)
├── data/ # Market data & trade logs
├── docs/ # Documentation
│ ├── arsitektur-ai/ # Architecture docs (23 components)
│ └── research/ # Research & analysis
├── web-dashboard/ # Next.js monitoring dashboard
└── docker/ # Docker configuration
```
## Backtest Results (Jan 2025 - Feb 2026)
| Metric | Value |
|--------|-------|
@@ -24,80 +117,92 @@ An intelligent automated trading system for XAUUSD (Gold) using Machine Learning
| Max Drawdown | 2.2% |
| Sharpe Ratio | 4.83 |
## Architecture
## Installation
### Prerequisites
- Python 3.11+
- MetaTrader 5 terminal (Windows)
- PostgreSQL (optional, for trade logging)
### Setup
```bash
# Clone the repository
git clone https://github.com/GifariKemal/xaubot-ai.git
cd xaubot-ai
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your MT5 credentials and Telegram token
```
├── main_live.py # Main trading orchestrator
├── src/
│ ├── ml_model.py # XGBoost ML model
│ ├── smc_polars.py # Smart Money Concepts analyzer
│ ├── regime_detector.py # HMM market regime detection
│ ├── smart_risk_manager.py # Risk management system
│ ├── feature_eng.py # Feature engineering
│ ├── mt5_connector.py # MetaTrader 5 connection
│ ├── session_filter.py # Trading session management
│ └── ...
├── backtests/
│ ├── backtest_live_sync.py # Main backtest (synced with live)
│ └── archive/ # Historical backtest scripts
├── models/ # Trained ML models (.pkl)
├── data/ # Market data and trade logs
├── docs/ # Documentation
└── web-dashboard/ # Next.js monitoring dashboard
### Configuration
Key settings in `.env`:
```env
# MetaTrader 5
MT5_LOGIN=your_login
MT5_PASSWORD=your_password
MT5_SERVER=your_server
MT5_PATH=C:/Program Files/MetaTrader 5/terminal64.exe
# Telegram Notifications
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Trading
CAPITAL=5000
SYMBOL=XAUUSD
```
### Run
```bash
# Train models first
python train_models.py
# Start the bot
python main_live.py
# Run backtest
python backtests/backtest_live_sync.py --tune
```
## Risk Management
- **ATR-Based Stop Loss**: Minimum 1.5 ATR distance
- **Broker-Level Protection**: Emergency SL at broker level
- **Time-Based Exit**: Max 6 hours per trade
- **Daily Loss Limit**: 5% of capital
- **Position Limit**: Max 2 concurrent positions
| Protection | Details |
|-----------|---------|
| **ATR-Based Stop Loss** | Minimum 1.5x ATR distance |
| **Broker-Level SL** | Emergency SL set at broker level |
| **Position Sizing** | Kelly criterion with capital mode scaling |
| **Daily Loss Limit** | 5% of capital per day |
| **Total Loss Limit** | 10% of capital |
| **Position Limit** | Max 2 concurrent positions |
| **Time-Based Exit** | Max 6 hours per trade |
| **Session Filter** | Only trades during active sessions |
| **Spread Filter** | Rejects trades during high spread |
| **Cooldown** | Minimum time between trades |
## Installation
## Tech Stack
1. Clone the repository
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Copy `.env.example` to `.env` and configure:
- MT5 credentials
- Telegram bot token
- Database connection
4. Train models:
```bash
python train_models.py
```
5. Run the bot:
```bash
python main_live.py
```
## Configuration
Key settings in `.env`:
- `MT5_LOGIN`, `MT5_PASSWORD`, `MT5_SERVER` - MetaTrader 5 credentials
- `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` - Telegram notifications
- `CAPITAL` - Trading capital amount
- `SYMBOL` - Trading symbol (default: XAUUSD)
## Backtest
Run backtest with threshold tuning:
```bash
python backtests/backtest_live_sync.py --tune
```
Run backtest with specific threshold:
```bash
python backtests/backtest_live_sync.py --threshold 0.50 --save
```
- **Polars** — High-performance data engine (not Pandas)
- **XGBoost** — Gradient boosted ML model
- **hmmlearn** — Hidden Markov Model for regime detection
- **MetaTrader5** — Broker connection API
- **asyncio** — Async event loop for low-latency execution
- **loguru** — Structured logging
- **PostgreSQL** — Trade database
- **Next.js** — Web dashboard
## Disclaimer
This software is for educational purposes only. Trading involves substantial risk of loss. Past performance is not indicative of future results. Use at your own risk.
> This software is for **educational and research purposes only**. Trading foreign exchange (Forex) and commodities on margin carries a high level of risk and may not be suitable for all investors. Past performance is not indicative of future results. You could lose some or all of your investment. **Use at your own risk.**
## License
MIT License
[MIT License](LICENSE) - Copyright (c) 2025-2026 Gifari Kemal