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

 
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...
 

Hi, interesting article. Thanks for that.


Was wondering. Why did you decide to implement the server in Python and the EA as the client in MT5?


Wouldnt it be more natural to have the server as an EA in MT5 providing data and executing traders and the client(s) in python, processing the data and making the trade decisions that are sent to the server?


Is there some obvious advantage to using the client as an EA and the server in python, that I am missing?



If i remember correctly, from past experience with ZeroMQ the server was as an EA in MT5 and the client in python.

 
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, I want to connect mt5 with live data using an api. Because in my country, there are no authorised broker or data vendor that support mt5. Can you pls help me. 
 

Thank you for complete description. 

i have a question:

is it possible for us to run a script of .ex5 type by a command in python environment?

i wanna run it through python, and the script save the results in an excel file, so can i use the excel data again in my website or android program.

Thanks a lot.

 

Hello - Can someone please help me!!!


I'm trying to execute this code in Python and keep getting an error:


Below is my code and it results in the error:


>>> # Copying data to dataframe

>>> d = pd.DataFrame()

>>> for i in sym:

... rates = mt.copy_rates_from_pos(i, mt.TIMEFRAME_M1, 0, 1000)

  File "<stdin>", line 2

    rates = mt.copy_rates_from_pos(i, mt.TIMEFRAME_M1, 0, 1000)

    ^

IndentationError: expected an indented block

>>> d[i] = [y.close for y in rates]

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "<stdin>", line 1, in <listcomp>

AttributeError: 'numpy.void' object has no attribute 'close'


# sbcapitalfx Heat Map - version 1.0



import MetaTrader5 as mt

import pandas as pd

from datetime import datetime

import matplotlib.pyplot as plt



# Initializing MT5 connection 



mt.initialize()



login = ************

password = ' ************ '

server = 'MetaQuotes-Demo'



mt.login(login,password,server)



# Create currency watchlist for which correlation matrix is to be plotted

sym = ['EURUSD','USDJPY','USDCHF','USDNZD']



# Copying data to dataframe

d = pd.DataFrame()

for i in sym:

        rates = mt.copy_rates_from_pos(i, mt.TIMEFRAME_M1, 0, 1000)

        d[i] = [y.close for y in rates]
 
Thnks bro. This article is greate. You help me a lot. :*
Reason: