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
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
it should be written in the main thread ... i copied
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 ...
Wrong. There can be many connections to one terminal (rather to a broker / account). Or did I misunderstand?
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
...
However, examples for the following functions on the site have not yet been updated, they will be a little later:
The examples for the following functions were updated:
pip install MetaTrader5 does not work even after an upgrade to python 3.8
It does work. I'm using 3.82 and python and additional packages are running fine.
I'm not sure if you are into developing, if so please ignore my lack of knowledge about you. If not then take a look at https://www.mql5.com/en/docs/integration/python_metatrader5 and https://datatofish.com/upgrade-pip/
Notice that you must be using CMD as Administrator. You have to find the CMD app and right click >Run as administrator
Pip is an absolute must prior to continuing with any of the steps. You don't want to build the whl with outdated Pip
All these steps must be done every time you update Python.
I would recommend using PyCharm as your Python IDE outside of MT5 purposes
Nothing will install if you don't run CMD as Administrator.
1. Install the latest developer packages into the MT5 MetaEditor under options.
2. Ensure that the Python directory is the actual 3.8 path and not the MT5 python path. (you may have to copy and paste the path)
3. Did you ensure all boxes were checked during the 3.8 installation?
4. You will need quite a few gigabytes of storage in your hard drive for all the developer tools
The below test script is modified from the python_metatrader5 link above. This will run if you follow all the developer installation steps
# Copyright 2019, MetaQuotes Software Corp.
# https://www.mql5.com
from datetime import datetime
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
import MetaTrader5 as mt5
# you code here
# connect to MetaTrader 5
if not mt5.initialize():
print("initialize() failed")
mt5.shutdown()
# request connection status and parameters
print(mt5.terminal_info())
# get data on MetaTrader 5 version
print(mt5.version())
# shut down connection to MetaTrader 5
mt5.shutdown()
Is it possible to send a request to set a stop loss on an existing order?
I have a code that works in my python ea, which can set and open trades. however I need to know the syntax for mt5.Buy(), mt5.Sell(), and what values they accept. for example how can i set a stop loss and take profit value when sending a buy? or a sell?
Buy(), Sell(), Close() just wrappers on oreder_send() in module __init__.py file:
Forum on trading, automated trading systems and testing trading strategies
MetaTrader 5 Python User Group - how to use Python in Metatrader
MetaQuotes , 2020.03.31 19:38
Version 5.0.30 releasedWrong. There can be many connections to one terminal (rather to a broker / account). Or did I misunderstand?
MT5 can be used in portable mode
https://www.metatrader5.com/en/terminal/help/start_advanced/start
2 MT5 instance - 2 broker/accounts, but 1 MetaTrader5 library, 1 connection at a time ...
Bug report - package version 5.0.30
1. The functions [history_deals_get, history_deals_total, history_orders_get, history_orders_total, ...all of the copy_funcs] all have a fundamental flaw, and that is the parameter "from". From is a reserved keyword in python and cannot be used as a parameter name. This prevents the creation of pythonic adapter functions due to the naming conflict. The following will not even compile:
The parameter names should be changed to something that doesn't conflict with python and is more descriptive. Example:
2. The mt5.RES_* constants are assigned as tuples instead of <int>. Someone forgot to remove the commas after the expressions in the MetaTrader5.__init__.py module. This is how to fix the bug:
Test
3. last_error() should return a tuple instead of a list in order to remain consistent with the API.
Test
4. The documentation for version() needs to change the type for the "build-number" from type "string" to "int"
5. history_deals_get (and perhaps other functions) are inconsistent with their return type. Some functions return None when there is no data to return and other functions return an empty tuple. These functions all need to be consistent. They should all return the same object in the case of no data -- instead of some returning None and some returning an empty tuple.
Test
Please see all pytest unittests attached.
version 5.0.31 released
Thanks for the rapid response! All tests passed with the exception of the one that checks for different return types. Any idea about change the keyword "from" in the C-functions?