MetaTrader 5 Python User Group - how to use Python in Metatrader - page 88

 

   File
   "C: \ Users \ MyName \ .spyder-py3 \ MyCode.py"
   , line 3
   ,
   in
   <module>
   import MetaTrader5
   as
   mt5
   File
   "C: \ Users \ Myname \ anaconda3 \ lib \ site-packages \ MetaTrader5 \ __ init__.py"
   , line
   257
   ,
   in
   <module>
   from
   ._core import *
ModuleNotFoundError:
   No module named
      'MetaTrader5._core'

does anyone know how to fix? wake up this morning and this.

did nothing new.

Nvm. I downgrade python to version 3.8.11 and its ok now.
 

I would like the developers to announce new versions of MetaTrader5(Py) with information about new changes and version requirements for major related packages (e.g. numpy, pandas and others if needed). Very annoying with incomprehensible bugs when upgrading, e.g. to version 37. Rolled back to version 35 and still using it.

Maybe there's a description posted somewhere on the forum?

 

Perhaps an amateurish question. I am not a programmer.
There are some inconsistencies in the tick data in MT5. Namely, trades hanging in the air and being
out of place. One person here on the forum, in one of the articles described the solution of this problem.
But there it was solved by a specific task.
That is, tick data from the server get to the terminal in a normal form but their processing in MT is distorted.
Is it possible to make some kind of retranslator of already corrected data using python? The last ones are needed in the indicator.

Or in another way. Can I use python to write the code of an indicator that uses the tick data?
Maybe python isn't designed to solve such problems...

Vasiliy Sokolov
Vasiliy Sokolov
  • 2019.09.05
  • www.mql5.com
Профиль трейдера
 
hello,

as far as I know  python order_send() method is using MT5 equivalent of OrderSend()

I am building an async adapter for the mt5 library and I would like my python order_send to use the  MT5 - OrderSendAsync()  instead of OrderSend ()

Is this possible with the current functionality available ?
 
Dmitri Custurov #:
Dear developers, could you please comment on my previous question? The history_deals_get(ticket=TICKET) function does not work. Response is always (-2, 'Terminal: Invalid params'). The same function but with a different parameter history_deals_get(position=POSITION) works, but I need to find a trade by ticket order.
Dmitri Custurov #:
I have progressed with my question. By requesting the history of closed positions mt5.history_deals_get, I can find the ticket of a closed order and its execution price among the orders. This works if I specify a time range in the parameters. I also call the same function passing the ticket of an order to it - mt5. history_deals_get(ticket=TICKET) - but the response (-2, 'Terminal: Invalid params'). Does the function with this parameter even work?

stackoverflow: https://stackoverflow.com/questions/72081988/how-do-i-get-the-result-of-a-trade-in-mt5-with-python-using-the-ticket-number


I have the same issue here, even though the function "history_deals_get" accepts the argument "ticket=", it keeps return error (-2, 'Terminal: Invalid params'). I guess this function is buggy with argument "ticket", so the developer team denies it.


history_deals_get([date_from, date_to, [group="GROUP"]],[position=POSITION],[ticket=TICKET])


Hope developer team can see the discussion. Still no workaround after 1 year.


Thx


 

Hello, I've installed Python 3.11.0 and the latest version of Pycharm. Now I'm trying to install MetaTrader5 package but it gives me this error.

ERROR: Could not find a version that satisfies the requirement MetaTrader5 (from versions: none)
ERROR: No matching distribution found for MetaTrader5

Not sure what I'm doing wrong. Please advice. Thanks.

Files:
image.png  36 kb
 
Eric Pedron #:

Hello, I've installed Python 3.11.0 and the latest version of Pycharm. Now I'm trying to install MetaTrader5 package but it gives me this error.

ERROR: Could not find a version that satisfies the requirement MetaTrader5 (from versions: none)
ERROR: No matching distribution found for MetaTrader5

Not sure what I'm doing wrong. Please advice. Thanks.


Hi Eric, hope everything's fine.

I encountered and solved the same error last week. I hope this will help in your case, too:


Latest major release is Python 3.11, but MetaTrader5 package on PyPi (https://pypi.org/project/MetaTrader5/) allows only following Python versions as of today:

  • Programming Language
    • Python :: 3
    • Python :: 3.10
    • Python :: 3.6
    • Python :: 3.7
    • Python :: 3.8
    • Python :: 3.9


If you downgrade Python version to 3.10 (Python 3.10.8 is the latest  3.10 version today.), I think it will solve your issue.

MetaTrader5
MetaTrader5
  • 2022.11.04
  • pypi.org
API Connector to MetaTrader 5 Terminal
 

Hello! I'm building my first robot in python for MT5.


I have a problem. Whenever I send an ORDER_TYPE_BUY_LIMIT or ORDER_TYPE_SELL_LIMIT, the platform already executes the order at market value.


What can I do to make the order wait in the order book?


Here's the code:

import time import MetaTrader5 as mt5 # exibimos dados sobre o pacote MetaTrader5 print("MetaTrader5 package author: ", mt5.__author__) print("MetaTrader5 package version: ", mt5.__version__) # estabelecemos a conexão ao MetaTrader 5 if not mt5.initialize(): print("initialize() failed, error code =", mt5.last_error()) quit() time.sleep(5) # preparamos a estrutura de solicitação para compra symbol = "WDOJ23" symbol_info = mt5.symbol_info(symbol) if symbol_info is None: print(symbol, "not found, can not call order_check()") mt5.shutdown() quit() # se o símbolo não estiver disponível no MarketWatch, adicionamo-lo 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() lot = 1.0 point = mt5.symbol_info(symbol).point price = 5251.000 request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_SELL_LIMIT, "price": price, "magic": 234000, "comment": "python script open", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_FOK, } time.sleep(3) # enviamos a solicitação de negociação result = mt5.order_send(request) # verificamos o resultado da execução print("1. order_send(): by {} {} lots at {} ".format(symbol, lot, price)) if result.retcode != mt5.TRADE_RETCODE_DONE: print("2. order_send failed, retcode={}".format(result.retcode)) # solicitamos o resultado na forma de dicionário e exibimos elemento por elemento result_dict = result._asdict() for field in result_dict.keys(): print(" {}={}".format(field, result_dict[field])) # se esta for uma estrutura de uma solicitação de negociação, também a exibiremos elemento a elemento if field == "request": traderequest_dict = result_dict[field]._asdict() for tradereq_filed in traderequest_dict: print(" traderequest: {}={}".format(tradereq_filed, traderequest_dict[tradereq_filed]))

 
@Allysson Christopher #: Hello! I'm building my first robot in python for MT5.

As per Forum rules and recommendations, please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post.

 
Hello, how can I connect and open trade positions with the Deriv broker API using python ? I have read their documentation and it's not beginner friendly. 
Reason: