OrderCloseTime Expert Advisor MQL5 - page 2

To add comments, please log in or register
fxsaber
10625
fxsaber  

Alain Verleyen:
It was not a specification, obviously I will not select all history on each tick.

So write a function that you can call on each event NewTick!


No it's exactly what was asked. Why are you thinking it's different ?

It does not matter. Look at the result above.


I demonstrated above it is. Why are you saying it's not ?

Measuring the performance of the code is done on a multiple call.

Alain Verleyen
36581
Alain Verleyen  

fxsaber:

...

Measuring the performance of the code is done on a multiple call.

If you want a scientific benchmark yes. It was not my goal. I executed the script a dozen of time (Amount=1) and mql5 style was ALWAYS faster, obviously. Everyone can check by himself and should better learn mql5.

fxsaber
10625
fxsaber  
Alain Verleyen:

If you want a scientific benchmark yes. It was not my goal. I executed the script a dozen of time (Amount=1) and mql5 style was ALWAYS faster, obviously. Everyone can check by himself and should better learn mql5.

Refer to @Renat Fatkhullin for clarification.

fxsaber
10625
fxsaber  
fxsaber:

So write a function that you can call on each event NewTick!

void LastTimeMQL5( datetime &OpenTime, datetime &CloseTime )
{
  static datetime PrevTime = 0;
  
  if (HistorySelect(PrevTime, INT_MAX)) // HistorySelect(0, INT_MAX) - slow.
  {
    for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
    {
      const ulong Ticket = HistoryDealGetTicket(i);
  
      if (HistoryDealGetInteger(Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
      {
        CloseTime = (datetime)HistoryDealGetInteger(Ticket, DEAL_TIME);

        if (HistorySelectByPosition(HistoryDealGetInteger(Ticket, DEAL_POSITION_ID)))
          OpenTime = (datetime)HistoryDealGetInteger(HistoryDealGetTicket(0), DEAL_TIME);
          
        break;
      }
    }
  }
  
  PrevTime = CloseTime;
}


Result

HistoryDealsTotal() = 345
1970.01.01 19:26:40
Time[Bench(LastTimeMQL4)] = 186586
1970.01.01 19:26:40
Time[Bench(LastTimeMQL5)] = 151659
fxsaber
10625
fxsaber  

The larger the size of the history of trading, the stronger the MQL5-native loses.

HistoryDealsTotal() = 3721
HistoryOrdersTotal() = 6303
1970.01.03 02:00:00
Time[Bench(LastTimeMQL4)] = 1111305
1970.01.03 02:00:00
Time[Bench(LastTimeMQL5)] = 1799255
Alain Verleyen
36581
Alain Verleyen  
fxsaber:

The larger the size of the history of trading, the stronger the MQL5-native loses.

Your library is using the MQL5-native and is keeping data in memory. Of course the mql5 above could be optimized to keep data in memory too, and you know it.

If someone want to use your library or an other, there is no problem. However, I am still suggesting people to learn the mql5 way.

fxsaber
10625
fxsaber  
Alain Verleyen:

Your library is using the MQL5-native and is keeping data in memory. Of course the mql5 above could be optimized to keep data in memory too, and you know it.

If someone want to use your library or an other, there is no problem. However, I am still suggesting people to learn the mql5 way.

It's not in my library. It's not at all clear how to write simple functions in MQL5-native, so that they are still fast?

12
To add comments, please log in or register