0f9548e5fb
Exit Strategy v6.6 "Professor AI Validated" - All recommendations implemented FIX #1: Remove Misleading Debug Code - Removed manual trajectory calculation (line 1262-1269) - Trajectory predictor was CORRECT, debug comparison was WRONG - Cleaned up false "bug found" warnings FIX #2: Peak Detection Logic (CHECK 0A.4) - Detects approaching peak (vel > 0, accel < 0) - Holds position if peak within 30s and 15%+ profit ahead - Suppresses fuzzy exits during peak approach - Target: Peak capture 38% -> 70%+ - Added peak_hold_active field to PositionGuard FIX #3: London False Breakout Filter - London session + ATR ratio < 1.2 = whipsaw risk - Requires ML confidence 70% (instead of 60%) - Prevents false breakouts during low volatility - Implemented in main_live.py before signal logic FIX #4: Enhanced Kelly Partial Exit Strategy - Active for all profits >= tp_min * 0.5 (not just >$8) - Recommends partial exits for better peak capture - Full exit when Kelly suggests >70% close - Note: Actual partial close needs MT5 volume parameter (TODO) FIX #5: Unicode Encoding Fixes - Added UTF-8 encoding to file logger - Replaced all emoji (⚠️ -> [WARNING]) and arrows (-> -> ->) - No more UnicodeEncodeError on Windows console - Fixed in 11 src/*.py files Expected Performance: - Peak Capture: 38% -> 70%+ (+84%) - Avg Profit: $2.00 -> $4.50 (+125%) - Risk/Reward: 0.49 -> 1.2+ (+145%) - Win Rate: Maintain 76% Files Modified: - src/smart_risk_manager.py (peak detection, Kelly, unicode) - src/trajectory_predictor.py (unicode arrows) - main_live.py (London filter, UTF-8 encoding) - src/*.py (unicode cleanup: 11 files) - VERSION (0.2.1 -> 0.2.2) - CHANGELOG.md (comprehensive v0.2.2 docs) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
171 lines
4.3 KiB
Markdown
171 lines
4.3 KiB
Markdown
# XAUBot AI v0.6.0 FIXED - Backtest
|
|
|
|
Backtest dengan implementasi rekomendasi dari **Profesor AI & Ilmuwan Algoritma Trading**.
|
|
|
|
## 📋 Fixes Implemented
|
|
|
|
### PRIORITY 1: Tiered Fuzzy Exit Thresholds
|
|
**Problem:** 75% wins adalah micro profits (<$1) karena fuzzy threshold fixed 90%
|
|
**Solution:** Dynamic thresholds based on profit tier
|
|
|
|
```python
|
|
Micro (<$1): 70% threshold # Exit early (was 90%)
|
|
Small ($1-3): 75% threshold # Small protection (was 85%)
|
|
Medium ($3-8): 85% threshold # Hold for more (was 85%)
|
|
Large (>$8): 90% threshold # Maximize (was 80%)
|
|
```
|
|
|
|
**Expected Impact:** Micro profits 75% → <20% (-73%)
|
|
|
|
### PRIORITY 2: Trajectory Confidence Calibration
|
|
**Problem:** Predictions $10-66 but actual $0.28-0.58 (error 95%+)
|
|
**Solution:** Conservative predictions with regime penalty
|
|
|
|
```python
|
|
# Regime penalties
|
|
ranging: 0.4 # 60% discount (low predictability)
|
|
volatile: 0.6 # 40% discount (high noise)
|
|
trending: 0.9 # 10% discount (best predictability)
|
|
|
|
# Add 95% CI uncertainty
|
|
prediction_std = abs(acceleration) * horizon * 5
|
|
conservative = calibrated - 1.96 * prediction_std
|
|
```
|
|
|
|
**Expected Impact:** Prediction error 95% → <40% (-58%)
|
|
|
|
### PRIORITY 3: Session Filter
|
|
**Problem:** Sydney/Tokyo (00:00-10:00) generated micro profits only
|
|
**Solution:** DISABLE low-volatility sessions
|
|
|
|
```python
|
|
Sydney/Tokyo (00:00-10:00): BLOCKED
|
|
Late NY (22:00-01:00): BLOCKED
|
|
London (14:00-20:00): ALLOWED (best performance)
|
|
```
|
|
|
|
**Expected Impact:** Avg profit/trade +50%+ (filtering bad trades)
|
|
|
|
### PRIORITY 4: Unicode Fix
|
|
**Problem:** Log corruption from emojis (⏳, →, ✓)
|
|
**Solution:** ASCII-only logging
|
|
|
|
**Impact:** Stable logs, easier debugging
|
|
|
|
### PRIORITY 5: Tighter Stop-Loss
|
|
**Problem:** Max loss -$34.70 (17x avg win)
|
|
**Solution:** Reduce max loss per trade
|
|
|
|
```python
|
|
Max Loss: $50 → $25
|
|
```
|
|
|
|
**Expected Impact:** Avg loss $20.91 → $8-12 (-60%)
|
|
|
|
---
|
|
|
|
## 🎯 Expected Results
|
|
|
|
| Metric | Before | Target | Improvement |
|
|
|--------|--------|--------|-------------|
|
|
| Avg Win | $4.07 | $8-12 | +100-200% |
|
|
| RR Ratio | 1:5 | 1.5:1 | +650% |
|
|
| Micro Profits | 75% | <20% | -73% |
|
|
| Win Rate | 57% | 62-65% | +8% |
|
|
| Sharpe Ratio | 0.8 | 1.5+ | +87% |
|
|
|
|
---
|
|
|
|
## 🚀 Usage
|
|
|
|
### Quick Run (90 days)
|
|
```bash
|
|
cd "C:/Users/Administrator/Videos/Smart Automatic Trading BOT + AI/backtests/v0.6.0_fixed"
|
|
python run_backtest.py
|
|
```
|
|
|
|
### Custom Period
|
|
```bash
|
|
python run_backtest.py --days 30
|
|
python run_backtest.py --days 180
|
|
```
|
|
|
|
### Save Results to CSV
|
|
```bash
|
|
python run_backtest.py --days 90 --save
|
|
```
|
|
|
|
---
|
|
|
|
## 📁 Files
|
|
|
|
- `backtest_v0_6_0_fixed.py` - Main backtest engine with fixes
|
|
- `run_backtest.py` - Quick runner script
|
|
- `README.md` - This file
|
|
- `results_*.csv` - Backtest results (when using --save)
|
|
|
|
---
|
|
|
|
## 📊 Understanding Results
|
|
|
|
### PASS Criteria
|
|
- ✅ Avg Win ≥ $8
|
|
- ✅ RR Ratio ≤ 1.5:1 (avg loss ≤ 1.5x avg win)
|
|
- ✅ Micro Profits < 20%
|
|
- ✅ Win Rate 62-65%
|
|
- ✅ Sharpe Ratio ≥ 1.5
|
|
|
|
### What to Look For
|
|
1. **Micro Profit %** - Should be dramatically lower (<20% vs 75%)
|
|
2. **RR Ratio** - Should be balanced (1.5:1 or better)
|
|
3. **Sharpe Ratio** - Should exceed 1.5 (risk-adjusted returns)
|
|
4. **Exit Reasons** - Fuzzy exits should dominate (not trajectory overrides)
|
|
|
|
---
|
|
|
|
## 🔬 Technical Details
|
|
|
|
### Exit Logic Flow
|
|
```
|
|
1. Take Profit Hit → Exit (ideal)
|
|
2. Max Loss ($25) → Exit (protection)
|
|
3. Fuzzy Confidence > X% → Exit (tiered threshold)
|
|
- <$1: 70% threshold
|
|
- $1-3: 75% threshold
|
|
- $3-8: 85% threshold
|
|
- >$8: 90% threshold
|
|
4. ML Reversal (>65%) → Exit (signal change)
|
|
5. Timeout (8 hours) → Exit (stuck trade)
|
|
```
|
|
|
|
### Fuzzy Confidence Calculation
|
|
```python
|
|
Components (0.0-1.0):
|
|
- Velocity (40%): crashing=-0.10 → conf +0.40
|
|
- Retention (30%): <70% from peak → conf +0.30
|
|
- Acceleration (20%): <-0.002 → conf +0.20
|
|
- Time (10%): >6h → conf +0.10
|
|
```
|
|
|
|
---
|
|
|
|
## 🎓 Next Steps
|
|
|
|
### If Results PASS (meet targets):
|
|
1. Apply fixes to `main_live.py`
|
|
2. Update `smart_risk_manager.py` with new thresholds
|
|
3. Demo account testing (2 weeks)
|
|
4. Go live if Sharpe >1.2
|
|
|
|
### If Results FAIL (below targets):
|
|
1. Analyze exit reason distribution
|
|
2. Adjust fuzzy thresholds (try 65-85%)
|
|
3. Test different session windows
|
|
4. Re-run with different parameters
|
|
|
|
---
|
|
|
|
**Author:** Profesor AI & Ilmuwan Algoritma Trading
|
|
**Date:** 2026-02-11
|
|
**Version:** v0.6.0 FIXED
|