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

 
Sivoraksha-ia:
Strange, but an empty table arrives too. There is no need to open anything in the terminal itself as in Quicksilver to make the unloading work?

Any chart with the desired pair (for ticks).

 
Hi all,


I have a problem with the OrderSendResult structure returned after an order_send () request using the Python API. One of the fields returned is a "comment" which should contain the broker's comment on the transaction. However, this field returns the same comment that was passed to the request, not the broker return as it should.


To reproduce the error, do the following:

1. Create a query that results in a comment. Fill the "comment" query with a dummy comment.

2. Send the request using the order_send () command from the Python API.

3. In the returned orderSendResult object, check the "comment" field.


The "comment" field will pass the same comment, whereas it should have a comment returned by the broker, which can be checked in the "Log" tab of the MT5 Terminal.

Can anyone confirm this? Is there any way to get a comment from the broker?



Документация по MQL5: Торговые функции / OrderSend
Документация по MQL5: Торговые функции / OrderSend
  • www.mql5.com
OrderSend - Торговые функции - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Vladimir Perervenko:

Would you add a description to the Documentation?

Added

  • market_book_add
  • market_book_get
  • market_book_release
  • Документация по MQL5: Интеграция / MetaTrader для Python / market_book_add
    Документация по MQL5: Интеграция / MetaTrader для Python / market_book_add
    • www.mql5.com
    market_book_add - MetaTrader для Python - Интеграция - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
     

    I want to organise a virtual trade accounting in python. I need it in order to distinguish the char- teristics of different trading strategies. The broker used is Otkritie. There is no netting. There is a common position for the instrument, Stop and Take of the position is common. I decided to do this: I open a trade by any strategy by market with any volume, without stop and take. Instead, I put a stop and limit order of the same size. I memorize the orders in the table separately. Every certain period of time, I place orders = mt5.orders_get(symbol=symb) and get a list of known ticket orders.ticket.tolist().

    Then I go through my trade table and check if a stop or limit order ticket still exists in the list of open orders received. If there is no stop loss, it means that a stop loss has triggered virtually; if there is no limit, it means a take profit. Then I delete entries for this trade from my table and delete the remaining pending order for this trade. And everything works except one - I don't know how to calculate virtual profit on this deal. In the picture you can see the sell stop is set at 141430, but in reality there was a slippage and the open price is 141350. I request the request for a triggered position: deals = mt5.history_orders_get(ticket=246525084) (this ticket has been saved in the system when the order was placed, as in the picture above), but in my reply I see no information about the order place, only information about the order place. The history shows that the sell stop was really executed in the ticket 15215696 and I can ask for the right price in this ticket. But first I need to find the ticket from the trade. How do I match this ticket with the pending order ticket (sell stop)?

     
    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?
     
    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.
     
    Is it possible to make a python api news calendar with access to history, to do research?
     
    Dear, are there anyone who trades on MOEX? Who has the same problem that when you initialise the connection to the terminal, it reconnects to the server and asks for a certificate password?
    Документация по MQL5: Интеграция / MetaTrader для Python / initialize
    Документация по MQL5: Интеграция / MetaTrader для Python / initialize
    • www.mql5.com
    initialize - MetaTrader для Python - Интеграция - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
     

    order_send and order_check return None. I don't understand where to look. Please tell me what's wrong. Please.

    Code

    import MetaTrader5 as mt
    
    if not mt.initialize(login=12345):#
        print("initialize() failed")
        mt.shutdown()
    
    terminal_info=mt.terminal_info()
    if terminal_info!=None:
        print(f"terminal {'''connected''' if terminal_info.connected else '''disconnected'''}")
    print("version: ",mt.version())
    
    info = mt.symbol_info("Si-6.21")
    print(f"Si-6.21  {info.bid=}  {info.ask=}")
    
    request = {
        "action": mt.TRADE_ACTION_PENDING,
        "symbol": "Si-6.21",
        "volume": 1,
        "type": mt.ORDER_TYPE_BUY_LIMIT,
        "price": 77300,
        "sl": 0,
        "tp": 0,
        "deviation": 0,
        "magic": 123,
        "comment": "test",
        "type_time": mt.ORDER_TIME_DAY,
        "type_filling": mt.ORDER_FILLING_RETURN,
    }
    
    check = mt.order_check(request)
    print("order check: ",check)
    
    ret = mt.order_send(request)
    print("order send: ", ret)
    if not ret is None:
        print(f" retcode:{ret.retcode}")
    

    Output

    terminal connected
    version:  (500, 2875, '02 Apr 2021')
    Si-6.21  info.bid=77770.0  info.ask=77773.0
    order check:  None
    order send:  None
    
    Process finished with exit code 0


    I managed to solve the problem. In request volume,price,sl,tp fields should have float type. It works like this

    request = {
        "action": mt.TRADE_ACTION_PENDING,
        "symbol": "Si-6.21",
        "volume": 1.,
        "type": mt.ORDER_TYPE_BUY_LIMIT,
        "price": 77300.,
        "sl": 0.,
        "tp": 0.,
        "deviation": 0,
        "magic": 123,
        "comment": "test",
        "type_time": mt.ORDER_TIME_DAY,
        "type_filling": mt.ORDER_FILLING_RETURN,
    }
     

    Colleagues, please advise:

    1. How can I pull available trading session intervals by instrument from mt5 in Python and update them periodically?

    2. do i expect to see a method in the library to request and change Trailing Stop on open positions?

    Reason: