import MetaTrader5 as mt5
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# establish connection to MetaTrader 5 terminal
mt5.initialize(login=<this has my login number>, server="XM.COM-MT5",password="<this has my pass>")
# get account currency
account_currency=mt5.account_info().currency
print("Account сurrency:",account_currency)
# prepare the request structure
symbol="USDJPY"
symbol_info = mt5.symbol_info(symbol)
if symbol_info is None:
print(symbol, "not found, can not call order_check()")
mt5.shutdown()
quit()
# if the symbol is unavailable in MarketWatch, add it
if not symbol_info.visible:
print(symbol, "is not visible, trying to switch on")
if not mt5.symbol_select(symbol,True):
print("symbol_select({}}) failed, exit",symbol)
mt5.shutdown()
quit()
# prepare the request
point=mt5.symbol_info(symbol).point
request = {
"action": mt5.TRADE_ACTION_DEAL,
"symbol": symbol,
"volume": 1.0,
"type": mt5.ORDER_TYPE_BUY,
"price": mt5.symbol_info_tick(symbol).ask,
"sl": mt5.symbol_info_tick(symbol).ask-100*point,
"tp": mt5.symbol_info_tick(symbol).ask+100*point,
"deviation": 10,
"magic": 234000,
"comment": "python script",
"type_time": mt5.ORDER_TIME_GTC,
# "type_filling": mt5.ORDER_FILLING_RETURN,
}
# perform the check and display the result 'as is'
result = mt5.order_check(request)
print(result);
# request the result as a dictionary and display it element by element
result_dict=result._asdict()
for field in result_dict.keys():
print(" {}={}".format(field,result_dict[field]))
# ifthis is a trading request structure, display it element by element as well
if field=="request":
traderequest_dict=result_dict[field]._asdict()
for tradereq_filed in traderequest_dict:
print(" traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed]))
# shut down connection to the MetaTrader 5 terminal
mt5.shutdown()
I find it very strange and makes me second guess the documentation or I've found a bug. Though to be honest I'm hoping I made a beginners mistake. This issue occurs for all combinations of type_filling,type_time,type and action. I know this as each represents an integer and by abusing loops I've tested all possible combinations, none worked.
# request the result as a dictionary and display it element by element # request the result as a dictionary and display it element by element 2. order_send done, OrderSendResult(retcode=10009, deal=535084512, order=557416535, volume=0.1, price=108.023, ...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello,
I know this topic has been addressed before but I cannot find a scenario where it also happens using documentation available examples.
Using a freshly installed MT5=5 build 2489, the most recent library for python MT5=5.0.33 and the example from: https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py
The result is:
I find it very strange and makes me second guess the documentation or I've found a bug. Though to be honest I'm hoping I made a beginners mistake. This issue occurs for all combinations of type_filling,type_time,type and action. I know this as each represents an integer and by abusing loops I've tested all possible combinations, none worked.
Some additional information:
Please help!
Kind regards,
Viktor