XAUUSD Ichimoku Multi-Timeframe RL Trading Bot — Train, Backtest, Generate MQL5 EA
Project description
🤖 XAUUSD AI Trading Bot — Ichimoku Multi-Timeframe RL
RL (PPO) Trading Bot cho XAUUSD sử dụng chiến lược Ichimoku Cloud Break trên 4 timeframes đồng thời (M5/M15/H1/H4).
Inspired by MoonDev's DRL Trading Bot — nhưng Ichimoku là core, không phải generic indicators.
⚡ Install
pip install xauusd-ichi-rl
CLI Commands
# 1. Train RL bot (cần file CSV XAUUSD M1 trong thư mục hiện tại)
ichi-train --timesteps 500000 --sl 5.0 --tp 3.0
# 2. Rule-based backtest + grid search optimizer
ichi-backtest --mode optimize --year 2026 --month 01
# 3. Generate file MQL5 EA (output → mql5_output/)
ichi-gen-mql5
# ↑ Ra IchiMTF_RL_Strategy.mq5 — copy vào MT5 Experts/ là dùng được!
💡 Workflow:
ichi-train→ichi-backtest→ichi-gen-mql5→ Copy.mq5vào MetaTrader 5
🐍 Python API:
from xauusd_ichi import run_v2, generate_all result = run_v2(timesteps=500_000, sl=5.0, tp=3.0)
📊 Kết Quả Backtest — Jan 2026 (Out-of-Sample)
| Metric | Giá trị | Benchmark |
|---|---|---|
| Net Profit | +$724 (+7.12%) | MoonDev target: 5-7.5%/month |
| Profit Factor | 3.76 | Industry good: >1.5 |
| Win Rate | 86.7% | MoonDev: 58-62% |
| Max Drawdown | 0.12% | MoonDev: 8-12% |
| Total Trades | 406 | ~20/day |
| Consecutive Wins | 36 | |
| Training Time | 24 phút | 500k steps, 348 it/s |
⚠️ Disclaimer: Kết quả quá khứ không đảm bảo hiệu suất tương lai. Test chỉ trên 1 tháng, cần validate thêm.
🧠 Tư Duy & Điểm Khác Biệt
So với MoonDev (forbbiden403/tradingbot):
| MoonDev | Bot này | |
|---|---|---|
| Core Strategy | 63 generic indicators | Ichimoku Cloud Break (từ EA thực chiến) |
| Entry Logic | RL tự quyết 100% | RL + Ichimoku signal bias trong reward |
| SL/TP | RL tự học cắt lỗ | Built-in SL/TP (grid search optimized) |
| DCA | Không | DCA awareness (từ EA IchiDCA) |
| Speed | ~35 it/s | 348 it/s (pre-cached numpy arrays) |
| Features | 140+ | 128 (focused, less noise) |
Quá trình phát triển (3 iterations):
v1: RL + Ichimoku only (M5) → LỖ -4.95% ❌
└─ Insight: 50 features, 1 TF không đủ edge
v1.5: Rule-based Ichimoku + Grid Search → LỖ -$65 ❌
└─ Insight: Ichimoku đơn lẻ trên M5 = quá nhiều noise
v2: RL + Multi-TF (M5/M15/H1/H4) → LÃI +7.12% ✅
└─ Insight: Multi-TF confirmation + RL flexibility = edge
Key Insights:
- Ichimoku cần multi-TF: M5 quá noisy, cần H1/H4 confirm trend
- Built-in SL/TP > RL-learned SL/TP: RL mất quá nhiều steps để học risk management
- Numpy pre-cache: Tăng speed 10x (35 → 348 it/s) bằng cách bỏ pandas.iloc
- 128 features > 140+ features: Focused features (Ichimoku core) < noise reduction
🏗️ Kiến Trúc
┌─────────────────────────────────────────────┐
│ Multi-TF Feature Engine │
│ M1 Data → Resample → M5, M15, H1, H4 │
│ │
│ Per TF: Ichimoku│EMA│RSI│MACD│ATR│BB│ADX │
│ + Sessions + Price Returns │
│ ───────────────────────────────── │
│ → 128 features (forward-fill merge) │
└──────────────────┬──────────────────────────┘
│
┌──────────────────▼──────────────────────────┐
│ Trading Environment (Gym) │
│ • Pre-cached numpy arrays (fast!) │
│ • Built-in SL=$5 / TP=$3 │
│ • Ichimoku-aware reward (Sharpe) │
│ • Cooldown 5 bars (anti-overtrading) │
└──────────────────┬──────────────────────────┘
│
┌──────────────────▼──────────────────────────┐
│ PPO Agent (SB3) │
│ • Network: [256, 256] │
│ • 500k steps, n_steps=1024 │
│ • Live metrics callback (pass tracking) │
│ • Auto-save best checkpoint │
└──────────────────┬──────────────────────────┘
│
┌──────────────────▼──────────────────────────┐
│ MT5-Style Report │
│ PF│WR│DD│Sharpe│Recovery│Consecutive│MFE/MAE│
└─────────────────────────────────────────────┘
🚀 Quick Start
Option A: Via PyPI (recommended)
pip install xauusd-ichi-rl
# Đặt file CSV vào thư mục rồi chạy:
ichi-train --timesteps 500000 --sl 5.0 --tp 3.0
ichi-backtest --mode optimize --year 2026 --month 01
ichi-gen-mql5
Option B: Clone & Run
git clone https://github.com/hungpixi/xauusd-ichimoku-rl-bot
cd xauusd-ichimoku-rl-bot
pip install -r requirements.txt
Prepare Data
Đặt file XAUUSD M1 CSV vào root:
XAUUSD_2025_10.csv # Train
XAUUSD_2025_11.csv # Train
XAUUSD_2025_12.csv # Train
XAUUSD_2026_01.csv # Test
Train + Test (1 lệnh)
python run_rl_v2.py --timesteps 500000 --sl 5.0 --tp 3.0
# hoặc:
ichi-train --timesteps 500000 --sl 5.0 --tp 3.0
Rule-Based Backtest + Grid Search
# Optimize SL/TP
ichi-backtest --mode optimize --year 2026 --month 01
# Single backtest
ichi-backtest --mode backtest --year 2026 --month 01 --sl 5 --tp 3
📁 Cấu Trúc
src/
├── data/
│ ├── data_loader.py # Load CSV data
│ ├── resampler.py # M1 → M5/M15/H1/H4
│ ├── multi_tf_engine.py # ★ Multi-TF feature builder (128 features)
│ ├── ichimoku_features.py # Ichimoku indicator calculations
│ └── macro_data.py # DXY/VIX from Yahoo Finance
├── env/
│ └── trading_env.py # ★ Gymnasium env (numpy-optimized, SL/TP)
├── strategy/
│ └── ichimoku_strategy.py # ★ Rule-based strategy + grid search
├── models/
│ └── mt5_report.py # MT5 Strategy Tester report format
└── rbi/
└── progressive_validation.py # Progressive validation runner
run_rl_v2.py # ★ Main: Train + Test (1 command)
run_backtest.py # Rule-based backtest + optimizer
🔮 Hướng Phát Triển
- Macro data integration: DXY/VIX correlation (fix merge bug)
- Grid search SL/TP: Tìm SL/TP tối ưu cho RL
- Multi-month validation: Test trên 2025 full (12 tháng)
- DCA logic: Dollar Cost Averaging từ EA IchiDCA gốc
- Live trading: MetaTrader 5 integration
- Dreamer V3: World-model RL (more sample efficient)
📚 References
- forbbiden403/tradingbot — MoonDev's DRL Trading Bot (inspiration)
- IchiDCA_CCBSN_PropFirm.mq5 — EA MQL5 gốc (Ichimoku + DCA + CCBSN)
- Stable-Baselines3 — PPO implementation
- Gymnasium — RL environment
🤝 Bạn muốn Bot Trading AI tương tự?
| Bạn cần | Chúng tôi đã làm ✅ |
|---|---|
| Bot trade tự động | RL Bot XAUUSD multi-TF |
| Backtest nhanh | Grid search 576 combos trong vài giây |
| Báo cáo chuyên nghiệp | MT5 Strategy Tester format |
| Tối ưu chiến lược | Multi-indicator + multi-timeframe |
| 🌐 Yêu cầu Demo | 💬 Zalo |
Comarai — Companion for Marketing & AI Automation
"Thời gian là tài sản quý nhất. Để AI làm những việc lặp lại, bạn tập trung vào chiến lược." — Phạm Phú Nguyễn Hưng, Founder
4 nhân viên AI chạy 24/7:
- 🤖 Em Trade — Bot trading tự cải tiến
- 📝 Em Content — Sáng tạo nội dung
- 📢 Em Marketing — Automation marketing
- 💼 Em Sale — Tìm kiếm khách hàng
Built with ❤️ by hungpixi × AI (Antigravity)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xauusd_ichi_rl-2.1.0.tar.gz.
File metadata
- Download URL: xauusd_ichi_rl-2.1.0.tar.gz
- Upload date:
- Size: 36.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bdf9463500de27deec52b852a67bfb3c2084ac8c44003a8dba06fed37a638d1
|
|
| MD5 |
8efe3908f218f4fa154e61aa3423bb1e
|
|
| BLAKE2b-256 |
885b44ea8cd053b54f466c14925212b3ed29a7eb1a773016ea13626e09698bca
|
File details
Details for the file xauusd_ichi_rl-2.1.0-py3-none-any.whl.
File metadata
- Download URL: xauusd_ichi_rl-2.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2221a468d8d45cb8ae61e40c8a67bb94a6cab1fe3830a1cbcd9a84957641c5a2
|
|
| MD5 |
7993457dcbd97d15259f34d01e0aa44d
|
|
| BLAKE2b-256 |
c0a11670a54b9148999bb9745b8351ee67529a109c673539e77753858cd6a83f
|