Skip to main content

MetaTrader AI

An AI-powered trading assistant for MetaTrader 4 and MetaTrader 5! Now you can use AI in your trading strategies.

Features

Feature Python MQL
Open, close, modify positions & orders
Modify SL, TP, and entry prices
Fetch positions, orders, and deal history
Account info (balance, equity, margin, etc.)
Symbol info (bid, ask, spread, digits, lots)
OHLCV bars and individual bar prices
Pip value and risk-based lot sizing
MQL5 file compilation
20+ technical indicators (MA, RSI, ATR, ADX, MACD, Stochastic, CCI, WPR, Momentum, Envelopes, Fractals, Bulls/Bears Power, VWAP, PVI, AO, ADR, ATHR, custom)
Chart screenshots and analysis
Open, close, and inspect charts
Enable/disable symbols in Market Watch
Terminal info (OS, CPU, memory, build, connection)
File operations (read, write, copy, move, delete)
Chat GUI (desktop or on-chart panel) ✅ Desktop ✅ On-chart

Requirements

  • Windows operating system (for Python integration, MQL works on all platforms that MetaTrader supports)
  • MetaTrader 5 and Python 3.9.7 or higher for Python integration
  • MetaTrader 4 or MetaTrader 5 for MQL integration
  • OpenAI or DeepSeek API key

Installation

Python

pip install metatrader-ai

MQL

  1. Navigate to MetaTrader's data folder (File → Open Data Folder), then:
cd "C:\Users\YourUsername\AppData\Roaming\MetaQuotes\Terminal\YourTerminalID"
cd MQL4 # or MQL5
cd Include
  1. Clone the repo into the Includes folder:
git clone https://github.com/jblanked/metatrader-ai.git

Usage

Desktop GUI (Python)

from metatrader_ai.app import launch
from metatrader_ai.llm import DEEPSEEK  # or OPENAI

launch(
    api_key="...",
    account_login=...,
    account_password="...",
    broker_server_name="...",
    model=DEEPSEEK,  # default; use OPENAI for OpenAI
)

Or pass a pre-built agent:

from metatrader_ai.app import launch
from metatrader_ai.agent import Agent

agent = Agent(
    api_key="...",
    account_login=...,
    account_password="...",
    broker_server_name="...",
)
launch(agent=agent)

Without an agent (info-only mode):

from metatrader_ai.app import launch
launch()

The Chat tab lets you converse with the AI assistant about your positions, market analysis, and trading strategies. The Info tab displays terminal, symbol, and account details from MetaTrader 5.

One-shot Function

from metatrader_ai.agent import run

result = run(
      api_key=API_KEY,
      account_login=ACCOUNT_LOGIN,
      account_password=ACCOUNT_PASS,
      broker_server_name=BROKER_NAME,
      prompt="What is the daily high of ETHUSD?",
)

Multi-turn Class API

from metatrader_ai.agent import Agent

agent = Agent(
    api_key="...",
    account_login=...,
    account_password="...",
    broker_server_name="...",
)
response = agent.run("What is the daily high of ETHUSD?")
print(response)

Command Line

metatrader-ai \
   --api-key "$DEEPSEEK_API_KEY" \
   --account-login "$ACCOUNT_LOGIN" \
   --account-pass "$ACCOUNT_PASS" \
   --broker-name "$BROKER_NAME" \
   --provider deepseek

Use --provider openai (with OPENAI_API_KEY) to switch to OpenAI.

Single prompt mode:

metatrader-ai --prompt "Show account info" ...

MQL (In-Editor)

#include <metatrader-ai/mql/agent.mqh>

void OnStart()
{
   Agent *agent = new Agent(
      "your-api-key",               // API key
      LLM_PROVIDER_DEEPSEEK,        // provider (default)
      DEEPSEEK_MODEL_V4_FLASH       // model (default)
   );
   string response = agent.run("What is the daily high of ETHUSD?");
   Print("[Agent] ", response);
   delete agent;
}

Use LLM_PROVIDER_OPENAI with an OpenAI model (e.g. OPENAI_MODEL_GPT_5_4_MINI) to switch providers.

Or compile and run app.mq5 (in metatrader-ai/mql) to get an on-chart chat panel with provider/model inputs where you can type prompts and see AI responses.

Notes

  • I am available for hire to integrate your strategy into the system, with advanced prompts and multi layer thinking: https://www.jblanked.com/coding-request/
  • In the Python environment, two LLM providers are supported: DeepSeek (deepseek-v4-flash, default) and OpenAI (gpt-5.4-mini). Switch with --provider in the CLI or model=OPENAI / model=DEEPSEEK (from metatrader_ai.llm) in code. In MQL, switch providers and models with the providerId and providerModel parameters when creating the Agent (e.g. LLM_PROVIDER_OPENAI with OPENAI_MODEL_GPT_5_4_MINI).
  • The python environment works best directly inside of MetaTrader5, but if you run it from a Windows terminal, you should open up MetaTrader5 and log in to your account first, then run the python script for the best experience. The script attempts to open and login to MetaTrader5 if it is not already open.

Disclaimer

Trading and investing involve substantial risk. Past performance is not indicative of future results. This software is provided for educational and informational purposes only and should not be considered as financial advice. Always do your own research and consult with a qualified financial advisor before making any trading decisions. JBlanked and the developers of this software are not responsible for any losses or damages that may occur from using this software.

Release files for metatrader-ai 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metatrader-ai 1.2.2
File Size Uploaded
metatrader_ai-1.2.2.tar.gz 25.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for metatrader-ai 1.2.2
File Interpreter ABI Platform
metatrader_ai-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 52.0 kB

Release files / metatrader_ai-1.2.2.tar.gz

Download URL metatrader_ai-1.2.2.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bb9410b1d6652b329a112cf1c2e3221e9796c68a31a1ae30dc24a4e62a73a138
BLAKE2b-256 checksum
How to use checksums
b4af9689bbccb84839ec8f72f3918f135748d2800a1e5756c4e3722a9614dcd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release files / metatrader_ai-1.2.2-py3-none-any.whl

Download URL metatrader_ai-1.2.2-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d40fe9019ae9f60c9534d78edda14afd8235af85384b9cd04c5efb5cc692408
BLAKE2b-256 checksum
How to use checksums
04ef3384e7ec1a4904cd45ce5752d397c05588a7e1cc43be79cb6b52889f8b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page