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

 
Maxim Dmitrievsky:

Renat, is there any update on ONNX support?

No.

There is no demand and no prepared audience yet.

 

A lot of changes have been made over the past year, old scripts are no longer working.

There is a terminal MT5 build 2361, 32bit on Windows 7. The terminal itself works, but connection of python scripts has stopped working (although it was working at the beginning of the year).

Obviously due to terminal updates, nothing else has changed. For the test run a simple script

import MetaTrader5 as mt5
from time import sleep

mt5.initialize()
print('start')
print(mt5.terminal_info())
sleep(10) 

mt5.shutdown()
print('end')

Question what version of MetaTrader5 python module should I install to make it work again ? (Or how to rollback the terminal updates ?)

I tried different versions of module - all of them have errors. Those that are newer give out -10003, 'IPC initialize failed, MetaTrader 5 x64 not found',

some of them initialize and run terminal, but they return RuntimeError: IPC recv failed in 'py_test.py'.

The oldest 5.0.10 has other commands, but they don't work either.

Terminal can't update to newer versions, there was some working version of python module, but I can't find it now.

64-bit version of the terminal requires OS updates and a lot of other updates, plus 64-bit OS eats many times more memory and disk space, bad choice. In general, the policy of auto-updating anything is bad. If it works, do not touch it.

In general, you should have a table in the documentation which versions are compatible with which, if you do not support compatibility with older versions and updates are forced.

Автоматическое обновление - Для продвинутых пользователей - Справка по MetaTrader 5
Автоматическое обновление - Для продвинутых пользователей - Справка по MetaTrader 5
  • www.metatrader5.com
В платформу встроена система автоматического обновления. Она позволяет своевременно получать и устанавливать новые версии программы. Эту систему отключить нельзя. Порядок обновления При подключении к торговому серверу происходит проверка наличия обновлений платформы. Если найдено обновление какого-либо из компонентов торговой платформы...
 
Lyuk:


Support for the 32-bit operating system was disabled many builds ago. The terminal has changed a lot since then. Hence the likely solution to your problem: you MUST use 64-bit Windows 10.

 

But there WAS a compatible build of the terminal and module, you can just install them, without any new features.

And requiring Windows 10 64 bit is too much for a program like the terminal. It is too heavy, greedy, unreliable to run anything that requires long-term operation. There are also problems with automatic updates. It's a pity that MT is tied to this system.

 
Vladimir Karputov:

You NEED to use 64-bit Windows 10.

What's wrong with Windows 7 x64? Did I miss another update???

 
Aleksey Vyazmikin:

What's wrong with Windows 7 x64? Did I miss another news???

Seems to me 7 is better than 10. no orientation on mobile systems.

 
Valeriy Yastremskiy:

For me 7 is better than 10. no orientation to mobile systems.

I agree, worked on 10 for almost a year and was happy with 7 when I came home!

 
Renat Fatkhullin:

No.

As long as there is no demand and no prepared audience.

4 people have expressed demand so far, in the machine learning topic :) it seems to me that if there is an opportunity and a couple of articles on the topic, pythonists will start to port models. Especially English-speaking ones.
 
2020.11.09 09:43:31.509 Terminal        MetaTrader 5 x64 build 2670 started for MetaQuotes Software Corp.
2020.11.09 09:43:31.510 Terminal        Windows 10 build 19042, Intel Core i7-9750 H  @ 2.60 GHz, 23 / 31 Gb memory, 1665 / 1861 Gb disk, IE 11, UAC, GMT+2
2020.11.09 09:43:31.510 Terminal        C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075


I run it both as a script in MetaEditor and in jupyter notebook.

Python version:  sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)
Scikit-Learn version:  0.23.1


I can't print the first five lines of the DataFrame object.

I take the script from the 'data folder'\Scripts\Python\copy_rates_from.py' and add the lines:

from datetime import datetime
import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)

# импортируем модуль pandas для вывода полученных данных в табличной форме
import pandas as pd
pd.set_option('display.max_columns', 500) # сколько столбцов показываем
pd.set_option('display.width', 1500)      # макс. ширина таблицы для показа
# импортируем модуль pytz для работы с таймзоной
import pytz

# установим подключение к терминалу MetaTrader 5
if not mt5.initialize():
    print("initialize() failed")
    mt5.shutdown()

# установим таймзону в UTC
timezone = pytz.timezone("Etc/UTC")
# создадим объект datetime в таймзоне UTC, чтобы не применялось смещение локальной таймзоны
utc_from = datetime(2020, 1, 10, tzinfo=timezone)
# получим 10 баров с EURUSD H4 начиная с 01.10.2020 в таймзоне UTC
rates = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_H4, utc_from, 10)

# завершим подключение к терминалу MetaTrader 5
mt5.shutdown()
# выведем каждый элемент полученных данных на новой строке
print("Выведем полученные данные как есть")
for rate in rates:
    print(rate)

# создадим из полученных данных DataFrame
rates_frame = pd.DataFrame(rates)

# выведем пять первых строк (метод 'head' pandas)
print("\nВыведем пять первых строк")
rates_frame.head()

rates_frame['time']=pd.to_datetime(rates_frame['time'], unit='s')

# выведем данные
print("\nВыведем датафрейм с данными")
print(rates_frame)

rates_frame['time']=pd.to_datetime(rates_frame['time'], unit='s')

# выведем данные
print("\nВыведем датафрейм с данными")
print(rates_frame)

and the method doesn't output anything:

(1578614400, 1.11051, 1.11093, 1.11017, 1.11041, 2448, 1, 0)

Выведем пять первых строк

Выведем датафрейм с данными



Why the 'head()' method didn't work, but this maneuver:

Forum on trading, automated trading systems and strategy testing

New version of MetaTrader 5 build 2650: Background Loading of Charts and Improvements in MQL5 Profiler

Rashid Umarov, 2020.11.10 14:03

Try it

# выведем пять первых строк (метод 'head' pandas)
print("\nВыведем пять первых строк")
print( rates_frame.head())

Result

Выведем пять первых строк
         time     open     high      low    close  tick_volume  spread  real_volume
0  1578484800  1.11384  1.11386  1.11110  1.11200        12101       0            0
1  1578499200  1.11200  1.11308  1.11087  1.11180        13243       0            0
2  1578513600  1.11180  1.11180  1.11018  1.11041         5709       0            0
3  1578528000  1.11053  1.11194  1.11033  1.11174         4409       0            0
4  1578542400  1.11174  1.11190  1.11126  1.11183         2964       0            0



worked?

 
Vladimir Karputov:

Why didn't the 'head()' method work, but this manoeuvre:


worked?

Because the head() method(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.head.html) returns an object, not output to the log. To see the content, you need to explicitly send the object to print()

This anaconda for convenience outputs the objects as if print() had been called.

Reason: