SkillAgentSearch skills...

Tradingbot

DRL Trading - AI Gold Trading Bot Deep reinforcement learning system for autonomous XAUUSD trading using: - PPO & Dreamer algorithms (PyTorch) - 140+ features: multi-timeframe, macro data, economic events - MetaTrader 5 live trading - 2M steps trained, targeting 80-120% annual returns - Multiple strategies (aggressive/swing/standard)

Install / Use

npx skills add zero-was-here/tradingbot

Installs into whichever agent you are using.

About this skill

Quality Score

0/100

Supported Platforms

Universal

README

🤖 DRL Trading Bot - XAUUSD

An advanced AI-powered trading system using Deep Reinforcement Learning to trade gold (XAUUSD) autonomously. Built with 140+ market features, multi-timeframe analysis, and state-of-the-art RL algorithms.

Python 3.12+ PyTorch License: MIT


📋 Table of Contents


🎯 What is This?

This is a fully autonomous trading bot that uses artificial intelligence to trade gold (XAUUSD) in the forex market. Unlike traditional bots that follow rigid rules, this system learns from historical data using Deep Reinforcement Learning (DRL) - the same technology behind AlphaGo and ChatGPT.

Why Gold (XAUUSD)?

  • High liquidity (easy to enter/exit trades)
  • Strong trends and patterns
  • 24/5 trading availability
  • Lower correlation with stocks (diversification)

What Makes This Different?

  • 140+ Market Features: Most bots use 5-10 indicators. We use 140+ data points from multiple sources
  • Multi-Timeframe Analysis: Analyzes M5, M15, H1, H4, and D1 charts simultaneously
  • Macro Awareness: Integrates VIX, Oil, Bitcoin, Dollar Index, and economic events
  • Self-Learning: Improves through millions of simulated trades, not manual programming

🚀 Key Features

🧠 Advanced AI Architecture

Two Cutting-Edge Algorithms:

  1. PPO (Proximal Policy Optimization)

    • Industry-standard for trading bots
    • Stable, reliable training
    • Proven results in financial markets
  2. Dreamer V3

    • Cutting-edge world model-based RL
    • Learns market dynamics and predicts future states
    • More sample-efficient (trains faster)

Powered By:

  • Stable-Baselines3: Production-ready RL library
  • PyTorch: Deep learning framework
  • Gymnasium: OpenAI's standard RL environment

Hardware Flexibility:

  • ✅ CPU (any computer)
  • ✅ MPS (Apple M1/M2/M3 chips)
  • ✅ CUDA (NVIDIA GPUs)
  • ✅ Google Colab (free cloud GPUs)

📊 Comprehensive Market Intelligence (140+ Features)

Multi-Timeframe Analysis

Analyzes 5 timeframes simultaneously for complete market context:

  • M5 (5-min): Entry timing and momentum
  • M15 (15-min): Short-term trends
  • H1 (1-hour): Intraday direction
  • H4 (4-hour): Daily bias
  • D1 (Daily): Long-term trend

63 Technical Indicators ("God Mode Features")

  • Trend: Moving Averages (EMA, SMA), MACD, ADX
  • Momentum: RSI, Stochastic, CCI, Williams %R
  • Volatility: ATR, Bollinger Bands, Keltner Channels
  • Volume: OBV, MFI, Volume analysis
  • Price Action: Support/Resistance, Pivot Points, Candlestick patterns

Macro Market Data

Understands the broader economy:

  • DXY (US Dollar Index) - Dollar strength affects gold inversely
  • SPX (S&P 500) - Stock market risk sentiment
  • US10Y (Treasury Yields) - Interest rates impact gold
  • VIX (Volatility Index) - Market fear gauge
  • Oil (WTI Crude) - Commodity correlation
  • Bitcoin - Risk-on/risk-off indicator
  • EURUSD - Major currency pair correlation
  • Silver (XAGUSD) - Precious metals correlation
  • GLD (Gold ETF) - Institutional positioning

Economic Calendar Integration

Knows when major events happen:

  • NFP (Non-Farm Payrolls) - Monthly jobs report
  • CPI (Consumer Price Index) - Inflation data
  • FOMC (Federal Reserve meetings) - Interest rate decisions
  • GDP - Economic growth reports
  • Automatically adjusts risk before/during high-impact events

Market Microstructure

  • Order flow analysis
  • Bid-ask spread monitoring
  • Volatility regime detection
  • Session-based patterns (Asian/London/New York)

Optional Sentiment Analysis

  • Reddit sentiment from r/wallstreetbets, r/Forex
  • News headlines analysis
  • Google Trends for "gold price" searches

🎯 Trading Strategies

Three pre-configured strategies for different risk profiles:

| Strategy | Frequency | Hold Time | Risk Level | Best For | |----------|-----------|-----------|------------|----------| | Standard | Medium | Hours-Days | Moderate | Balanced traders | | Aggressive | High | Minutes-Hours | Higher | Active traders | | Swing | Low | Days-Weeks | Lower | Patient traders |


🔌 Live Trading Integration

MetaTrader 5 (MT5)

  • Direct integration with MT5 platform
  • Real-time price feeds
  • Instant order execution
  • Works with any MT5 broker

MetaAPI (Cloud Trading)

  • Trade from anywhere (no VPS needed)
  • Cloud-based execution
  • Multiple broker support
  • Automatic reconnection

Risk Management Features

  • Dynamic position sizing based on account equity
  • Automatic stop-loss placement
  • Maximum drawdown protection
  • Daily loss limits
  • Position concentration limits

📊 Performance Targets

| Metric | Target | Explanation | |--------|--------|-------------| | Annual Return | 80-120%+ | Expected yearly profit | | Sharpe Ratio | 3.5-4.5+ | Risk-adjusted returns (>2 is excellent) | | Max Drawdown | <8% | Largest peak-to-valley loss | | Win Rate | 60-65% | Percentage of profitable trades | | Profit Factor | 2.5-3.0+ | Gross profit / Gross loss |

Note: These are targets based on backtesting. Real performance depends on market conditions, slippage, and execution quality.


🔍 How It Works

1️⃣ Data Collection

The bot gathers data from multiple sources:

XAUUSD prices (M5, M15, H1, H4, D1)
    ↓
Macro data (VIX, Oil, Bitcoin, etc.)
    ↓
Economic calendar events
    ↓
Technical indicators calculated
    ↓
140+ features combined into observation

2️⃣ AI Decision Making

The trained model analyzes the 140+ features and decides:

  • Action: Buy, Sell, or Hold
  • Position Size: How much to risk
  • Stop Loss: Where to exit if wrong
  • Take Profit: Where to exit if right

3️⃣ Execution

The decision is sent to MT5 or MetaAPI:

AI Decision → Order Execution → Position Monitoring → Risk Management

4️⃣ Learning Process (Training)

The bot improves through simulation:

1. Start with random strategy
2. Take actions in historical market data
3. Receive rewards (profit = positive, loss = negative)
4. Update strategy to maximize rewards
5. Repeat for 1,000,000+ steps
6. Deploy trained model

Training Time:

  • Local Mac (MPS): 6-8 days
  • NVIDIA GPU: 2-3 days
  • Google Colab Pro+: 5-7 hours ⚡ (Recommended)

🛠️ Installation

Prerequisites

✅ Python 3.12 or higher
✅ MetaTrader 5 (for live trading only)
✅ 8GB+ RAM recommended
✅ 10GB free disk space (for data)

Step-by-Step Setup

1. Clone the Repository

git clone https://github.com/zero-was-here/tradingbot.git
cd tradingbot

2. Create Virtual Environment

# Create environment
python3 -m venv .

# Activate it
source bin/activate  # Mac/Linux
# OR
.\Scripts\activate   # Windows

3. Install Dependencies

pip install -r requirements.txt

What gets installed:

  • stable-baselines3 - RL algorithms
  • torch - Deep learning
  • pandas - Data processing
  • numpy - Numerical computing
  • gymnasium - RL environments
  • MetaTrader5 - Live trading
  • tqdm - Progress bars

🔐 Security Setup (API Keys)

IMPORTANT: Never commit API keys to git!

Step 1: Create Environment File

# Copy the example file
cp .env.example .env

# Edit with your credentials
nano .env  # or use any text editor

Step 2: Fill in Your Credentials

# .env file
METAAPI_TOKEN=your_actual_token_here
METAAPI_ACCOUNT_ID=your_actual_account_id_here

Step 3: Verify .env is Ignored

The .env file is already in .gitignore - it will never be committed to git.

Get your MetaAPI credentials:

  1. Sign up at MetaAPI
  2. Create a trading account connection
  3. Copy your API token and account ID

📚 Quick Start Guide

Step 1: Get the Data

A. Auto-fetch Macro Data (5 minutes)

python scripts/fetch_all_data.py

Downloads: VIX, Oil, Bitcoin, EURUSD, Silver, GLD from Yahoo Finance

B. Generate Economic Calendar (1 minute)

python scripts/generate_economic_calendar.py

Creates calendar with 1,500+ major economic events (2015-2025)

C. Export XAUUSD from MetaTrader 5 (15-20 minutes)

  1. Open MetaTrader 5
  2. ViewSymbols
  3. Find XAUUSD, right-click → "All history"
  4. Wait for download (may take 10-30 min)
  5. ToolsHistory Center
  6. Select XAUUSDM5 timeframe
  7. Click Export → Save as data/xauusd_m5.csv
  8. Repeat for M15 → Save as data/xauusd_m15.csv

Expected files:

data/xauusd_m5.csv   (~50-100 MB, 1M+ rows)
data/xauusd_m15.csv  (~20-40 MB, 350k+ rows)

Step 2: Train the Model

Option A: Local Training (Slower but Free)

# Mac with Apple Silicon
python train/train_ultimate_150.py --steps 1000000 --device mps --batch-size 64

# Windows/Linux with NVIDIA GPU
python train/train_ultimate_150.py --steps 1000000 --device cuda --batch-size 128

# CPU only (slowest)
python train/train_ultimate_150.py --steps 1000000 --device cpu --batch-size 32

Training time:

  • Mac M1/M2/M3: 6-8 days
  • NVIDIA RTX 3080+: 2-3 days
  • CPU: 15-20 days (not recommended)

Monitor progress:

  • Models saved every 50k steps in train/ppo_xauusd_[steps]k.zip
  • Check training log for rewards and losses

Related Skills

View on GitHub
GitHub Stars161
CategoryEducation
Updated7h ago
Forks61

Languages

Python

Security Score

95/100

Audited on Aug 8, 2026

No findings