- initialize
- login
- shutdown
- version
- last_error
- account_info
- terminal_info
- symbols_total
- symbols_get
- symbol_info
- symbol_info_tick
- symbol_select
- market_book_add
- market_book_get
- market_book_release
- copy_rates_from
- copy_rates_from_pos
- copy_rates_range
- copy_ticks_from
- copy_ticks_range
- orders_total
- orders_get
- order_calc_margin
- order_calc_profit
- order_check
- order_send
- positions_total
- positions_get
- history_orders_total
- history_orders_get
- history_deals_total
- history_deals_get
MetaTrader module for integration with Python
MQL5 is designed for the development of high-performance trading applications in the financial markets and is unparalleled among other specialized languages used in the algorithmic trading. The syntax and speed of MQL5 programs are very close to C++, there is support for OpenCL and integration with MS Visual Studio. Statistics, fuzzy logic and ALGLIB libraries are available as well. MetaEditor development environment features native support for .NET libraries with "smart" functions import eliminating the need to develop special wrappers. Third-party C++ DLLs can also be used. C++ source code files (CPP and H) can be edited and compiled into DLL directly from the editor. Microsoft Visual Studio installed on user's PC can be used for that.
Python is a modern high-level programming language for developing scripts and applications. It contains multiple libraries for machine learning, process automation, as well as data analysis and visualization.
MetaTrader package for Python is designed for convenient and fast obtaining of exchange data via interprocessor communication directly from the MetaTrader 5 terminal. The data received this way can be further used for statistical calculations and machine learning.
Installing the package from the command line:
pip install MetaTrader5 |
Updating the package from the command line:
pip install --upgrade MetaTrader5 |
Functions for integrating MetaTrader 5 and Python
Function |
Action |
---|---|
Establish a connection with the MetaTrader 5 terminal |
|
Connect to a trading account using specified parameters |
|
Close the previously established connection to the MetaTrader 5 terminal |
|
Return the MetaTrader 5 terminal version |
|
Return data on the last error |
|
Get info on the current trading account |
|
Get status and parameters of the connected MetaTrader 5 terminal |
|
Get the number of all financial instruments in the MetaTrader 5 terminal |
|
Get all financial instruments from the MetaTrader 5 terminal |
|
Get data on the specified financial instrument |
|
Get the last tick for the specified financial instrument |
|
Select a symbol in the MarketWatch window or remove a symbol from the window |
|
Subscribes the MetaTrader 5 terminal to the Market Depth change events for a specified symbol |
|
Returns a tuple from BookInfo featuring Market Depth entries for the specified symbol |
|
Cancels subscription of the MetaTrader 5 terminal to the Market Depth change events for a specified symbol |
|
Get bars from the MetaTrader 5 terminal starting from the specified date |
|
Get bars from the MetaTrader 5 terminal starting from the specified index |
|
Get bars in the specified date range from the MetaTrader 5 terminal |
|
Get ticks from the MetaTrader 5 terminal starting from the specified date |
|
Get ticks for the specified date range from the MetaTrader 5 terminal |
|
Get the number of active orders. |
|
Get active orders with the ability to filter by symbol or ticket |
|
Return margin in the account currency to perform a specified trading operation |
|
Return profit in the account currency for a specified trading operation |
|
Check funds sufficiency for performing a required trading operation |
|
Send a request to perform a trading operation. |
|
Get the number of open positions |
|
Get open positions with the ability to filter by symbol or ticket |
|
Get the number of orders in trading history within the specified interval |
|
Get orders from trading history with the ability to filter by ticket or position |
|
Get the number of deals in trading history within the specified interval |
|
Get deals from trading history with the ability to filter by ticket or position |
Example of connecting Python to MetaTrader 5
- Download the latest version of Python 3.8 from https://www.python.org/downloads/windows
- When installing Python, check "Add Python 3.8 to PATH%" to be able to run Python scripts from the command line.
- Install the MetaTrader 5 module from the command line
pip install MetaTrader5 |
- Add matplotlib and pandas packages
pip install matplotlib
|
- Launch the test script
from datetime import datetime
|
- Get data and chart
[2, 'MetaQuotes-Demo', '16167573']
|