Discussion of article "MetaTrader 5 and Python integration: receiving and sending data" - page 7

 
yogibass:

@Maxim Dmitrievsky

I just wanted to say thank you for making this available. I always wanted to be able to code my indicators in Python and since you began this thread I've been able to access realtime futures data and use it to develop and run my indicators. I use my Python to plot and analyze the live feed and I place trades through the MT5 platform - it works great. Please keep up the good work and I truly hope Python will be full embraced my the MT community.

Thank you and best regards!

Hi do you know why the code does not compile I get a none value. 

rates = MT5CopyRatesFromPos(i, MT5_TIMEFRAME_M1, 0, 1000)
     d[i] = [y.close for y in rates
 
Dannyhill.0:
Hi do you know why the code does not compile I get a none value. 

Several reasons...

  • missing bracket on list comp
  • using deprecated functions from the MetaTrader5 package
  • i is not defined
  • polluted namespace by using from x import * (possible collisions?)
  • close is not an attribute of ndarray
  • don't iter an ndarray to pull out a series
  • did terminal initialize???

It should look like this

import MetaTrader5 as mt

try:
    if not mt.initialize():
        raise Exception('Failed to initialize')
    close_price_map = {}
    for symbol in ['EURUSD', 'USDJPY']:
        rates = mt.copy_rates_from_pos(symbol, mt.TIMEFRAME_M1, 0, 5)
        close_price_map[symbol] = rates['close']
        print(symbol)
        print(close_price_map[symbol])
except Exception as e:
    print(e)
finally:
    mt.shutdown()
    
# EURUSD
# [1.12594 1.12598 1.12584 1.12564 1.12543]
# USDJPY
# [107.5   107.494 107.509 107.525 107.527]

See docs  https://www.mql5.com/en/docs/integration/python_metatrader5

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
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...
 
I am trying to use this for MT4 and it says "SocketClose function not defined" ...  do MQL5 functions also work for MQL4 ? I don't see anything on the documentation itself. is this supposed to run in MQL4? can you help me figure it out please? 
 

found really great github

python metatrader api

[Deleted]  
sanazgolriz:
I am trying to use this for MT4 and it says "SocketClose function not defined" ...  do MQL5 functions also work for MQL4 ? I don't see anything on the documentation itself. is this supposed to run in MQL4? can you help me figure it out please? 

hi i think socket functions don't work in metatrader4

you can use it in mt5, also you can use new MetaTrader5 package (see documentation)

for mt4 you can try zeromq

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
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...
 

Hello, Maxim!

In another thread you helped me with the code modification, for which I would like to thank you once again. I searched the MQL5 website and found your article about receiving and sending data using Python programming language. However, I have an amateurish, perhaps even childish question: is a network socket a physical device or a software product in the form of a set of several files or a single file, for example, the same csv?

Regards, Vladimir.

[Deleted]  
MrBrooklin:

Hello, Maxim!

In another thread you helped me with the code modification, for which I would like to thank you once again. I searched the MQL5 website and found your article about receiving and sending data using Python programming language. However, I have an amateurish, perhaps even childish question: is a network socket a physical device or a software product in the form of a set of several files or a single file, for example, the same csv?

Regards, Vladimir.

It is a software interface through which programmes (processes) can exchange data. For example, when you go to a website, you access the open socket of the website server. The same thing can be done within a single PC. Roughly speaking, a socket is a built-in feature of the operating system.

 
Maxim Dmitrievsky:

This is a software interface through which programmes (processes) can communicate. For example, when you go to a website, you access the open socket of the site's server. The same thing can be done within a single PC. Roughly speaking, a socket is a built-in feature of the operating system.

Thanks, Maxim!

Did I understand the essence of your article correctly? I'll put it in my own words, and you can correct me if I misunderstood something.

  1. Let's assume that there are some third-party programmes on my computer, which are created in a programming language fundamentally different from the MQL programming language, but I need these programmes very much for my work.
  2. The programme code written in the Python programming language allows me to link the interaction of these third-party programs, for example, with the same MT5 terminal.
  3. Third-party programs from another computer can remotely control the work of the same MT5 terminal on my computer.

Is this correct? I will explain later why I ask such questions.

Regards, Vladimir.

[Deleted]  
MrBrooklin:

Thank you, Maxim!

Did I understand the essence of your article correctly? I'll put it in my own words, and you can correct me if I misunderstood something.

  1. Let's assume that there are some third-party programmes on my computer, which are created in a programming language fundamentally different from the MQL programming language, but I need these programmes very much for my work.
  2. The programme code written in the Python programming language allows me to link the interaction of these third-party programs, for example, with the same MT5 terminal.
  3. Third-party programmes can remotely control the work of the same MT5 terminal.

Is this correct? I will explain later why I ask such questions.

Regards, Vladimir.

It depends on the task, it's hard to say. Rather, it is better to "link" them directly, if you have access to the source code. Otherwise, if there is a programme but there is no source code and you need it badly, you can do something through Python scripts, yes, where it is possible.
 
Maxim Dmitrievsky:
It depends on the task, it's hard to say. Rather, it is better to "link" them directly, if you have access to the source code. Otherwise, if there is a programme but there is no source code and you need it badly, you can do something through Python scripts, yes, where it is possible.

Now we come to the task itself. This is not a technical task, but a very brief statement of its essence.

You need to periodically (for example, once an hour, once a day, once a week) take various data from several (no more than 10) sites and perform complex intermediate calculations in a third-party programme (not MQL). The result of these calculations will be three signals for MT5 terminal control: a signal to open a buy order, a signal to open a sell order or a signal to close an order.

Is this possible? I need to know this in order to be able to competently compose a technical task for freelancing.

Regards, Vladimir.

Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Свойства пользовательских индикаторов
Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Свойства пользовательских индикаторов
  • www.mql5.com
Количество индикаторных буферов, которые можно использовать в пользовательском индикаторе, не ограничено. Но каждому массиву, который назначается в качестве индикаторного буфера с помощью функции SetIndexBuffer(), должен быть указан тип данных, которые он будет хранить. Это может быть одно из значений перечисления ENUM_INDEXBUFFER_TYPE...