datetime Current= TimeCurrent(), Begin = StringToTime( TimeToString(Current, TIME_DATE) + " 03:00" ), End = StringToTime( TimeToString(Current, TIME_DATE) + " 23:00" ); Print("Current Time = ", Current); Print("Begin Time = ", Begin); Print("Finish Time = ", End);
For the current day
You seem to have missed the point.
I was talking about a possible problem with StrToTime()
TimeCurrent is always broker-server time. Your begin and end times had rolled-over to the next day since those times had already passed. Working with time using strings is asking for weird bugs like this. Instead, you should practice working with time using literal integers and the Mql-time-structs and convert back and forth with the structs instead of time-strings. It may be more verbose, but you always know exactly what you're getting.
So for example if I know I need to set some times for the following trading day the method is as follows.
#property strict void OnStart() { MqlDateTime begin,end; TimeToStruct(TimeCurrent()+PeriodSeconds(PERIOD_D1),begin); begin.sec=0; begin.min=0; end=begin; begin.hour=3; end.hour=23; printf( "%s -> %s", TimeToString(StructToTime(begin)), TimeToString(StructToTime(end)) ); }
Find bar of the same time one day ago - Simple Trading Strategies - MQL4 and MetaTrader 4 - MQL4 programming forum
Seems like you have all missed the point.
The function should return the time with the current broker's date not my local time date.
I am not asking for alternatives I am suggesting that there might be a bug.
I have reported it to the service desk, so will see what they have to say.
Seems like you have all missed the point.
The function should return the time with the current broker's date not my local time date.
I am not asking for alternatives I am suggesting that there might be a bug.
I have reported it to the service desk, so will see what they have to say.
Seems like you have all missed the point.
The function should return the time with the current broker's date not my local time date.
I am not asking for alternatives I am suggesting that there might be a bug.
I have reported it to the service desk , so will see what they have to say.
And this is not the server date???
datetime Current= TimeCurrent(), Begin = StringToTime( TimeToString(Current, TIME_DATE) + " 03:00" ), End = StringToTime( TimeToString(Current, TIME_DATE) + " 23:00" );
You can use this way
MqlDateTime structTime; TimeToStruct(TimeCurrent(), structTime); structTime.min = 0; structTime.sec = 0; structTime.hour = 3; datetime begin = StructToTime( structTime ); structTime.hour = 23; datetime end = StructToTime( structTime );P.S. You need to get the server date. Then use. As you wish.
You are running it at your computer so it uses local time and not broker time, seems logical to me. I doubt it's a bug, the problem is rather it's not documented.
Yes Alain, apparently, according to service desk it is local time. As you say the documentation does not mention this at all.
From codes done by other coders that I have modified, I know that a lot assume that this is broker time, not local time. Luckily I have rarely used this function myself.
Yes Alain, apparently, according to service desk it is local time. As you say the documentation does not mention this at all.
From codes done by other coders that I have modified, I know that a lot assume that this is broker time, not local time. Luckily I have rarely used this function myself.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
now I may just be missing something here.
resulted in
0 03:59:07.242 Scratchings NZDUSD,H1: Current Time = 2018.05.08 23:59:06
0 03:59:07.242 Scratchings NZDUSD,H1: Begin Time = 2018.05.09 03:00:00
0 03:59:07.242 Scratchings NZDUSD,H1: Finish Time = 2018.05.09 23:00:00
As you can see, the date for the current time is 8th, but Begin and Finish are both 9th.
This was just before midnight broker time and just before 4 AM my computer time.
I ran the code again when broker midnight passed
0 04:00:30.517 Scratchings NZDUSD,H1: Current Time = 2018.05.09 00:00:19
0 04:00:30.517 Scratchings NZDUSD,H1: Begin Time = 2018.05.09 03:00:00
0 04:00:30.517 Scratchings NZDUSD,H1: Finish Time = 2018.05.09 23:00:00
and then all dates were the 9th.
Documentation states
So is the current date taken from Local time not broker time?
That doesn't make sense.