Skip to main content
Glama
metatrader-mcp-server

metatrader-mcp-server

πŸ“ˆ Riffmax-TradingBot-AI-RiffEx

Autonomous AI Trading Agent powered by Python and MetaTrader 5 (MT5) MCP β€” real-time market structure analysis, automated signal generation, intelligent order execution, and strict risk guardrails.

Python MetaTrader 5 MCP Protocol License: MIT Status: Active


πŸ“Œ What it does

Riffmax-TradingBot-AI-RiffEx is an autonomous trading agent that operates directly on MetaTrader 5 (MT5) using Python and the Model Context Protocol (MCP):

  • πŸ“Š Real-Time Market Analysis β€” Ingests live tick data, OHLCV candles, order books, and open positions directly through MT5 MCP tools.

  • 🧠 AI Decision Engine β€” Analyzes price action, market liquidity, and volatility metrics using Python-based quantitative models and LLM agent reasoning.

  • ⚑ Direct Order Execution β€” Places, tracks, modifies, and closes market and pending orders programmatically via the MT5 MCP interface.

  • πŸ›‘οΈ Autonomous Risk Guardrails β€” Enforces dynamic lot sizing based on account equity, automatic stop-loss (SL), take-profit (TP), maximum drawdown thresholds, and spread filtering.

  • πŸ“ Structured Logging & Auditing β€” Records all signal evaluations, execution payloads, and deal receipts in JSON/CSV audit trails.


Related MCP server: MetaTrader 5 MCP Server

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             AI Agent Decision Layer (Python)           β”‚
β”‚   β€’ Technical Analysis  β€’ Price Action  β€’ Volatility   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
               Model Context Protocol (MCP)
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    MT5 MCP Server                      β”‚
β”‚   β€’ get_candles_latest   β€’ get_account_info            β”‚
β”‚   β€’ place_market_order   β€’ modify_position             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               MetaTrader 5 (MT5) Terminal              β”‚
β”‚       Broker Execution Β· Live Market Liquidity         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Stack

Component

Technology

Description

Language

Python 3.10+

Core trading engine and quantitative analysis

Execution Protocol

MT5 Model Context Protocol (MCP)

Tool-based interface for market data & order dispatch

Broker Platform

MetaTrader 5 (MT5)

Multi-asset execution terminal (Forex, Indices, Crypto)

Data Processing

NumPy, Pandas

Candle parsing, moving averages, volatility metrics

Risk Management

Custom Python Engine

Lot sizing, trailing stops, daily loss limits

Configuration

.env + config.yaml

Secure credential isolation


πŸš€ Quick Start

Prerequisites

  • Python 3.10+

  • MetaTrader 5 terminal installed and logged into your broker account

  • MT5 MCP server configured

1. Clone & Install

git clone https://github.com/Riffmax2030-hub/Riffmax-TradingBot-AI-RiffEx.git
cd Riffmax-TradingBot-AI-RiffEx
pip install -r requirements.txt

2. Configure Environment

cp .env.example .env
# Edit .env with your credentials β€” NEVER commit real .env files

.env.example template:

MT5_ACCOUNT=your_account_number
MT5_PASSWORD=your_password
MT5_SERVER=your_broker_server
MAX_RISK_PER_TRADE_PERCENT=1.0
MAX_DAILY_DRAWDOWN_PERCENT=3.0

3. Run the Trading Agent

python main.py

πŸ“ Project Structure

Riffmax-TradingBot-AI-RiffEx/
β”œβ”€β”€ agent/
β”‚   β”œβ”€β”€ market_analyzer.py    # Price action & indicator analysis
β”‚   β”œβ”€β”€ decision_engine.py    # Signal generation logic
β”‚   β”œβ”€β”€ mcp_bridge.py         # MT5 Model Context Protocol interface
β”‚   └── risk_guard.py         # Dynamic lot sizing & risk limits
β”œβ”€β”€ config/
β”‚   └── config.yaml           # Symbol lists, timeframe, max spread
β”œβ”€β”€ logs/                     # Trade logs & audit trails (gitignored)
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_market_analyzer.py
β”‚   └── test_risk_guard.py
β”œβ”€β”€ .env.example              # Template with placeholders
β”œβ”€β”€ .gitignore                # Excludes credentials, logs, caches
β”œβ”€β”€ requirements.txt
└── README.md

πŸ” Security & Risk Disclaimer

CAUTION

Financial & Credential Security:

  • Never hardcode broker account numbers, server details, or passwords in code or commits.

  • All sensitive configurations are loaded strictly via environment variables.

  • Trading financial markets carries risk. Use a demo account for testing before any live deployment.


πŸ“„ License

MIT Β© Sherif Akanmu

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to interact with the MetaTrader 5 trading platform for market data analysis, placing trades, and managing trading positions. Provides comprehensive access to forex and financial market operations through the Model Context Protocol.
      1
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants to connect to MetaTrader 5 for trading, market data access, and account management through the Model Context Protocol.
      107 PyPI
      245
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to trade on MetaTrader 5 using natural language, supporting account management, order placement, and real-time market data.
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables read and execution access to multiple MetaTrader 5 accounts, allowing an AI assistant to manage positions, P&L, prices, indicators, history, logs, and trades across accounts.
      1
      MIT