MetaTrader 5 Python User Group - how to use Python in Metatrader - page 37

 
Renat Fatkhullin:

Since version 5.0.15 the python library works in a new format which is not compatible with the old format and requires the latest beta of the terminal.

We will post updated documentation and examples soon

Is it possible to download the old version of the library temporarily?

 
Dmitri Custurov:

Is it possible to temporarily download an old version of the library?

https://pypi.org/project/MetaTrader5/5.0.11/#files

MetaTrader5
MetaTrader5
  • 2020.01.24
  • pypi.org
Download the file for your platform. If you're not sure which to choose, learn more about installing packages. Files for MetaTrader5, version 5.0.11 Filename, size File type Python version Upload date Hashes MetaTrader5-5.0.11-cp36-cp36m-win32.whl (31.7 kB) MetaTrader5-5.0.11-cp36-cp36m-win_amd64.whl (43.3 kB...
 

I can't resist expressing an opinion on integrations. I'm in favour with both hands. Python, neural networks, AI, compiler extensions and so on and so forth...

But there is one BUT.

No matter how cool the development environment is, it should be mass, right? And how can it be mass if its toolkit is usual primitives? NO - not usual primitives but GENICAL PRIMITIVES. SUPERCOMPLEX PRIMITIVES.

Let's take the CCanvas class - it's an assembly of graphic primitives. Can we assemble a lot of them? A lot. But how much brains and labour is needed for that? - A LOT. A sea of brains and labour to create the THING. How many are capable of it? - Just a few.

Again the main question: how could the development environment tools become popular, if they APRIORI assume the presence of uncommon design abilities in a man? Mass availability, in such a case, is out of the question.

I will paraphrase briefly:

If a person is familiar with Python, C++, MQL5, Algotrading and has extraordinary design abilities, what difference does it make to him what professional environment to create his THING in? He'll use MINIMUM of features and produce MAXIMUM of results. Others will try to use everything and won't create anything, because of the complexity threshold of the toolkit.

So who and what should you focus on?

 

Version lower down to the lowest available 5.0.10

444

Apparently we will have to wait for updates.

 

Greetings to all!

Why do I get this error even though I have followed examples correct?

Greetings all!

Why do I get this error even though I have followed examples correct?


 
Renat Fatkhullin:
Is python enabled in visual studio?

Because of the zoo of pythons deployed indirectly or automatically by different systems, it is easy to get libraries installed in another python copy and then try to run other copies.

Sort out the pythons, please. Those who move to python must be prepared to spend the rest of their lives battling with libraries, dependencies, and incompatibilities.

This is the fate of a pythonist - to build an environment of libraries and pray that some library update doesn't mess up another unknown number of libraries.

There is no Python zoo. There is an environment. There may be more than one environment. The user chooses which environment to use.

Python environment should be initialized before running a script.

I have considered this in my library . Here is environment initialization function code.

MetaTrader 5 (MQL5) + Python 3 DLL для Forex, CFD и Futures
  • roffild.com
Использование MetaTrader с Python 3 на финансовых фондовых биржах, Forex, CFD и Futures. Из MetaTrader можно получать котировки в Python, но нет полноценной связи между ними. Пост одного из разработчиков. Главная идея и отличие этой обертки от остальных: обмен данными между MQL и Python через заранее созданные функции. Это самый быстрый и...
 

Maybe it's time to give up on MetaEditor? Why cram different technologies into your IDE when you can get a full-fledged ready-made one?

Everyone is creating a module for the IDE these days:

microsoft visual studio code

jetbrains intellij idea

 
Roffild:

There is no Python zoo. There is the concept of Environment. There can be several environments on a computer. It is up to the user to choose which environment to use.

Python environment should be initialized before running a script.

I have considered this in my library . Here is the code of environment initialization function.

We easily support environments. Have a look at the compiler settings in the editor, please.

I meant about zoo in the sense that the terminal can select one environment (eg default path), and libraries will be manually put by user to another environment.


Tomorrow we will release a new beta of the terminal and a new python library. All old methods and examples are broken because we have rewritten the api and library from scratch.

The new set of api is wide and allows you to fully manage trading and has access to open positions and deal history.

You can now write full-fledged Metatrader robots directly in Python.

 

New version of MetaTrader 5 for Python 5.0.18 and MetaTrader 5 build 2319 beta:

  • MT5 beta download via Help -> Check beta version
  • python library:
    pip install --upgrade metatrader5
    

As all api have changed, the old examples no longer work.

Here is the new feature set:

initialize(path=None)                              Establish connection with the MetaTrader 5 Terminal
wait()                                             Wait for the MetaTrader 5 Terminal to connect to a broker's server
shutdown()                                         Disconnect from the MetaTrader 5 Terminal

version()                                          Get the MetaTrader 5 Terminal version
terminal_info()                                    Get the parameters of the MetaTrader 5 terminal
account_info()                                     Returns information of current account

copy_ticks_from(symbol, from, count, flags)                Get ticks starting from the specific date
copy_ticks_range(symbol, from, to, flags)                  Get ticks from the specified period
copy_rates_from(symbol, timeframe, from, count)            Get bars starting from the specific date
copy_rates_from_pos(symbol, timeframe, start_pos, count)   Get bars starting from the specified position
copy_rates_range(symbol, timeframe, date_from, date_to)    Get bars from the specified period

positions_total()                                          Returns the number of open positions
positions_get([symbol=\"SYMBOL\"],[ticket=TICKET])         Returns all open positions, can be filtered by symbol or ticket

orders_total()                                             Returns the number of orders
orders_get([symbol=\"SYMBOL\"],[ticket=TICKET])            Returns all orders, can be filtered by symbol or ticket

history_orders_total(from, to)                             Returns the number of orders in selected range from the history
history_orders_get(from, to)                               Returns orders in selected range from the history or filtered by position id, ticket

history_deals_total(from, to)                              Returns the number of deals in selected range from the history
history_deals_get(from, to)                                Returns deals in selected range from the history or filtered by position id, ticket

order_check(request)                                                Checks if there are enough funds to execute the required trade operation
order_send(request)                                                 Sends trade requests to a server
order_calc_margin(action, symbol, volume, price)                    Calculates the margin required for the specified order
order_calc_profit(action, symbol, volume, price_open, price_close)  Calculates the profit for the current account, in the current market conditions, based on the parameters passed

symbol_info(symbol)                                        Returns full information for a specified symbol
symbol_info_tick(symbol)                                   Returns current prices of a specified symbol
symbol_select(symbol,[enable])                             Selects a symbol in the Market Watch window or removes a symbol from the window

Example:

import MetaTrader5 as mt5
import time

mt5.initialize()
mt5.wait()

dev = 0.00010;
symbol = "EURUSD"
buy_price = 0

mt5.symbol_select(symbol)

time.sleep(1)
p = mt5.symbol_info_tick(symbol)
prev_price = p.ask

while True:
    p = mt5.symbol_info_tick(symbol)
    print(p.bid,'/',p.ask)
    
    if p.ask > prev_price and buy_price == 0:
            print("Buy ", p.ask)
            r = mt5.Buy(symbol, 0.01)
            if r.retcode == mt5.TRADE_RETCODE_DONE:
                buy_price = p.ask;
    elif buy_price > 0 and p.ask + dev < buy_price:
        print("Buy(close) ", p.bid)
        mt5.Close(symbol)
        buy_price = 0

    prev_price = p.ask
    time.sleep(1)

mt5.shutdown()
 
Renat Fatkhullin:

New version of MetaTrader 5 for Python 5.0.18 and MetaTrader 5 build 2319 beta:

  • MT5 beta download via Help -> Check beta version
  • python library:

Since all api have changed, the old examples no longer work.

Everything is changing dynamically.

Don't really want to get caught up in this mess.

Probably worth waiting forWinML implementationwith ONNX. And before that to grasp the ML theory. Fortunately, now plenty of available literature and various courses.

Reason: