MQL4 Time function miscalculation

MQL4 Time function miscalculation

Manage alerts

Loading saved threads...

Pinto André · External communityPost link
External question — Stack Overflow Stack Exchange Author: Pinto André Original post: https://stackoverflow.com/questions/71413450 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have the following function where tries to calculate the time between the last closed trade and the current time. if the time difference is <> that a certain number of bars it gives a different result. that being said, during the backtest at some point the bar calculation begins to fail and i do not find the error. Any thoughts? int LastOrderTicket() { datetime TicketTime = 0; int LastOT; datetime Timeorder = LastOrderTime(), Timeahora = TimeCurrent(), Times = Timeahora - Timeorder; int m = TimeMinute(Times), h = TimeHour(Times), d = TimeDay(Times), bars = (((d - 1) * 24 * 60) + (h * 60) + m) / 240; for(int ix = 0; ix < OrdersHistoryTotal(); ix++) { if(OrderSelect(ix, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol()) { if(bars > barsback) { LastOT = -1; } else { if(bars < barsback) { LastOT = OrderType(); //For testing } } } else Print("OrderSelect returned the error of ",GetLastError()); } Print("TicketN ",LastOT); Print("bars ",bars); Print("Timeorder=",TimeToStr(Timeorder, TIME_MINUTES|TIME_SECONDS|TIME_DATE)); Print("Timeahora=",TimeToStr(Timeahora, TIME_MINUTES|TIME_SECONDS|TIME_DATE)); Print("Times=",TimeToStr(Times, TIME_MINUTES|TIME_SECONDS|TIME_DATE)); Print("m ",m); Print("h ",h); Print("d ",d); return(LastOT); // Buy==0, Sell==1, Others==2 through 5 } Here where i find the error: 0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: bars 182 0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Timeorder=2021.03.09 12:00:00 0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Timeahora=2021.08.06 23:59:59 0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: Times=1970.05.31 11:59:59 0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: m 59 0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: h 11 **0 18:02:11.243 2021.08.06 23:59:59 BBReverse V1 EURUSD,H4: d 31** 0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: bars 8 0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Timeorder=2021.03.09 12:00:00 0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Timeahora=2021.08.08 23:05:00 0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: Times=1970.06.02 11:05:00 0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: m 5 0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: h 11 **0 18:02:11.243 2021.08.08 23:05:00 BBReverse V1 EURUSD,H4: d 2** the function time keep summing up but the day value not... thank you.
Quote
Report
Yasin İPEK · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Yasin İPEK Original post: https://stackoverflow.com/a/71525165 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. datetime lastTime = TimeCurrent()-OrderOpenTime();
Quote
Report
Pinto André · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Pinto André Original post: https://stackoverflow.com/a/71540344 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. i've used ibarshif and it worked. thank you anyway.
Quote
Report

Post Reply

Checking account access…