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.
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.
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);
PrevTime = CloseTime;
HistoryDealsTotal() = 345
Time[Bench(LastTimeMQL4)] = 186586
Time[Bench(LastTimeMQL5)] = 151659
The larger the size of the history of trading, the stronger the MQL5-native loses.
HistoryDealsTotal() = 3721
HistoryOrdersTotal() = 6303
Time[Bench(LastTimeMQL4)] = 1111305
Time[Bench(LastTimeMQL5)] = 1799255
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?