Libraries: MT4Orders - page 5

 
pcdeni #:

Is it possible there is a memory leak or a more than necessary memory use? Maybe in this.tickets or in this.amount (::ArrayResize) or maybe somewhere else?

The size of the arrays only get increased over time. Is this a must? Is it possible to empty them or perhaps don't load all the previous trades?

The library does not fully cache history data. Getting a memory shortage is possible only in theory, but not in practice.

Write a script that sorts through the entire trading history using the library and see how much memory is consumed.

 
fxsaber #:

The library does not fully cache history data. Getting a memory shortage is possible only in theory, but not in practice.

Write a script that sorts through the entire trading history using the library and see how much memory is consumed.

in strategy testing the ea is using 25 GB per core.

edit: it is a 1 year timeframe test, so not a lot.
 
pcdeni #:

in strategy testing the ea is using 25 GB per core.

edit: it is a 1 year timeframe test, so not a lot.

The library (MT4Orders.mqh) does not consume that amount of memory. You can run, for example, this EA to see for yourself.

Most likely, you are working with indicators incorrectly: you create new indicator handles, but do not delete the old ones.

 
fxsaber #:

The library (MT4Orders.mqh) does not consume that amount of memory. You can run, for example, this EA to see for yourself.

Most likely, you are working with indicators incorrectly: you create new indicator handles, but do not delete the old ones.

I don't use any indicators.

While you are right, the library doesn't consume that amount of memory, it does however use this: 

HistorySelect(0,INT_MAX);

According to this page:

https://www.mql5.com/en/articles/211

"The attempt to handle all of the trading history, in the majority of cases, is wrong. When the number of processed deals/orders becomes around thousands and tens of thousands, the work of the program drastically slows down."

In case there are 1M+ trades, your library stores all of them in an array.

I appreciate you made this library, bridging between mt4 and mt5, and you shared it with everyone, not trying to trash it. I just find it pityful that there is only one place online that describes how to get swap and commission values properly (given that the broker actually provides them), and it is written in such an obfuscated way.

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • www.mql5.com
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
 
pcdeni #:

While you are right, the library doesn't consume that amount of memory, it does however use this: 

According to this page:

https://www.mql5.com/en/articles/211

"The attempt to handle all of the trading history, in the majority of cases, is wrong. When the number of processed deals/orders becomes around thousands and tens of thousands, the work of the program drastically slows down."

In case there are 1M+ trades, your library stores all of them in an array.

#define MT4ORDERS_BYPASS_MAXTIME 1000000
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

double GetSummaryCommissionMQL5()
{
  double Res = 0;
  
  if (HistorySelect(0, INT_MAX))
    for (uint i = HistoryDealsTotal(); (bool)i--; )
      Res += HistoryDealGetDouble(HistoryDealGetTicket(i), DEAL_COMMISSION);

  return(NormalizeDouble(Res, 2));
}

double GetSummaryCommissionMQL4()
{
  double Res = 0;
  
  for (uint i = OrdersHistoryTotal(); (bool)i--; )
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
      Res += OrderCommission();

  return(NormalizeDouble(Res, 2));
}

#define PRINT(A) Print(#A + " = " + (string)(A))

void OnStart()
{
  PRINT(MQLInfoInteger(MQL_MEMORY_USED));
  PRINT(TerminalInfoInteger(TERMINAL_MEMORY_USED));

  PRINT(GetSummaryCommissionMQL5());

  PRINT(MQLInfoInteger(MQL_MEMORY_USED));
  PRINT(TerminalInfoInteger(TERMINAL_MEMORY_USED));

  PRINT(GetSummaryCommissionMQL4());

  PRINT(MQLInfoInteger(MQL_MEMORY_USED));
  PRINT(TerminalInfoInteger(TERMINAL_MEMORY_USED));

  PRINT(HistoryDealsTotal());
  PRINT(HistoryOrdersTotal());
  PRINT(PositionsTotal());
}


Result.

MQLInfoInteger(MQL_MEMORY_USED) = 1
TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1203

GetSummaryCommissionMQL5() = -43568.97
MQLInfoInteger(MQL_MEMORY_USED) = 1
TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1404

GetSummaryCommissionMQL4() = -43568.97
MQLInfoInteger(MQL_MEMORY_USED) = 45
TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1424

HistoryDealsTotal() = 130330
HistoryOrdersTotal() = 190241
PositionsTotal() = 0


130K deals + 190K orders, terminal memory consumption increased by 20 MB (+10%).

You can measure performance yourself. The documentation is long out of date.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: MT4Orders

fxsaber, 2023.07.22 13:23

The idea behind this macro is

#define MT4ORDERS_AUTO_VALIDATION // Trade orders are sent only in case of successful validation
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

that you don't need to do any checks in your code. This makes the code concise and immediately ready to pass automatic validation in the Market.

 

Hey there,

many thanks for sharing this impressive library.

Would it be possible to use it on MT5 .tst files from the Tester\Cache directory and to extract the orders from there?

Thank you in advance.

 
Eric Emmrich #:

Would it be possible to use it on MT5 .tst files from the Tester\Cache directory and to extract the orders from there?

Read from here.

In Strategy Tester, how to know which "Out" order correspond to which "In" order ?
In Strategy Tester, how to know which "Out" order correspond to which "In" order ?
  • 2023.07.31
  • www.mql5.com
Hello, See the results of a Strategy testing below: If we consider Order number 2 for instance (of type "sell", and direction "in", executed at 14...
 
fxsaber #:

Read from here.

Awesome, thank you so much! Is it possible to modify the report layout, e.g. by modifying a Report.htm template file? 

Also, would it be possible to specify the .tst file that is used for report generation, rather than always using the latest one?

Thank you in advance.

 
Eric Emmrich #:

Awesome, thank you so much! Is it possible to modify the report layout, e.g. by modifying a Report.htm template file? 

Such flexibility was not envisaged, because wrote for himself.

Also, would it be possible to specify the .tst file that is used for report generation, rather than always using the latest one?

Didn't make this functionality. You can place your file in the Tester cache folder by changing its date to the current one.

Reason: