Libraries: MT4Orders - page 2

 
HotFix! Please download the latest version.
 

This library is amazing!! So easy to run MT4 code in MT5. Thanks a lot

I have one issue the OrderTicket() function doesn't not return the right number when the trade is closed. This is a real problem to follow a trade when is closed.

For example a trade # 4584849 will become # 38484939 when closed.

Thanks in advance for your help

This is my code in a script:

#include <MT4Orders1.mqh>
void OnStart()
  {
int n=OrdersTotal();
//pLog(StringConcatenateV4("detectCloseTrade n=",n," ticket=",ticket));
   for(int i=n-1; i>=0; i--)
     {
      //---
      //if((ticket=HistoryOrderGetTicket(i))>0 && isMagic())
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()>=OP_BUY && OrderSymbol()==Symbol())
        {
         Print("MOH ",i, " ",OrderTicket());
        }
     }
  Print("History");
  n=OrdersHistoryTotal();
//pLog(StringConcatenateV4("detectCloseTrade n=",n," ticket=",ticket));
   for(int i=n-1; i>=0; i--)
     {
      //---
      //if((ticket=HistoryOrderGetTicket(i))>0 && isMagic())
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderType()>=OP_BUY && OrderSymbol()==Symbol())
        {
         Print("MOH ",i, " ",OrderTicket());
        }
     }
}
 
It's not a issue. A closed position in MT5 has several tickets. They will all work through SELECT_BY_TICKET.
Perhaps you need OrderTicketID().
 

