Skip to main content

An AI-powered trading assistant for MetaTrader 5.

Project description

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 API key

Installation

Python Package Usage (pip)

Install from PyPI:

pip install metatrader-ai

Use the convenience function (one-shot if prompt is provided, interactive mode if omitted):

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?",
)

Use the class API for multi-turn conversations:

from metatrader_ai.agent import Agent

agent = Agent(API_KEY, ACCOUNT_LOGIN, ACCOUNT_PASS, BROKER_NAME)
response = agent.run("What is the daily high of ETHUSD?")
print(response)

Use the command line entrypoint:

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

Optional single prompt mode:

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

MQL

  1. Open up Terminal and navigate to where MetaTrader's data folder is located. You can find this by going to MetaTrader, clicking on File > Open Data Folder. Then copy and paste that path into your terminal:
cd "C:\Users\YourUsername\AppData\Roaming\MetaQuotes\Terminal\YourTerminalID"
  1. Navigate to the MQL4 or MQL5 folder, depending on which version of MetaTrader you are using:
cd MQL4
  1. Navigate into the Includes folder:
cd Include
  1. Clone (or download) this repository into the Includes folder:
git clone https://github.com/jblanked/metatrader-ai.git
  1. Create a file called secrets.mqh

Windows:

ni secrets.mqh 

Mac/Linux:

touch secrets.mqh
  1. Add your OpenAI API key to the secrets.mqh file:
#define OPENAI_API_KEY "your_openai_api_key"

Or define OPENAI_API_KEY in your own code before including the agent.mqh file.

  1. Open up MetaTrader and you should see the metatrader-ai folder in the Navigator under Include. You can now include the agent.mqh file in your MQL scripts to use the AI functions:
#include <metatrader-ai/mql/agent.mqh>

void OnStart()
{
   Agent *agent = new Agent();

    // get a response
   string response = agent.run("What is the daily high of ETHUSD?");
   Print("[Agent] ", response);

   delete agent; // clean up the agent
}

Or you can compile and run the app.mq5 file (within the metatrader-ai/mql folder) to see a demo of the AI assistant in action. It will create a panel on your chart where you can type in prompts and see the AI's 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/
  • I configured this with one of the cheapest models, gpt-5-nano, which is $0.05 for 1 million tokens. You can use a smarter model, and optionally switch to claude, but for basic trading logic, the nano is sufficient and very cost effective (roughly $0.05 per 50 requests)
  • The python environment works best directly inside of MetaTrader5, but if you run it from a Windows/Linux 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metatrader_ai-1.2.0.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metatrader_ai-1.2.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file metatrader_ai-1.2.0.tar.gz.

File metadata

  • Download URL: metatrader_ai-1.2.0.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for metatrader_ai-1.2.0.tar.gz
Algorithm Hash digest
SHA256 bd79d1997e2d2f3b060513c2d3d09782aeb7ef6aabeddf155596d78e97855f32
MD5 f67176991de5479ae6b4c71376df6d42
BLAKE2b-256 494787460a255751a22e898f11759454e5bb73dfc9c97fd8b7d62c291de14287

See more details on using hashes here.

File details

Details for the file metatrader_ai-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: metatrader_ai-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for metatrader_ai-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c0cfd5dea7885ea255dbb238d585704c380ffd79c99af93656a0d19e394591
MD5 deede73500949bca3cc66baa22ddc490
BLAKE2b-256 0315b9f0a3f6c6f4071e95afa31b8a46f3d3b26f2f8426ac103731828fce8cc6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page