YAML Metadata Warning: empty or missing yaml metadata in repo card (https://huggingface.co/docs/hub/model-cards#model-card-metadata)

XAU/USD Scalping AI - Hybrid MA Crossover Strategy

License: MIT Python 3.8+ Hugging Face Models

A professional XAU/USD scalping system that combines rule-based moving average crossover signals with advanced backtesting and live trading capabilities. Achieves consistent monthly profits through trend-following scalping with robust risk management.

🎯 Key Features

  • Hybrid Strategy: Rule-based MA crossover with AI-optimized parameters
  • Advanced Backtesting: Realistic trading conditions with slippage, commissions, and position sizing
  • Live Trading: MetaTrader 5 integration with automated order execution
  • Risk Management: Dynamic position sizing, trailing stops, and capital protection
  • Multi-Timeframe: Optimized for 1-hour data with intraday scalping
  • Performance Tracking: Comprehensive metrics and trade logging
  • Model Sharing: Pre-trained models available on Hugging Face Hub

πŸ“Š Performance Results

Optimal Configuration (2022-2025 Forward Test):

  • Total Return: 4,163.14% (10,000 β†’ 416,314)
  • Annualized Return: ~416%
  • Trades: 1,392 total (mix of long/short positions)
  • Win Rate: 70%+ (short scalps), 60%+ (long positions)
  • Risk Parameters:
    • Long TP: 1,000 points, SL: 400 points
    • Short TP: 10 points, SL: 20 points
    • Position Size: 2% long, 0.02% short
  • Monthly Target: 35,000 THB (~$1,000 USD) achievable

Risk Metrics:

  • Maximum Drawdown: <15% (optimal risk threshold)
  • Sharpe Ratio: >2.0
  • Profit Factor: >1.5

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • MetaTrader 5 account (for live trading)
  • Hugging Face account (for model access)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/xauusd-scalping-ai.git
cd xauusd-scalping-ai
  1. Create virtual environment:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment:
cp .env.example .env
# Edit .env with your API keys and trading credentials

Download Models from Hugging Face

from huggingface_hub import hf_hub_download
import joblib

# Download models
models = ['entry_clf.joblib', 'lstm.pt', 'transformer.pt', 'xgb.model', 'meta.joblib']
for model in models:
    hf_hub_download(repo_id="JonusNattapong/xauusd-scalping-models",
                    filename=model,
                    local_dir="./models")

πŸ“ˆ Usage

Backtesting

Run comprehensive backtests with different parameter combinations:

# Grid search optimization
python scripts/forward_hybrid_2024_2025.py

# Small capital testing ($100-$1,000)
python scripts/backtest_small_capital.py

# Custom backtest
python scripts/run_backtests.py

Training (Optional)

Train new models on updated data:

# Advanced training with hyperparameter tuning
python scripts/advanced_train.py

# Basic training
python src/train.py

Live Trading

⚠️ WARNING: Live trading involves real financial risk. Start with small positions.

  1. Setup MT5:

    • Install MetaTrader 5 platform
    • Configure your trading account in .env
    • Ensure MT5 is running before starting live trading
  2. Start live trading:

python scripts/live_trading.py

Features:

  • Automated signal generation
  • Order execution with slippage protection
  • Real-time position monitoring
  • Telegram notifications
  • Emergency stop functionality

Data Analysis

# Generate performance plots
python scripts/generate_plots.py

# Compute detailed metrics
python scripts/compute_metrics.py

# Test data integrity
python scripts/test_data.py

πŸ—οΈ Project Structure

β”œβ”€β”€ data/                    # Historical price data
β”‚   β”œβ”€β”€ XAU_1h_data.jsonl   # Primary 1-hour data
β”‚   └── *.jsonl             # Multi-timeframe data
β”œβ”€β”€ models/                  # Pre-trained models
β”‚   β”œβ”€β”€ entry_clf.joblib    # Entry signal classifier
β”‚   β”œβ”€β”€ lstm.pt            # LSTM model
β”‚   β”œβ”€β”€ transformer.pt     # Transformer model
β”‚   β”œβ”€β”€ xgb.model          # XGBoost model
β”‚   └── meta.joblib        # Meta-model
β”œβ”€β”€ output/                  # Backtest results & analysis
β”‚   β”œβ”€β”€ forward_hybrid_summary_*.csv
β”‚   β”œβ”€β”€ best_trades.csv
β”‚   └── *.npy               # Forward test arrays
β”œβ”€β”€ scripts/                 # Executable scripts
β”‚   β”œβ”€β”€ live_trading.py     # MT5 live trading
β”‚   β”œβ”€β”€ forward_hybrid_*.py # Backtesting
β”‚   β”œβ”€β”€ generate_plots.py   # Visualization
β”‚   └── *.py                # Analysis tools
β”œβ”€β”€ src/                    # Core source code
β”‚   β”œβ”€β”€ backtest.py         # Advanced backtest engine
β”‚   β”œβ”€β”€ data_loader.py      # Data loading utilities
β”‚   β”œβ”€β”€ features.py         # Feature engineering
β”‚   β”œβ”€β”€ models.py           # Model definitions
β”‚   └── utils.py            # Helper functions
β”œβ”€β”€ tests/                  # Unit tests
β”œβ”€β”€ white_paper.pdf         # Comprehensive documentation
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ .env                    # Environment variables
└── README.md              # This file

πŸ“Š Strategy Overview

Core Logic

  • Primary Signal: MA(5) vs MA(20) crossover on 1-hour charts
  • Long Positions: One large position per day (1000-3000 point targets)
  • Short Scalps: Multiple intraday positions (10-50 point targets)
  • Session Focus: London/NYC trading sessions for optimal liquidity

Risk Management

  • Position Sizing: Percentage-based allocation (0.02%-2% per trade)
  • Stop Loss: Fixed points with trailing stop options
  • Maximum Holding: Long positions ≀24 hours, shorts ≀3 hours
  • Capital Protection: 15% maximum drawdown threshold
  • Diversification: Mix of long-term and short-term positions

Technical Indicators

  • Moving Averages (5, 20 periods)
  • RSI for overbought/oversold confirmation
  • MACD for trend strength validation
  • ATR for volatility adjustment

πŸ”§ Configuration

Environment Variables (.env)

# Hugging Face
HF_TOKEN=your_hf_token

# Trading APIs
EXNESS_API_KEY=your_api_key
EXNESS_SERVER_API=Exness-MT5Trial
EXNESS_PASSWORD_API=your_password

# Data APIs
FINNHUB_API_KEY=your_key
GOLDAPI_KEY=your_key
ALPHA_VANTAGE_KEY=your_key
TWELVE_DATA_KEY=your_key

# Notifications
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id

# Paths
DATA_PATH=data/
MODEL_PATH=models/

Backtest Parameters

Key parameters in src/backtest.py:

  • ENTRY_THRESH: Signal confidence threshold
  • STOP_LOSS: Stop loss in points
  • TAKE_PROFIT: Take profit in points
  • POSITION_SIZE: Capital allocation percentage

πŸ€– Models & AI Components

Available Models

  • Entry Classifier: XGBoost-based signal confirmation
  • LSTM Model: Sequential pattern recognition
  • Transformer Model: Attention-based feature extraction
  • Ensemble Meta-Model: Combined predictions

Model Performance

  • Accuracy: 65-75% signal prediction
  • Precision: 70%+ for profitable signals
  • Recall: 60%+ for trade opportunities

Download from: https://huggingface.co/JonusNattapong/xauusd-scalping-models

πŸ“š Documentation

πŸ§ͺ Testing

Run the test suite:

python -m pytest tests/

Or run smoke tests:

python scripts/smoke_test.py

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guidelines
  • Add tests for new features
  • Update documentation
  • Ensure backward compatibility

βš–οΈ License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

This software is for educational and research purposes only. Trading cryptocurrencies and forex involves substantial risk of loss and is not suitable for every investor. Past performance does not guarantee future results. Please trade responsibly and never risk more than you can afford to lose.

πŸ“ž Support

πŸ™ Acknowledgments

  • Data sourced from reliable financial providers
  • Built with MetaTrader 5 API
  • Models hosted on Hugging Face Hub
  • Inspired by quantitative trading research

Happy Trading! πŸš€πŸ“ˆ

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support