Downloads · 30 days
0
nerds-gaming/xauusd-ml-trader
xauusd-ml-trader is a machine learning model from nerds-gaming. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A comprehensive ML-based Gold (XAUUSD) trading system implementing 5 institutional-grade strategies with online learning, Walk-Forward Optimization (WFO) backtesting, and Probability of Best Fit analysis.
Downloads · 30 days
0
Access
Public
Updated Apr 24, 2026
Repo size
—
Likes
2
Public
Click a slice to open those files.
.py137 KB · 92%
From the Hugging Face model README
A comprehensive ML-based Gold (XAUUSD) trading system implementing 5 institutional-grade strategies with online learning, Walk-Forward Optimization (WFO) backtesting, and Probability of Best Fit analysis.
This is an educational/research project. This is NOT financial advice. Trading Gold (XAUUSD) involves substantial risk of loss. Past performance (including backtests) is NOT indicative of future results. Never trade with money you can't afford to lose.
xauusd_trader/
├── data_loader.py # XAUUSD data loading (yfinance + synthetic)
├── main.py # Main orchestrator - ties everything together
├── strategies/
│ ├── smc_strategy.py # Strategy 1: Smart Money Concepts (Order Blocks, BOS, FVG)
│ ├── ict_power_of_3.py # Strategy 2: ICT Power of 3 (AMD phases)
│ ├── momentum_strategy.py # Strategy 3: RSI Divergence & Stochastics
│ ├── sentiment_strategy.py # Strategy 4: Fundamental/Sentiment Alignment
│ └── risk_management.py # Strategy 5: Volatility-aware Risk Management
├── ml/
│ └── ensemble_model.py # XGBoost ensemble with online learning & drift detection
└── backtesting/
├── wfo_engine.py # Walk-Forward Optimization backtesting
└── probability_best_fit.py # Distribution fitting & strategy selection
The most profitable strategy in our analysis. Detects institutional footprints:
Session-based institutional movement detection:
Momentum oscillator confluence:
Macro-driven directional bias:
Gold-specific volatility protection:
| Group | Features | Key Indicators |
|---|---|---|
| SMC | 16 | BOS, OB strength, FVG, liquidity sweeps, structure code |
| AMD | 14 | Accumulation tightness, manipulation direction/strength, distribution |
| Momentum | 31 | RSI (7/14/21), Stochastics, MACD, BBands, EMA crossovers, divergences |
| Sentiment | 5 | Risk sentiment score, trend, regime code |
| Volatility | 11 | HV, Parkinson, Yang-Zhang, vol ratio, gap detection |
| Price Action | 8 | Returns, candle body/wicks, ATR |
| Session | 1 | Trading session code |
Rolling temporal cross-validation that prevents look-ahead bias:
Fold 0: [====TRAIN====][=TEST=]
Fold 1: [======TRAIN======][=TEST=]
Fold 2: [=========TRAIN=========][=TEST=]
Statistical strategy selection using:
Score = 0.25 × Normalized_Expected_Return
+ 0.25 × Pct_Positive_Folds
+ 0.25 × Sharpe_Stability
+ 0.25 × MC_Probability
pip install numpy pandas scikit-learn xgboost scipy yfinance river joblib
from xauusd_trader.main import XAUUSDTradingSystem, ModelConfig, BacktestConfig
from xauusd_trader.strategies.risk_management import RiskConfig
system = XAUUSDTradingSystem(
model_config=ModelConfig(
n_estimators=300,
max_depth=6,
learning_rate=0.08,
n_models=3,
online_batch_size=30,
),
risk_config=RiskConfig(
initial_capital=100000.0,
max_risk_per_trade=0.01, # 1% risk per trade
max_daily_loss_pct=0.03, # 3% daily loss limit
max_total_drawdown_pct=0.10, # 10% total DD halt
),
backtest_config=BacktestConfig(
n_folds=5,
forward_bars=10,
min_confidence=0.35,
),
)
# Run everything: load data → features → train → WFO → Best Fit → Online trading
results = system.full_pipeline(use_real_data=True)
# Just run SMC analysis
from xauusd_trader.data_loader import load_xauusd, add_atr
from xauusd_trader.strategies.smc_strategy import compute_smc_features
df = load_xauusd(period="1y", interval="1h")
df = add_atr(df)
df = compute_smc_features(df)
# See Order Block signals
signals = df[df['smc_signal'] != 0]
print(signals[['close', 'smc_signal', 'smc_entry', 'smc_sl', 'smc_tp', 'smc_confidence']])
Results from 5000-bar test (your results will vary with real data):
WFO BACKTEST (3 folds, all profitable):
Total OOS Trades: 1260
Win Rate: 52.2%
Profit Factor: 2.09
Sharpe Ratio: 5.34
WFO Efficiency: 0.54
Sharpe Stability: 3.07
STRATEGY RANKING (Probability of Best Fit):
1. SMC_OrderBlock Score=0.823 WinRate=81.8% Sharpe=18.2 BestFit=Laplace
2. ML_Ensemble Score=0.782 WinRate=52.2% Sharpe=5.36 BestFit=Normal
3. Momentum Score=0.490 WinRate=27.1% Sharpe=0.37 BestFit=Student-t
ONLINE TRADING (with learning):
Trades: 1621, WinRate: 51.3%, PF: 2.03, Sharpe: 4.98
Drift events detected: 2, Model adapted successfully
| Parameter | Default | Description |
|---|---|---|
n_estimators | 300 | XGBoost trees per model |
max_depth | 6 | Max tree depth |
learning_rate | 0.08 | Boosting learning rate |
n_models | 3 | Ensemble size |
online_batch_size | 50 | Trades before incremental retrain |
online_boost_rounds | 10 | Boost rounds per online update |
| Parameter | Default | Description |
|---|---|---|
max_risk_per_trade | 1% | Max capital risk per trade |
max_daily_loss_pct | 3% | Daily loss limit |
max_total_drawdown_pct | 10% | Total DD halt threshold |
min_sl_atr_mult | 0.5× ATR | Minimum stop loss distance |
max_sl_atr_mult | 3.0× ATR | Maximum stop loss distance |
MIT License - See LICENSE file for details.