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

 
Rashid Umarov:

Check whether your account type is netting or hedging. For netting, the ticket of an already existing position will not change, and there is no point in looking for a position after the share by order number.

Yep, all clear, looked at yes, in case of opening a position on a netting ticket, corresponds to the position being opened. The point is clear.

 
Almaz:
error code 1, this is success mt5.RES_S_OK, the next build will write [1, 'Success']. Codes with negative values are errors mt5.RES_E_xxx.

Yes, thank you - the point is clear as to why the blank line was there.

 
Hi, is there any update on post #517 about getting an update from the terminal about newbar?
 
fbrand:
Hi, is there any update on post #517 about getting an update from the terminal about newbar?

So far I've had to cycle with the time check:

if mt5.symbol_info_tick(symbol).time % (60 * timefr) == 0:
...

Not very convenient. But as a temporary option it's fine.

 
Vladimir Perervenko:

So far I've had to cycle with the time check:

Not very convenient. But as a temporary option it's fine.

Not planned. Check for new bars on a timer or in a loop.

 
Rashid Umarov :

Not planned. Check for new bars on a timer or in a loop.


If you use according to Vladimir, we will not get the exact volume then, but only the volume of that tick at polling?


And if you then use the new bars in EA to call the Python script, and the script points to more than one symbol, are all new bars for all symbols in the terminal executed at the same time, or should I create a Python script and advisor for each symbol?


Thanks

ps: sorry had to go to english as the translator messed up the words
Обработчик события "новый бар"
Обработчик события "новый бар"
  • www.mql5.com
Для создателей индикаторов и экспертов всегда был актуален вопрос написания экономичного кода с точки зрения времени выполнения. Можно подойти к решению этой задачи с разных сторон. Из этой обширной темы в данной статье будет затронут, казалось бы уже решенный вопрос: проверка появления нового бара. Это достаточно популярный способ ограничения...
 

Usinghistory_orders_get().

In the documentation, explicitly copy-paste :)(https://www.mql5.com/ru/docs/integration/python_metatrader5/mt5historyordersget_py)

And there's an oddity in the usage:

    from_date = datetime(2020,1,1)
    to_date = datetime.now()
    if mt5.initialize(acc['path'], login=login, server=acc['server'], password=acc['pass']):
        orders = mt5.history_orders_get(from_date, to_date)    
        if len(orders) > 0:
            orders_frame = pd.DataFrame(orders)
            print(orders_frame.head())

Result:

 python.exe .\history-deal-mt-1.py
         0           1              2           3              4  5  6  7  8  9      10       11  12  13    14   15       16      17      18       19   20      21             22 23
0  4308935  1583603265  1583603265527  1583603267  1583603267535  0  0  0  0  4  234000  4308935   0   3  0.01  0.0     0.00     0.0     0.0  9128.00  0.0  BTCUSD  python script
1  4308936  1583603511  1583603511561  1583603511  1583603511561  0  1  0  1  4  234000  4308935   0   5  0.01  0.0  9128.01     0.0     0.0  9128.01  0.0  BTCUSD  [tp 9128.010]
2  4308937  1583603550  1583603550455  1583603552  1583603552460  0  1  0  0  4       0  4308937   0   0  0.01  0.0     0.00     0.0     0.0  9127.50  0.0  BTCUSD
3  4308938  1583603969  1583603969250  1583603971  1583603971253  0  0  0  0  4  234000  4308938   0   3  0.01  0.0     0.00  9135.5  9142.5  9139.00  0.0  BTCUSD  python script
4  4308939  1583603974  1583603974183  1583603974  1583603974188  0  1  0  1  4  234000  4308938   0   4  0.01  0.0  9135.50     0.0     0.0  9135.50  0.0  BTCUSD  [sl 9135.500]

Total, data is displayed, but where, what - one can only guess.

Folks, pls - add something like _fields or as_dict() or __dict__ to TradeOrder (and similar).

    Point = collections.namedtuple('Point', ['x', 'y', 'val'])    
    print(Point._fields)
python.exe .\history-deal-mt-1.py
('x', 'y', 'val')

Really, it's not convenient now.

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

Usinghistory_orders_get().

In the documentation, explicitly copy-paste :)(https://www.mql5.com/ru/docs/integration/python_metatrader5/mt5historyordersget_py)

Update the help or go to the link

 
Rashid Umarov:

There are no plans. Check new bars on a timer or in a loop.

Can you be more specific about the timer?

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

Folks, pls - add something like _fields or as_dict() or __dict__ to TradeOrder (and similar).

Really, it's not convenient now.

In 5.0.27 it already is, all structure sequence (analog of named tuple for C API) added method _asdict()

sym = mt5.symbol_info("EURUSD")._asdict()
for i in sym:
   print(i, '=', sym[i])
Reason: