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

 
Дмитрий Прокопьев:

Tried it, it all depends on the hardware it's running on.

One instance eats about 45-50Mb RAM + 2,5-4% CPU. (Yes, % CPU depends on CPU type, in my case Intel Xeon L5640 @ 2.27GHz).

The same, one instance of python.

If python runs with history, + 200-300Mb RAM. CPU is almost not used up.

Well, why, it depends on your ToR or idea.

Understood. Thanks for the information.

 
Developers, please make API function copy_buffer(). Receive indicator data via analog.
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
  • www.mql5.com
Отсчет элементов копируемых данных (индикаторный буфер с индексом buffer_num) от стартовой позиции ведется от настоящего к прошлому, то есть стартовая позиция, равная 0, означает текущий бар (значение индикатора для текущего бара). При копировании заранее неизвестного количества данных в качестве массива-приемника buffer[] желательно...
 
Denis Kirichenko:
Developers, please make API-function copy_buffer(). Get indicator data via analog.

Isn't there an indicator package in Python? Or is it some kind of special indicator. This one seems to work https://github.com/twopirllc/pandas-ta

twopirllc/pandas-ta
twopirllc/pandas-ta
  • twopirllc
  • github.com
Technical Analysis (TA) is an easy to use library that is built upon Python's Pandas library with more than 80 Indicators. These indicators are comminly used for financial time series datasets with columns or labels similar to: datetime, open, high, low, close, volume, et al. Many commonly used indicators are included, such as: Moving Average...
 
Vladimir Perervenko:

Isn't there an indicator package in Python? Or is it some kind of special indicator. This one seems to work https://github.com/twopirllc/pandas-ta

copy_buffer() implies getting an array of data for your calculations.
Andcopy_buffer() should work both ways.
What's missing is a bi-directional array transfer.

 
Roman:

The symbols_total and symbol_name functions are missing
To get a list of symbols like this:

In 5.0.29 added symbols_total(), symbols_get([group="EURUSD, "USDGBP", *RU*"]), requires the latest beta version of the Terminal to work.

Also, in all functions orders_get(),positions_get(), history_orders_get(), history_deals_get() added possibility of filtering by group - group="EURUSD, "USDGBP", *RU*".
The order_check(), order_send() methods will return the initial request for execution in the request field.

 
Roman:

Thecopy_buffer() implies getting an array of data for its own calculations.
Andcopy_buffer() should work in both directions.
What's missing is bidirectional passing of the array.

There are a lot of them on github, there are both b/gbin libs and paid packages...

Do not transfer the model of working with MQL5 to python. They are different and have different purposes.

 
Almaz:

In 5.0.29 added symbols_total(), symbols_get([group="EURUSD, "USDGBP", *RU*"]), requires the latest beta version of Terminal to work.

Also, in all functions orders_get(), positions_get(), history_orders_get(), history_deals_get() we added an option of filtering by group - group="EURUSD, "USDGBP", *RU*".
The order_check(), order_send() methods will return the initial request for execution in the request field.

And the list of _todict() is not yet able to return?

 
Дмитрий Прокопьев:

Can't they return a list of _todict() yet?

Yes, they can, see the example.

import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)

# установим подключение к терминалу MetaTrader 5
if not mt5.initialize():
    print("initialize() failed")
    mt5.shutdown()

# подключимся к торговому счету с указанием пароля и сервера
authorized=mt5.login(25115284, password="gqsdfgtdm",server="MetaQuotes-Demo")
if(authorized):
    # выведем данные о торговом счете
    print(mt5.account_info())
else:
    print("failed to connect to trade account 25115284 with password=gqz0lbdm")

account_info_dict=mt5.account_info(). _asdict()
for prop in account_info_dict:
    print("{}={}".format(prop,account_info_dict[prop]))

mt5.shutdown()

Result

AccountInfo(login=25115284, trade_mode=0, leverage=100, limit_orders=200, margin_so_mode=0, trade_allowed=True, trade_expert=True, margin_mode=2, currency_digits=2, fifo_close=False, balance=99511.4, credit=0.0, profit=9.04, equity=99520.44, margin=98.18, margin_free=99422.26, margin_level=101365.28824607862, margin_so_call=50.0, margin_so_so=30.0, margin_initial=0.0, margin_maintenance=0.0, assets=0.0, liabilities=0.0, commission_blocked=0.0, name='MetaQuotes Dev Demo', server='MetaQuotes-Demo', currency='USD', company='MetaQuotes Software Corp.')
login=25115284
trade_mode=0
leverage=100
limit_orders=200
margin_so_mode=0
trade_allowed=True
trade_expert=True
margin_mode=2
currency_digits=2
fifo_close=False
balance=99511.4
credit=0.0
profit=9.04
equity=99520.44
margin=98.18
margin_free=99422.26
margin_level=101365.28824607862
margin_so_call=50.0
margin_so_so=30.0
margin_initial=0.0
margin_maintenance=0.0
assets=0.0
liabilities=0.0
commission_blocked=0.0
name=MetaQuotes Dev Demo
server=MetaQuotes-Demo
currency=USD
company=MetaQuotes Software Corp.
 
Rashid Umarov:

They can, see example

Result

Thank you, I have seen this example, it works.

My question is a bit different.

    if mt5.initialize('c:\\Works\\MT5 - terminals\\RoboForex - MT5\\terminal64.exe',
                            login=500036189, server='RoboForex-MetaTrader 5', password='',  portable=True):
        positions = mt5.positions_get()
        print(positions)
        pList = []
        for elem in positions:
            pList.append(elem._asdict())

positions_get - it returns to me a list of tradePosition. In principle, it's OK, we can throw it in pandas and work fine.

(TradePosition(ticket=164661016, time=1585075408, time_msc=1585075408163, time_update=1585075408, time_update_msc=1585075408163, type=1, magic=0, identifier=164661016, reason=0, volume=0.01, price_open=120.306, sl=0.0, tp=0.0, price_current=120.279, swap=0.0, profit=0.24, symbol='EURJPY', comment='', external_id=''), 
 TradePosition(ticket=164661051, time=1585075426, time_msc=1585075426062, time_update=1585075426, time_update_msc=1585075426062, type=0, magic=0, identifier=164661051, reason=0, volume=0.01, price_open=1.07798, sl=0.0, tp=0.0, price_current=1.07806, swap=0.0, profit=0.08, symbol='EURUSD', comment='', external_id=''))

But it's not limited to pandas and if you want to get something like this:

[{'ticket': 164661016, 'time': 1585075408, 'time_msc': 1585075408163, 'time_update': 1585075408, 'time_update_msc': 1585075408163, 'type': 1, 'magic': 0, 'identifier': 164661016, 'reason': 0, 'volume': 0.01, 'price_open': 120.306, 'sl': 0.0, 'tp': 0.0, 'price_current': 120.328, 'swap': 0.0, 'profit': -0.2, 'symbol': 'EURJPY', 'comment': '', 'external_id': ''}, 
{'ticket': 164661051, 'time': 1585075426, 'time_msc': 1585075426062, 'time_update': 1585075426, 'time_update_msc': 1585075426062, 'type': 0, 'magic': 0, 'identifier': 164661051, 'reason': 0, 'volume': 0.01, 'price_open': 1.07798, 'sl': 0.0, 'tp': 0.0, 'price_current': 1.07881, 'swap': 0.0, 'profit': 0.83, 'symbol': 'EURUSD', 'comment': '', 'external_id': ''}]

we have to convert it somehow, pandas or for ... That's a lot of unnecessary gestures.

_asdict() has become much more convenient, if the developer is not an MQL5 programmer, but, say, a Pythonist ... or a data scientist, list/dict is

list/dict are the main elements of python. Many libs use list/dict to create data transfers.

Tuples are used a lot too, but only if you want to strictly control types of data in it.

and have an error handler for incorrect use or assignment. Somewhere ... :) I could be wrong.

 
Дмитрий Прокопьев:

There are plenty of them on github, there are both b/bp libs and paid packages...

Do not transfer the model of working with MQL5 to python. They are different and have different objectives.

What do you mean by that? Copying an array from mql5 to py and back?
You should at least carefully read what we're talking about.
You don't have to think only for yourself. If you don't need it, others do.

Reason: