MT5 · XAUUSD · AI-Powered

GoldMind AI

An AI-powered trading system that uses ChatGPT to analyze gold (XAUUSD) price charts and automatically place trades in MetaTrader 5. Runs entirely on your own computer.

Open Source — Free to use. Requires your own OpenAI API key. Expires 2026-03-31. By Syarief Azman.

Architecture

How It Works

A seamless pipeline from price data to intelligent trade execution.

1

EA Collects Data

Every candle timeframe (e.g. 15 minutes), the EA collects the latest candle data (OHLC prices) from the XAUUSD chart and sends it to your local Python server.

2

Server Forwards to AI

The FastAPI backend receives the price data and forwards it to OpenAI's ChatGPT API with a specialized gold analysis prompt.

3

AI Analyzes Market

ChatGPT analyzes the price action and responds with a structured JSON signal: buy stop, sell stop, or no trade — including entry, SL, and TP levels.

4

Signal Validation

The EA runs the AI signal through 6 safety filters: spread check, stop level, entry price, SL direction, R:R ratio, and lot size validation.

5

Order Placement

If all filters pass, the EA places a pending order (buy stop or sell stop). If the order isn't triggered within 4 hours, it's cancelled.

6

Cost Optimization

While a position is open, the EA skips signal requests entirely to save API costs. A new signal is only requested after the position is closed.

Capabilities

Key Features

Enterprise-grade AI trading with robust safety mechanisms.

🤖

AI-Powered Analysis

Uses OpenAI (ChatGPT) to analyze XAUUSD price charts and generate trading signals with structured JSON output.

🛡️

6 Safety Filters

Every signal passes through spread, stop level, entry price, SL direction, R:R ratio, and lot size validation.

📊

Pending Orders

Places buy stop or sell stop pending orders, automatically cancelled after 4 hours if not triggered.

💰

Smart Lot Sizing

Calculates lot size based on your risk percentage and the distance between entry and stop loss.

🔄

Auto Signal Refresh

Requests fresh AI signals at configurable intervals. Skips requests when a position is already open to save API costs.

Local Processing

Runs entirely on your computer — Python FastAPI backend communicates between MT5 and OpenAI API.

📈

XAUUSD Specialist

AI prompt specifically designed to analyze gold price action for optimal entry, stop loss, and take profit levels.

🔐

Secure API Key

Your OpenAI API key stays on your machine, stored in a local .env file that never leaves your computer.

Prerequisites

What You Need

Everything required to get GoldMind AI up and running.

🐍

Python 3.8+

Required to run the FastAPI backend server

📈

MetaTrader 5

Your broker's MT5 platform with a XAUUSD chart

🔑

OpenAI API Key

Paid API key from platform.openai.com — each signal costs ~$0.01–$0.02

📋 Before You Start — What You Need

GoldMind AI has two parts: a Python server (runs on your computer) and an EA in MetaTrader 5. The server receives market data from the EA and forwards it to ChatGPT for analysis.

Python 3.10+ — Download from python.org. Important: During installation, check the box that says "Add Python to PATH".
MetaTrader 5 — Your broker's version, logged in and able to see XAUUSD charts.
OpenAI API Key — Get one at platform.openai.com/api-keys. Click "+ Create new secret key" and copy it (starts with sk-). You also need API credits — add $5–10 at Billing. Each signal costs ~$0.01–$0.05.
1

Download & Extract the Project

Download the GoldMind AI source code and extract it to any folder on your computer (e.g. C:\goldmind-ai). Inside you'll find two important folders: backend/ (the Python server) and mt5/ (the MetaTrader files).
2

Set Up the Python Backend

Open a terminal: press Windows + R, type cmd, press Enter. Then run these commands one by one:

cd "C:\goldmind-ai\backend"
pip install -r requirements.txt
Wait until it says "Successfully installed..." (1–2 minutes).

Next, set up your API key. Copy the example file and edit it:copy .env.example .env
notepad .env
In Notepad, replace sk-your-key-here with your actual OpenAI API key. Save and close.
3

Start the Server

In the same terminal window, run:python main.pyYou should see: Uvicorn running on http://0.0.0.0:8000

To verify: Open a new terminal and run curl http://127.0.0.1:8000/health — you should get {"status":"ok"}.

⚠️ Keep this terminal window open! If you close it, the EA stops getting signals. Minimize it, but don't close it.
4

Install EA Files in MetaTrader 5

Open MT5 → File → Open Data Folder. A Windows Explorer window opens — this is your MT5 data folder.

Copy the JSON parser: From your project's mt5\Include\JASONNode.mqh, copy it into MQL5\Include\.

Copy the EA: From your project's mt5\Experts\GoldMind_AI.mq5, copy it into MQL5\Experts\.

Compile: In MT5, press F4 to open MetaEditor. Open GoldMind_AI.mq5, press F7 to compile. You should see 0 errors, 0 warnings. Close MetaEditor.

💡 You can also download the pre-compiled .ex5 file using the download button above and place it directly in MQL5\Experts\ — no compilation needed.
5

Allow WebRequest in MT5 (Critical!)

Without this step, the EA cannot talk to your server and you'll get error 4014.

In MT5: Tools → Options → Expert Advisors tab.
☑ Check "Allow WebRequest for listed URL".
Click Add and type exactly: http://127.0.0.1:8000
Click OK.
6

Attach EA to a XAUUSD Chart

⚠️ XAUUSD only! The AI is specifically trained for gold. Attaching to other symbols will produce bad signals.

Open a XAUUSD chart (your broker may call it GOLD, XAUUSDm, etc.). Press Ctrl+N to open the Navigator. Expand Expert Advisors, find GoldMind_AI, and drag it onto the chart.

In the dialog box:
Common tab: ☑ Check Allow Algo Trading
Inputs tab: Leave defaults or adjust: RiskPercent = 1.0 (1% per trade), MaxSpreadPoints = 50
Click OK.

Finally, make sure the Algo Trading button in the MT5 toolbar is enabled (green icon, not red).
7

Verify It's Working

Check the Experts tab at the bottom of MT5. You should see messages like:=== GoldMind AI initialized ===
Backend URL: http://127.0.0.1:8000/signal
Requesting new signal...
Signal: bias=bullish confidence=0.72
Order placed successfully!
Check the Trade tab — you should see a pending order (buy stop or sell stop) for XAUUSD. The EA will automatically cancel unfilled orders after 4 hours and request a fresh signal.

After PC reboot: Start the Python server first (cd backendpython main.py), then open MT5. The EA will resume automatically.
Configuration

EA Settings

Fine-tune the AI trading behavior to match your risk tolerance.

ParameterDefaultDescription
BackendURLhttp://localhost:8000Address of your local Python FastAPI server
MaxSpreadPoints50Maximum allowed spread in points. Signals rejected if spread exceeds this value
RiskPercent1.0Percentage of account equity to risk per trade
MinRR1.5Minimum reward-to-risk ratio required to place a trade
TimeframePERIOD_M15Candle timeframe used for price data sent to the AI
CandleCount100Number of historical candles sent to the AI for analysis
RefreshHours4.0Hours between signal refresh requests. Also the pending order expiry time
MagicNumber777Unique identifier for trades placed by this EA
Timeout30000WebRequest timeout in milliseconds for server communication
Project

File Structure

Clean, organized codebase with clear separation of concerns.

goldmind-ai/
├── backend/              ← Python backend server
│   ├── main.py           ← FastAPI + OpenAI integration
│   ├── requirements.txt  ← Python dependencies
│   ├── .env.example      ← Template for API key
│   └── .env              ← Your actual API key (secret!)
├── mt5/                  ← MetaTrader 5 files
│   ├── Include/
│   │   └── JASONNode.mqh ← JSON parser library
│   └── Experts/
│       └── GoldMind_AI.mq5  ← The Expert Advisor
├── .gitignore
└── README.md
⚠️ Important

Important Warnings

Please read before using GoldMind AI with real money.

🧪
Demo First

Always test on a demo account before using real money

🤖
AI Isn't Perfect

Past performance does not guarantee future results — AI predictions can be wrong

🔑
Protect Your Key

Keep your API key secret — treat it like a password

👀
Monitor Trades

Don't just set and forget, especially in the beginning

📊
Market Conditions

Works best in trending/breakout conditions, not during choppy/ranging markets

💻
Keep Running

Both the server and MT5 need to be running. A VPS is recommended for 24/7 operation

Support

Frequently Asked Questions

No. This is an AI-assisted trading tool, not a money-printing machine. AI can make wrong predictions. Always test on a demo account first, and never risk money you can't afford to lose.

Each signal request costs about $0.01–$0.02 in OpenAI API usage. If the EA places an order or holds a position, it stops polling to save costs.

Yes! Run the Python server and MT5 on the same VPS. Change BackendURL if they're on different machines.

No — the AI prompt is specifically designed to analyze gold price action. Using other symbols would produce unreliable signals.

Yes! Edit OPENAI_MODEL in backend/.env. Options include gpt-4o-2024-08-06, gpt-5-mini, and gpt-5.

Yes. The key is stored only on your computer in the .env file. It's never sent to MT5 or anywhere else.