Hello we have
TimeToString()
Function and also
StringToTime()
Function so i am not sure what you are trying to do but time is usually datetime datatype.
You can also see here https://www.mql5.com/en/docs/constants/structures/mqldatetime
- www.mql5.com
Hi
I am trying to allow an EA to accept some external integer values as string times "HH;MM".
I have the following code which compiles and runs but an error occurs and it says the time is formatted incorrectly.
I suspect it may be my concatenation method but can anyone advise?
extern int StartHr = 1;
extern int
StartMn =10;
extern int EndHr = 2;
extern int
EndMn =20;
string strStartHour = StringFormat("%[0][2]",IntegerToString(StartHr));
string strStartMin =
StringFormat("%[0][2]",IntegerToString(StartMn));
string strEndHour = StringFormat("%[0][2]",IntegerToString(EndHr));
string
strEndMin = StringFormat("%[0][2]",IntegerToString(EndMn));
//Print(strEndHour);
string strChartServerStartTime = StringConcatenate(strStartHour, ":",strStartMin);
string
strChartServerEndTime = StringConcatenate(strEndHour, ":",strEndMin);
string Chart_Server_Start_Time = strChartServerStartTime;
string Chart_Server_End_Time = strChartServerEndTime;
Thanks
Paxman
did u try like this
string Chart_Server_Start_Time = StringFormat("%02d;%02d",StartHr ,StartMn);
Hello we have
Function and also
Function so i am not sure what you are trying to do but time is usually datetime datatype.
You can also see here https://www.mql5.com/en/docs/constants/structures/mqldatetime
The EA set file accepts a string input as set out HH:MM.
Strategy tester cannot increment such strings to allow testing of timeslots.
My idea was to feed the code with the string but allow the user to input integers.
I think the ideas mentioned here will lead to a solution but i can not see any working without a modification currently. I will try myself and see what i can do.
I tried to do the conversion in stages and i had hoped to check the results using Print (as debug does not work in MT4 so i am told) but could not
get print to work either.
BTW i misstyped the separator it should have been a ":".
Thanks
Paxman
did u try like this
This would solve part of the problem but i wonder how to insert the ":" character in between the StartHr StartMin?
Thanks
Paxmanstring p="23;52"; //"HH;MM"
This is interesting but i an starting from a point of two integer values and trying to convert to HH:MM and not the other way about.
Thanks
Paxman
input int StartHour =09; input int StartMinute=15; datetime g_StartTime; int OnInit() { string timestr=StringFormat("%02d:%02d",StartHour,StartMinute); g_StartTime=StringToTime(timestr); ... } void OnTick() { if(TimeCurrent()>=g_StartTime) DoSomeWork();This will work for the current day. If the EA runs overnight however you need to recompute g_StartTime as it contains the current date.
This would solve part of the problem but i wonder how to insert the ":" character in between the StartHr StartMin?
Thanks
Paxmanreplace ";" by ":"
string Chart_Server_Start_Time = StringFormat("%02d:%02d",StartHr ,StartMn);
replace ";" by ":"
Ah sorry for some bizzare reason i thought the ; split the format but did not form part of it LOL thanks.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I am trying to allow an EA to accept some external integer values as string times "HH;MM".
I have the following code which compiles and runs but an error occurs and it says the time is formatted incorrectly.
I suspect it may be my concatenation method but can anyone advise?
extern int StartHr = 1;
extern int StartMn =10;
extern int EndHr = 2;
extern int EndMn =20;
string strStartHour = StringFormat("%[0][2]",IntegerToString(StartHr));
string strStartMin = StringFormat("%[0][2]",IntegerToString(StartMn));
string strEndHour = StringFormat("%[0][2]",IntegerToString(EndHr));
string strEndMin = StringFormat("%[0][2]",IntegerToString(EndMn));
//Print(strEndHour);
string strChartServerStartTime = StringConcatenate(strStartHour, ":",strStartMin);
string strChartServerEndTime = StringConcatenate(strEndHour, ":",strEndMin);
string Chart_Server_Start_Time = strChartServerStartTime;
string Chart_Server_End_Time = strChartServerEndTime;
Thanks
Paxman