Skip to main content

Overview

The XAUUSD Trading Assistant AI is built on a multi-layered architecture that combines real-time market data analysis, AI-powered decision making, and an interactive web interface. The system achieves 65% accuracy for profitable trades in live trading environments.

Core Components

Trading Bot Engine

The XAUUSDTradingBot class serves as the core engine, orchestrating market data collection, technical analysis, and AI decision-making processes.

Streamlit Dashboard

Interactive web interface (app.py) that provides real-time visualization of trading signals, market analysis, and system controls.

MetaTrader 5 Integration

Real-time market data feed through MetaTrader 5 API, providing accurate price data across multiple timeframes.

Groq LLM Engine

AI-powered analysis using Groq’s language models via LangChain for intelligent trade signal generation.

System Flow

The system operates in a continuous analysis cycle, processing market data every 30 minutes (configurable) or on-demand through the dashboard.

1. Data Collection

The bot connects to MetaTrader 5 and retrieves OHLCV (Open, High, Low, Close, Volume) data across six timeframes:
  • Daily (D1)
  • 4-Hour (H4)
  • 1-Hour (H1)
  • 30-Minute (M30)
  • 15-Minute (M15)
  • 5-Minute (M5)

2. Technical Analysis

For each timeframe, the system calculates:
  • RSI (Relative Strength Index): Momentum oscillator for overbought/oversold conditions
  • EMA (Exponential Moving Average): Trend direction and strength
  • ATR (Average True Range): Volatility measurement for risk management
  • Order Blocks: Key supply/demand zones
  • Fair Value Gaps (FVG): Price inefficiencies for potential trade entries

3. AI Decision Engine

The technical features are fed into the Groq LLM through LangChain, which:
  • Analyzes multi-timeframe confluence
  • Identifies high-probability trade setups
  • Generates actionable trading signals with entry, stop-loss, and take-profit levels
  • Provides market context and reasoning

4. Dashboard Presentation

Results are displayed through the Streamlit interface with:
  • Technical analysis summaries
  • Market data by timeframe
  • Trading signals with risk parameters
  • Current spread monitoring
  • Auto-refresh capabilities

Data Flow Diagram

┌─────────────────┐
│  MetaTrader 5   │
│   Market Data   │
└────────┬────────┘


┌─────────────────────────┐
│  XAUUSDTradingBot       │
│  ├─ Data Collection     │
│  ├─ Technical Analysis  │
│  └─ Feature Extraction  │
└────────┬────────────────┘


┌─────────────────────────┐
│   Groq LLM (LangChain)  │
│  ├─ Pattern Recognition │
│  ├─ Confluence Analysis │
│  └─ Signal Generation   │
└────────┬────────────────┘


┌─────────────────────────┐
│   Streamlit Dashboard   │
│  ├─ Analysis Tab        │
│  ├─ Trading Signal Tab  │
│  └─ Control Panel       │
└─────────────────────────┘

Technology Stack

The system is built with Python 3.8+ and leverages industry-standard libraries for trading and AI.
Core Technologies:
  • MetaTrader5: Real-time market data API
  • Pandas & NumPy: Data processing and numerical computations
  • LangChain-Groq: AI integration framework
  • Streamlit: Web dashboard framework

Session Management

The dashboard uses Streamlit’s session state to maintain analysis results between interactions, reducing unnecessary API calls.
Key session variables:
  • analysis_result: Stores the latest market analysis
  • last_update: Timestamp of the most recent analysis
  • last_refresh: Tracks auto-refresh timing

API Integration

The bot requires a Groq API key stored securely in .streamlit/secrets.toml:
GROQ_API_KEY = "your-groq-api-key"
This key is accessed via st.secrets and passed to the XAUUSDTradingBot constructor during initialization.

Scalability Considerations

  • Modular Design: Each component (data collection, analysis, AI) is separated for easy maintenance
  • Configurable Timeframes: Multi-timeframe analysis can be adjusted based on trading strategy
  • Auto-Refresh: Automated 30-minute refresh cycles reduce manual intervention
  • Error Handling: Comprehensive exception handling ensures system stability

Performance Metrics

The system has been tested on real accounts with a 65% accuracy rate for profitable trades, demonstrating the effectiveness of combining multi-timeframe analysis with AI decision-making.

Build docs developers (and LLMs) love