Skip to content

SamuelM1410/gold-trading-bot

Repository files navigation

🥇 GOLD TRADING BOT

AI-powered gold (XAUUSD) trading strategy analyzer and automated trading system.

Features

  • 📥 Real Market Data - Fetch XAUUSD data from Yahoo Finance
  • 📊 5 Pre-built Strategies - EMA Crossover, RSI Reversal, MACD, Support/Resistance, VWAP
  • 🔬 Backtesting Engine - Test strategies against historical data
  • 🏆 Strategy Comparison - Find the most profitable strategy
  • 💾 SQLite Database - Store strategies and results
  • 📈 Visual Analysis - Equity curves, trade distribution, monthly returns
  • 🤖 Paper Trading Ready - Binance Spot Testnet connector for fake-money testing
  • 🛡️ Risk Manager - Position sizing, max daily trades, max positions, max daily loss
  • 🔐 Secure Secrets - API keys loaded from .env, not hardcoded in code

Quick Start

1. Install Requirements

pip install -r requirements.txt

2. Configure Secrets Optional For Binance Testnet

cp .env.example .env
# edit .env with Binance Spot Testnet keys from https://testnet.binance.vision/
# keep BINANCE_TESTNET=true

You can use the analyzer without API keys. Keys are only needed for demo_trade.py.

3. Run the Bot

cd trading-bot
python run.py

4. Optional: Open Visual Signal Dashboard

python3 dashboard.py --open

This creates a graphical HTML chart at analysis/live_signal_dashboard.html using Yahoo Finance data.

5. Choose an Option

[1] 📥 Fetch Gold Data
[2] 📊 List Available Strategies  
[3] 🔬 Backtest Single Strategy
[4] 🏆 Compare All Strategies
[5] 📈 View Analysis Reports
[6] 🗄️ View Database
[7] 🤖 Run Live Bot (Simulation)
[0] 🚪 Exit

Project Structure

trading-bot/
├── 📁 config/         # Configuration settings
├── 📁 data/           # Historical market data
├── 📁 strategies/     # Trading strategy definitions
├── 📁 backtesting/    # Backtesting engine
├── 📁 database/       # SQLite database
├── 📁 bot/            # Trading execution
├── 📁 analysis/       # Performance reports
├── run.py            # Main program
└── requirements.txt  # Python dependencies

Available Strategies

# Strategy Timeframe SL TP Best For
1 EMA Crossover Gold Scalping 5m 10 15 London/NY overlap
2 RSI Mean Reversion Gold 15m 15 30 Trend reversal
3 MACD Trend Following Gold 1h 50 100 Swing trading
4 Support/Resistance Breakout 5m 12 24 NY session
5 VWAP Scalping Gold 1m 5 8 Fast scalping

How It Works

  1. Data Collection - Fetches real XAUUSD data from Yahoo Finance
  2. Strategy Definition - Each strategy has entry/exit rules + risk management
  3. Backtesting - Tests strategy against historical data with spread simulation
  4. Analysis - Generates equity curves, win rates, profit factors
  5. Live Trading - Run the bot (simulation first!)

Configuration

Edit config/settings.py to customize:

TRADING_MODE = 'simulation'  # or 'live'
INITIAL_CAPITAL = 10000.0
ASSET = 'XAUUSD'
DEFAULT_STRATEGY = 'ema_crossover_gold'

Browser Dashboard Recommended

If you do not like using the terminal, open the local browser dashboard:

cd trading-bot
python3 web_dashboard.py

Or double-click this Mac file:

Open Gold Dashboard.command

The dashboard opens at http://localhost:8765 and shows price, candles, indicators, BUY/SELL/WAIT signal, reasons, and a built-in fake-money paper trading account. You can click Paper BUY, Paper SELL, Trade Bot Signal, Close Position, and Reset Paper Account.

OANDA Practice Demo Mac-Friendly

OANDA practice is the recommended broker/demo route on Mac because it uses an API instead of MetaTrader/Windows.

  1. Create an OANDA practice/demo account.
  2. Create an API token.
  3. Copy .env.example to .env.
  4. Add:
OANDA_ENV=practice
OANDA_API_TOKEN=your_oanda_practice_token_here
OANDA_ACCOUNT_ID=your_oanda_practice_account_id_here
OANDA_INSTRUMENT=XAU_USD
OANDA_DEFAULT_UNITS=1

Then run:

python3 web_dashboard.py

If OANDA is configured, the dashboard uses OANDA practice data and demo order buttons. If not, it falls back to Yahoo Finance signal-only mode.

Binance Testnet Demo

cd trading-bot
python demo_trade.py

The demo uses Binance Spot Testnet by default. Binance is mainly for crypto, not XAUUSD gold. Do not put real keys in source code; use .env.

Next Real Milestone

Before any real-money trading, the bot should pass this checklist:

  1. Backtest on multiple market regimes, not only a few days.
  2. Run Binance Testnet / paper trading for weeks.
  3. Keep max risk per trade around 0.5–1%.
  4. Add logs and alerts for every order.
  5. Only consider live mode after consistent out-of-sample results.

Disclaimer

⚠️ IMPORTANT: This bot is for educational purposes.

  • Always test in simulation and paper/testnet mode first
  • Never trade with money you can't afford to lose
  • Past performance does not guarantee future results
  • Always use proper risk management

Author

Samuel + AI Assistant 🤖

Version: 1.0.0 Date: 2026-04-24

About

Educational gold trading strategy analyzer with backtesting and paper trading dashboard

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages