Libraries: MT4Orders - page 9

 
Stanislav Korotky #:
Since only one version is supported, why not leave it alone in the KB, or at least make a redirect from the wrong version in big red letters?
The author can't do anything about versions in other languages.
 
fxsaber #:
The author can't do anything about versions in other languages.
It has been reported to MQ attention.
 


 #include <MT4Orders.mqh>
 input datetime StartDate = D'2025.12.15 00:42:37' ;
 input datetime EndDate = D'2025.12.15 23:59:52' ;

 void OnStart() {
   int total = OrdersHistoryTotal();
   Print("OrdersHistoryTotal = " , total);
   for ( int i = 0 ; i < total; i++) {
     if (! OrderSelect (i, SELECT_BY_POS, MODE_HISTORY)) continue ;
     datetime openTime = OrderOpenTime();
     datetime closeTime = OrderCloseTime();
     if (openTime >= StartDate && closeTime <= EndDate) {
       ENUM_ORDER_TYPE orderType = ( ENUM_ORDER_TYPE )OrderType();
       if (orderType == OP_BUY || orderType == OP_SELL) {
        OrderPrint();
      }
    }
  }
}

I don't know why the number of lots obtained is 0.00 instead of 0.01?

If you need an account, I can provide it via private message.

OrderLots() also returns 0.

 
hini #:

I don't know why the number of lots received is 0.00 and not 0.01?

This is the correct behaviour. You have closed the position counter via CloseBy.

Run CustomReport - there will be more information to understand.

 
fxsaber #:

This is the correct behaviour. You have closed the position counter via CloseBy.

Run CustomReport - there will be more information to understand.

I manually closed all my positions using MT5, and the returned lot number was 0, which caused unexpected calculations for that order. Why does it return 0.00 instead of the official figure? For example, regarding the order count, I'm unsure whether to exclude this order. Logically, it shouldn't be excluded, but a return of 0 lots indicates an invalid order. 

Where can I modify this behavior?


 
If it's buy 0.01 and sell 0.03, will it return 0.02? I haven't tested it yet. I'll test it when I have time.
 
hini #:

I manually closed all my positions using MT5 and the lot number returned was 0, causing unexpected calculations for this order. Why is 0.00 being returned instead of the official number? For example, regarding the order count, I'm not sure if this order should be excluded. Logically, it should not be excluded, but returning 0 lots indicates that the order is invalid.

Where can I change this behaviour?

This is the correct behaviour, which is identical to the behaviour in MT4 in these situations. If two multidirectional 1 lot positions are closed via CloseBy, the total volume of the closed position should be 1, not 2.

The sum of lots is the trading volume, by which, among other things, the commission is calculated.


https://www.mql5.com/ru/blogs/post/751985

https://www.mql5.com/ru/blogs/post/754817

 
hini #:
If you buy 0.01 and sell 0.03, will 0.02 come back? I haven't tested this yet. I will test this when I have time.
There will be an open position of 0.01 lot and two closed positions: 0.01 lot and 0.00 (information) lot.
 
fxsaber # :
There will be an open position of 0.01 lot and two closed positions: 0.01 lot and 0.00 (information) lot.
If I want to count the number of trades, it should be 0.04, but now it is 0.03?
 
hini #:
If I want to count the number of trades, it should be 0.04, but now it's 0.03?
Gave all the links with details. Everything works correctly.