for(int dfz_in_29=0 ; dfz_in_29<OrdersTotal() ; dfz_in_29 = dfz_in_29 + 1)

     {

      if(OrderSelect(dfz_in_29,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol())   

        {


         if(OrderType()==0)

           {

            dfz_in_12 = OrderTicket() ;  // the   OrderTicket() is no return value,  in demo , the value is  Error 4003 //    -2045194504  ? 



}}}



what about are this ...   please tell me  too :thanx very much ...

 
sisz1688:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.


 
Библиотеки: MT4Orders
Библиотеки: MT4Orders
  • 2021.02.09
  • www.mql5.com
MT4Orders: Автор: fxsaber...
 

Bug found: 

Function OrderOpenReason() returns (ENUM_DEAL_REASON)DEAL_REASON_TP for orders closed on takeprofit.

 
amrali:

Bug found: 

Function OrderOpenReason() returns (ENUM_DEAL_REASON)DEAL_REASON_TP for orders closed on takeprofit.

Thank you! Fixed.

 

At my request, the MetaQutoes has completely localized the latest update of the library into English. The latest build of the library is now available on the English page with comments in the source code translated into English.


Difference from the previous version that was available on the English-language page.

// List of changes:
// 02.11.2018
//   Fix: Now the MT4 position Open price cannot be zero before its triggering.
//   Fix: Some rare execution aspects of certain trading servers have been taken into account.
// 26.11.2018
//   Fix: Magic and comment of a closed MT4 position: Priority of the relevant fields of opening transactions is higher than that of closing ones.
//   Fix: Rare changes in MT5-OrdersTotal and MT5-PositionsTotal are taken into account while calculating MT4-OrdersTotal and MT4-OrderSelect.
//   Fix: Library does not take into account the orders which have opened a position, but have not been yet deleted from MT5.
// 17.01.2019
//   Fix: Fixed an unfortunate error in selecting pending orders.
// 08.02.2019
//   Add: Comment of a position is saved at partial closing via OrderClose.
//        If you need to modify the comment on an open position at partial closing, you can specify it in OrderClose.
// 20.02.2019
//   Fix: In case of no MT5 order, the library will expect the history synchronization from the existing MT5 transaction. In case of failure, it will inform about it.
// 13.03.2019
//   Add: Added OrderTicketID() - PositionID of an MT5 transaction or MT5 position, and the ticket of a pending MT4 order.
//   Add: SELECT_BY_TICKET works for all MT5 tickets (and MT5-PositionID).
// 02.11.2019
//   Fix: Corrected lot, commission, and Close price for CloseBy positions.
// 12.01.2020
//   Fix: OrderTicketID() for balance deals returns now a correct value.
//   Fix: Fixed SELECT_BY_TICKET - selection by OrderTicketID() (MT5-PositionID).
//   Fix: Changed name of the internal library method for greater compatibility with macros.
// 10.04.2020
//   Fix: Partially executed live pending order did not get into OrdersTotal().
// 09.06.2020
//   Add: StopLoss/TakeProfit/ClosePriceRequest for closed positions are now better defined.
// 10.06.2020
//   Add: Added milliseconds, removed price and order rounding in OrderPrint().
// 13.08.2020
//   Add: Added ability to check the performance of library parts via the MT4ORDERS_BENCHMARK_MINTIME macro.
// 20.08.2020
//   Fix: Taking into account the revealed features of partial order execution.
// 29.08.2020
//   Fix: Implemented faster working with the history of trades.
// 24.09.2020
//   Add: If you need to increase the priority of an MT5 order over an MT5 position when selecting a live MT4 order by SELECT_BY_TICKET (the same tickets),
//        this can be done by changing the ticket size to negative: OrderSelect(-Ticket, SELECT_BY_TICKET).
//   Add: If you need to specify the selection of only MT5 order when modifying a live MT4 order (the same tickets),
//        this can be done by changing the ticket size to negative: OrderModify(-Ticket, ...).
//   Add: OrderSelect(INT_MAX, SELECT_BY_POS) - switch to an MT5 position without checking the existence and updating.
//        OrderSelect(INT_MIN, SELECT_BY_POS) - switch to a live MT5 order without checking the existence and updating.
//   Fix: Implemented faster working with the history of trades.
// 30.09.2020
//   Fix: Implemented faster working with the history of trades.
// 08.10.2020
//   Fix: OrderSend of a market order could be executed longer due to a flaw in a fresh MT5 deal search.
// 21.10.2020
//   Add: To provide compatibility for MT4, added OrderTicketID() - returns OrderTicket().
// 11.11.2020
//   Fix: OrderTicketID() and OrderTicketOpen() return the value type specified in TICKET_TYPE.
// 06.12.2020
//   Fix: The cases of incorrect SL/TP execution records in the MT5 trading history are now taken into account.
//   Add: The MT4ORDERS_TESTER_SELECT_BY_TICKET market forces SELECT_BY_TICKET to work in the Tester only via OrderTicketID().
// 04.05.2021
//   Fix: The MT5 orders that open positions and fail to disappear are no longer added to the list of MT4 orders.
//   Fix: CloseBy MT5 orders no longer appear in the list of MT4 orders.
// 12.05.2021
//   Add: The MT4ORDERS_BYPASS_MAXTIME macro changes the constantly emerging cases of trading environment desynchronization in MT5.
// 13.05.2021
//   Fix: Fixed bug in OrderOpenReason().
// 14.05.2021
//   Fix: The BYPASS mechanism no longer affects OrderSelect(INT_MAX, SELECT_BY_POS) and OrderSelect(INT_MIN, SELECT_BY_POS).
// 01.06.2021
//   Fix: Compatibility with the compiler build 2449 and higher.
//   Fix: Improved synchronization. ByPass.mqh must be of the latest version.
//   Add: OrderLots(true) - synchronized size of the selected position, taking into account all orders which close this position.


I recommend using the latest version along with the synchronization mechanism. Then all the problems that no other trading library can solve will be imperceptible.

#define MT4ORDERS_BYPASS_MAXTIME 1000000 // Max time (in microseconds) to wait for the trading environment synchronization
#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

For this mechanism to work, you need to download this library. All complex and effective checks of the correctness of the trading environment will be done automatically, without distracting the user when writing trading logic.

TradesID
TradesID
  • www.mql5.com
Быстрая работа с POSITION_ID