
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Forum on trading, automated trading systems and testing trading strategies
MetaTrader 5 Python User Group - how to use Python in Metatrader
Rashid Umarov , 2020.03.28 09:11
Descriptions of 3 new functions are added to the help:
In addition, changes were made to the descriptions of many functions, as they were finalized. Almost all the examples were rewritten taking into account the new functionality. However, examples for the following functions on the site have not yet been updated, they will be a little later:
How important is it to call mt5.shutdown()?
I would imagine that it is rather important otherwise it wouldn't be part of the common practice. That being said then why is it never presented in a try/finally block? If the user code raises an exception then mt5.shutdown will not get called. Another issue is not having any custom MT5 python exceptions. I'd like to propose is adding a context manager to the official MT5 library as well as a unique exception to catch in a try block. Example:
This code sets up a MT5 connection context manager and initializes the MT5 connect when entered and shuts it down when exited, ensuring that the mt5.shutdown() function is always called.
Produces the following result:
Here is the context manager code:
This code sets up a MT5 connection context manager and initializes the MT5 connect when entered and shuts it down when exited, ensuring that the mt5.shutdown() function is always called.
Produces the following result:
Here is the context manager code:
A good example, I would suggest devops that it be included in the documentation.
How important is it to call mt5.shutdown()?
MetaTrader5 - in the context of implementation limited resource.
Terminals may be running on the host several. To specify which is running - the path-variable is used.
To be precise, the first, unnamed parameter.
If you need to reconnect - change account or terminal, needed to execute mt5.shutdown()
Here is the context manager code:
MetaTrader5 - Exception don`t processed in the classic python concept, nessesary to use last_error()
https://www.mql5.com/en/docs/integration/python_metatrader5/mt5lasterror_py
MetaTrader5 - in the context of implementation limited resource.
Terminals may be running on the host several. To specify which is running - the path-variable is used.
To be precise, the first, unnamed parameter.
If you need to reconnect - change account or terminal, needed to execute mt5.shutdown()
So if I understand you correctly, it is not possible to have more than one concurrent terminal connection?
I've discovered an issue with the handling of **kwargs in some of the functions that can be called with or without arguments. Please reference these pytest unit tests.
Expected behavior:
All functions should be able to except **kwargs and return the equivalent of a call without args:
This is the undesirable workaround
pytest
Hi,
I'm newbie in MetaTrader5. I decided to start programing in this area and I'm looking for a way to integrate Python3 to it so I can extract the historical data as the first HelloWorld program.
I'm also using Debian 10 Buster. I've prepared all the packages according to the instruction here, but unfortunately I can't import MetaTrader5 and I confront with this error:
Error:Does anybody here know how to come over this error?
I also installed the package successfully:
I'd installed MetaTrader5 through pip3, but this error causes me to uninstall it and reinstall with the MetaTrader5 wheel file itself but same error. I've check MetaTrader5 .whl file in pypi.org and found out it has been named win_amd64 or win32 in filename. So this made me to rename the file according to my system architecture but after successfully installation (as before) again same error is being shown. Does this package has been developed only for Windows? If so, is there any other way to deploy this package in GNU/Linux.
Thank youDoes this package has been developed only for Windows?
Yes. It requires a running MT5 terminal which only runs on windows.
So if I understand you correctly, it is not possible to have more than one concurrent terminal connection?
Yes, 1 Terminal - 1 connection.
In my task, needed using over 1 terminals connections and in code i using threading.RLock() as semafor :)
I didn't come up with anything better ...