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

 
jalal ahmadi:
hi maxim

i'm trying to install EA and Python client by your instruction but i'm getting a 4014 error . like andres kull comment ,SocketCreate ends with error when i execute it on strategy tester.

can you guide me to fix this problem? and this problem has been fixed by developers from  2019.05.04 (the Date of this post ) ? 

i'll really appreciate you . 



Hi, sockets still not work in tester by default (limited by meqtaquotes in sense of security). Maybe later they will add such a possibility.

 
Oi, there is some place website to host this pyton application on internet for free? can you indicate some? I tested your script and  it works nice!
 
Hi!
I was wondering to know how can i keep getting live data from mql5 and append it to my list or my dataframe
At the moment a touple comes out of metatrader commands and converts to a dataframe, but what if we want to keep getting the data and at to the dataframe
Tnx maxim, you have been a great help
 

<Deleted>

This is an English language forum. Please only post in English.

 

Hi,

Could someone write an example code how to open a 'Buy' or 'Sell' position from Python and also how to close that postition?

Or maybe is that not possible?

Many thanks!

 

how to connect a metatrader5 indicator to python.


Thanks

 
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

Reason: