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

 
Almaz:

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 filtering by group - group="EURUSD, "USDGBP", *RU*".
The order_check(), order_send() methods will return the initial request for execution in the request field.

Thank you.

 
Roman:

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

Just out of interest, what data sets do you want to transfer from MT?

The developers have already said several times that they will not transfer anything to MT. You have to use other features for that.

 
Vladimir Perervenko:

Just out of interest, what data sets do you want to transfer from MT?

The developers have already said several times that they will not transfer anything to MT. You have to use other features to do this.

Yes any, their own calculated arrays.
I build synthetics exclusively, and the ability to transfer arrays both ways is sorely lacking.
It's clear that you can use PyAPI, but it's again binding to dll.
And using PyAPI, then there is no need for this integration library at all.

 
Roman:

Yes any, your own calculated arrays.
I build synthetics exclusively, and the ability to transfer arrays in both directions is sorely lacking.
It's clear that you can use PyAPI, but it's again binding to a dll.
And using PyAPI, then there is no need for this integration library at all.

Don't think I want to lecture. You calculate synthetics based on quotes from the terminal. Dump the quotes into Python and do all the calculations in Python.

But you'll have to do gymnastics with reverse transfer of arrays. The easiest way is through the database.

Or use this. Somewhere there was a small thread with this project. Or this.

In any case, this integration will not solve all of the traders' various desires. But it solves two main and the most important problems: obtaining quick quotes and trade management.

All the rest on its own with its own infrastructure.

Good luck

khramkov/MQL5-JSON-API
khramkov/MQL5-JSON-API
  • khramkov
  • github.com
<a href="#metaquotes-mql5
 
Vladimir Perervenko:

Don't think I want to lecture. You calculate synthetics based on quotes from the terminal. Dump the quotes into Python and do all the calculations in Python.

But you'll have to do gymnastics with reverse transfer of arrays. The easiest way is through the database.

Or use this. Somewhere there was a small thread with this project. Or this.

In any case, this integration will not solve all of the traders' various desires. But it solves two basic and very important problems: quick quotes and trade management.

All the rest on its own with its own infrastructure.

Good luck

This is what I'm talking about, no matter what implementation, via dll or database, sockets or even text files, etc.
But again, this is an additional crutch not related to the library.
The point is that now we are actively developing integration mt5 library, so it is desirable to provide all the necessary features for users in it from the very beginning.

 
Dmitry Prokopyev:

Thanks, this example I saw, it works.

I'm a bit about something else.


positions_get - the list of TradePosition will be returned to me. In principle, you can throw in pandas and work fine.

But everything is not limited to one pandas, and if you need to get something like:

you have to somehow compose, pandas or for... somehow a lot of extra body movements.

It has become much more convenient with _asdict (), if the one who writes is not a MQL5 prog, but let's say a pythonist ... or a datasynetist, then list / dict is

The basic elements of python, many are building a data transfer on list / dict.

Tuples are used, too often and a lot, but only if you need to tightly control the types of data that move in it.

and also hang an error handler, if not used or assigned properly. Well, somewhere ... :) I could be wrong.

You could use a simple list comprehension when assigning your variable instead.

positions = [p._asdict() for p in mt5.positions_get()]
 
nicholi shen:

You could use a simple list comprehension when assigning your variable instead.

this does not change the essence ... this is an additional cycle

 

Gentlemen, the guys in the next thread are asking questions about the libs:

URL:https://www.mql5.com/en/forum/306742/page11#comment_15595095

Can you give us some support?


The symbols_get function should return a generator of SymbolInfo named tuples. A call to symbols_get without args should return all symbols available in the terminal. The function should take a callback which would be passed in a SymbolInfo namedtuple to be processed using the filter function. Here are some examples.

import MetaTrader5 as mt5
from contextlib import contextmanager
import re


@contextmanager
def metatrader_connection(**kw):
    try:
        if not mt5.initialize(**kw):
            print("Failed to initialize python MT5")
            raise Exception
        yield
    finally:
        mt5.shutdown()


def symbols_get(function=None):
    """
    No function passed in will result in all symbols returned to the caller.
    If a callable function is passed in then the function is passed a SymbolInfo tuple for filtering
    :param function: callback function to filter the symbols
    """
    all_symbols_in_terminal_info = map(
        mt5.symbol_info,
        ['EURUSD', 'USDJPY', 'GBPJPY', 'EURGBP'] # *example only* this would represent all symbols available to the terminal
    )
    if function is not None:
        return filter(function, all_symbols_in_terminal_info)
    return all_symbols_in_terminal_info


if __name__ == "__main__":
    with metatrader_connection():
        all_terminal_symbols = symbols_get()
        jpy_symbols = symbols_get(lambda s: "JPY" in s.name)
        jpy_symbols_using_re = symbols_get(lambda s: re.match(r'\w*JPY\w*', s.name))
        visible_symbols = symbols_get(lambda s: s.visible)
        selected_symbols = symbols_get(lambda s: s.select)


        def my_criteria(symbol_info):
            return 'USD' in symbol_info.name and symbol_info.session_deals > 0


        usd_symbols_with_session_deals = symbols_get(my_criteria)
 

Good evening, could you please advise me, I understand that this connector is not able to take information from connected indicators?

Example:

int  iMA(
   string              symbol,        // имя символа
   ENUM_TIMEFRAMES      period,        // период
   int                 ma_period,    // период усреднения
   int                 ma_shift,     // смещение индикатора по горизонтали
   ENUM_MA_METHOD       ma_method,    // тип сглаживания
   ENUM_APPLIED_PRICE   applied_price  // тип цены или handle
   );
 
9805244:

Good evening, could you please advise me, I understand that this connector is not able to take information from connected indicators?

Example:

What do you need it for? Can't you calculate it in Python? You surprise me.

Reason: