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

 
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:

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

Here is the new feature set:

Example:

Are there any plans to add functions to run tests/optimisation and get their results?

 

Python programs will run in the terminal only as scripts and are not involved in any way and will not participate in the trading strategy tester.

This is a solution for those who are doing deep research in Python and want:

  1. access to market information from MT5
  2. access to deal history and open positions
  3. trade

Strategy Tester for MQL5 programs only.

Later we will expand the library and give the possibility to access built-in and custom indicators from the terminal.

 

Anyway, the situation at the moment is as follows: I have installed windows 7 on 3 machines.

Bottom line:333

Put it on windows server 2012 - started up half way through. And even on python 3.8.1

 
Dmitri Custurov:

Anyway, the situation at the moment is as follows: I have installed windows 7 on 3 machines.

Bottom line:

Put it on windows server 2012 - started half way through. And even on python 3.8.1.

Ten is not at hand, but I think there and start.

 
Just in case, installed visual studio and the libs with it on seven. It won't start. Gone to smoke sockets. Very cool stuff. I already started it on java.
 

On 10, it's back to normal.

from MetaTrader5 import *
#import MetaTrader5 as mt5
import time

initialize()
wait()

# mt5.initialize()
# mt5.wait()

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

symbol_select(symbol)

Acc = account_info()
Term = terminal_info()
vr = version()

Acc.server
Acc.login
Term.build

'MetaQuotes-Demo'
18192632
2319

1.The previous problem remains. During initialisation the terminal starts with an arbitrary broker and account. Wasn't it promised to fix it?

2) Orders are executed. I have not checked it further.

I don't understand why the "metatrader5 5.0.18 pypi_0 pypi" module is imported only as "MetaTrader5".

We will try.

Good luck

 
Renat Fatkhullin:

Python programs will run in the terminal only as scripts and are not involved in any way and will not participate in the trading strategy tester.

This is a solution for those who are doing deep research in Python and want:

  1. access to market information from MT5
  2. access to deal history and open positions
  3. trade

Strategy Tester for MQL5 programs only.

Later we will expand the library to allow access to built-in and custom indicators from the terminal.

Launching Python scripts themselves for optimization is not so interesting.

The possibility to automate the optimization of mql5-advisors through Python scripts is interesting. Something like that described in the article"Optimization Management".

Управление оптимизацией (Часть 2): Создание ключевых объектов и логики приложения
Управление оптимизацией (Часть 2): Создание ключевых объектов и логики приложения
  • www.mql5.com
В текущей статье мы продолжаем процесс создания удобного графического интерфейса для управления оптимизациями в нескольких терминалах одновременно. В прошлой статье мы рассмотрели способ, позволяющий нам запустить терминал из консоли, а также структуру конфигурационного файла. В данной статье мы рассмотрим создание обертки для терминала на...
 
Renat Fatkhullin:

Python programs will run in the terminal only as scripts and are not involved in any way and will not participate in the trading strategy tester.

This is a solution for those who are doing deep research in Python and want:

  1. access to market information from MT5
  2. access to deal history and open positions
  3. trade

Strategy Tester for MQL5 programs only.

Later we will expand the library and give the possibility to access built-in and custom indicators from the terminal.

I understand correctly that for transferring calculated values and arrays from Py to mt5, there will be no such functions ?
And it remains to use - network solutions, or to saw the module on transfer through memory?

As I noticed, now the structure of objects has changed
it used to be

Time  = [x.time for x in ticks]

now become

Time  = [x[0] for x in ticks]

Could you describe, structures for copy_ticks and copy_rates ?
Which x[] indexes, correspond to what.

Or is it the same sequence? as in

struct MqlTick 
{ 
   datetime     time;          // Время последнего обновления цен 
   double       bid;           // Текущая цена Bid 
   double       ask;           // Текущая цена Ask 
   double       last;          // Текущая цена последней сделки (Last) 
   ulong        volume;        // Объем для текущей цены Last 
   long         time_msc;      // Время последнего обновления цен в миллисекундах 
   uint         flags;         // Флаги тиков 
   double       volume_real;   // Объем для текущей цены Last c повышенной точностью 
};
 

Roman:

As I noticed, the structure of the objects has now changed

used to be

now it is.

Could you describe, structures for copy_ticks and copy_rates ?
Which x[] indexes, correspond to what.

Or is it the same sequence? as in

It is now a numpy array, not a tuple as it was before (i.e. effective direct mapping to memory of the data itself), its format can be seen simply by displaying it:

>>> ticks1 = mt5.copy_ticks_from("EURAUD", datetime(2020,2,13,13), 20, mt5.COPY_TICKS_ALL)
>>> ticks1
array([(1581591600, 1.61633, 1.61657, 0., 0, 1581591600170, 134, 0.),
       (1581591600, 1.61633, 1.61658, 0., 0, 1581591600362,   4, 0.),
       (1581591600, 1.61633, 1.61659, 0., 0, 1581591600569,   4, 0.),
       (1581591600, 1.61636, 1.61659, 0., 0, 1581591600759, 130, 0.),
       (1581591601, 1.61633, 1.61659, 0., 0, 1581591601964, 130, 0.),
       (1581591602, 1.61634, 1.61658, 0., 0, 1581591602261, 134, 0.),
       (1581591606, 1.61635, 1.61658, 0., 0, 1581591606276, 130, 0.),
       (1581591607, 1.61637, 1.61661, 0., 0, 1581591607795, 134, 0.),
       (1581591607, 1.61643, 1.61664, 0., 0, 1581591607880, 134, 0.),
       (1581591608, 1.61642, 1.61665, 0., 0, 1581591608184, 134, 0.),
       (1581591608, 1.61643, 1.61667, 0., 0, 1581591608791, 134, 0.),
       (1581591608, 1.61642, 1.61667, 0., 0, 1581591608992, 130, 0.),
       (1581591609, 1.61642, 1.61665, 0., 0, 1581591609192,   4, 0.),
       (1581591609, 1.61642, 1.61667, 0., 0, 1581591609584,   4, 0.),
       (1581591611, 1.61642, 1.61666, 0., 0, 1581591611397,   4, 0.),
       (1581591611, 1.61642, 1.61667, 0., 0, 1581591611694,   4, 0.),
       (1581591612, 1.61643, 1.61667, 0., 0, 1581591612091, 130, 0.),
       (1581591612, 1.61643, 1.61665, 0., 0, 1581591612881,   4, 0.),
       (1581591613, 1.61644, 1.61665, 0., 0, 1581591613300, 130, 0.),
       (1581591613, 1.61648, 1.6167 , 0., 0, 1581591613498, 134, 0.)],
      dtype=[('time', '<i8'), ('bid', '<f8'), ('ask', '<f8'), ('last', '<f8'), ('volume', '<u8'), ('time_msc', '<i8'), ('flags', '<u4'), ('volume_real', '<f8')])

you can now immediately de get them as separate vectors(multiply, subtract) and draw graphs:

rates2 = mt5.copy_rates_from_pos("EURGBP", mt5.TIMEFRAME_M1, 0, 1000)

import matplotlib.pyplot as plt

plt.plot(rates2['time'], rates2['low'], 'g-')
plt.plot(rates2['time'], rates2['high'], 'r-')

plt.show()
 
Almaz:

It is now a numpy array, not a tuple as it was before (i.e. effective direct mapping to memory of the data itself), its format can be seen simply by displaying it:

you can now get them immediately de as separate vectors(multiply, subtract) and draw graphs:

Thank you Almaz, now I understand.

There is still an open question:
Do I understand correctly that for transferring calculated values and arrays from Py to mt5, there will be no such functions ?
And it remains to use - network solutions, or to saw the module on transfer through memory?

Reason: