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.

The Assistant can:

  • Open positions and pending orders
  • Close positions
  • Delete pending orders
  • Modify stop loss and take profit levels
  • Get current and historical price data
  • Get account information and trading history

Requirements

  • Windows or Linux operating system
  • MetaTrader 4 or MetaTrader 5
  • Python 3.9.7 or higher
  • 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" ...

Python

  1. Clone (or download) this repository: git clone https://github.com/jblanked/metatrader-ai.git
  2. Create a virtual environment and install the required dependencies:

Windows:

cd metatrader-ai/python
python -m venv venv
./venv/Scripts/activate
pip install -r requirements.txt
ni secrets.py 

Linux:

cd metatrader-ai/python
python3 -m venv venv
source venv/bin/activate 
pip install -r requirements.txt
touch secrets.py 
  1. Open secrets.py and add your OpenAI API key, Account Number, Account Password, and Broker Server Name:
OPENAI_API_KEY = "your_openai_api_key"
ACCOUNT_NUMBER = 123456
ACCOUNT_PASSWORD = "your_account_password"
BROKER_SERVER_NAME = "your_broker_server"
  1. Run the Python script to start the AI assistant:
python main.py

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 

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
}

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.1.0.tar.gz (20.3 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.1.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: metatrader_ai-1.1.0.tar.gz
  • Upload date:
  • Size: 20.3 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.1.0.tar.gz
Algorithm Hash digest
SHA256 2ff5576a3e9b6907c466f079af9baea440bcc4a62d638973938538d1421086e4
MD5 f13198fddf9ae685555af1a34bcebb6d
BLAKE2b-256 cdf528016a9fd43d5f26f53b2047572cb1062ce12289d83e07c64ef713010874

See more details on using hashes here.

File details

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

File metadata

  • Download URL: metatrader_ai-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ce72ef55f913ab2c39de8f492a39d875b7d0d8c06fa066308345e49a704636a
MD5 75d503087a49b879de8fcf750f20e994
BLAKE2b-256 6f055d58f8136d82b03c77c86c9e2600ed247fd8c2f739f1ba063d9e8541608e

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