- Perhaps you should read the manual.
Conversion Functions / StringToTime - Reference on algorithmic/automated trading language for MetaTrader 5 - Of course if you do that, you won't be able to use Hour.
by opening a job and hiring a developer you will get a professional work coded to you
then, you will keep it saved to your library
Please see
TimeToString
Converting a value containing time in seconds elapsed since 01.01.1970 into a string of "yyyy.mm.dd hh:mi" format.
string TimeToString( datetime value, // number int mode=TIME_DATE|TIME_MINUTES // output format );
Parameters
value
[in] Time in seconds from 00:00 1970/01/01.
mode=TIME_DATE|TIME_MINUTES
[in] Additional data input mode. Can be one or combined flag:
TIME_DATE gets result as "yyyy.mm.dd", TIME_MINUTES gets result as "hh:mi", TIME_SECONDS gets results as "hh:mi:ss".
Return Value
String.
https://www.mql5.com/en/docs/convert/timetostring- www.mql5.com
It sounds like you would like to use a string input so you can type the exact time in minutes and hours, correct? If so then this is an example of how you could implement it.
input string TimeInput = "20:45"; void OnStart() { Print(CompareTime(TimeInput)); } //+------------------------------------------------------------------+ bool CompareTime(string time_str) { datetime time = StringToTime(time_str); MqlDateTime t1,t2; TimeToStruct(time,t1); TimeCurrent(t2); if(t1.hour==t2.hour && t1.min==t2.min) return true; return false; }
Hi
I have an extern int opentime
Above is used to enter a time.
This time is checked against another 'if' statement
if ( Hour() == opentime )
Above works but 'Hour' can only be entered as two digit number i.e. 23 or 04
I want to enter the time as 23:46 or 04:57
Can anyone point me in the right direction, thanks
regards
Jai
Hello in 2020!
It will work:
string hhmm = TimeToString(TimeCurrent(),TIME_MINUTES); if(hhmm == "23:h46" || hhmm == "04:57" ){}
Even with a string type, you will be able to use other signals in your condition, like <=, >=, !=
- 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 have an extern int opentime
Above is used to enter a time.
This time is checked against another 'if' statement
if ( Hour() == opentime )
Above works but 'Hour' can only be entered as two digit number i.e. 23 or 04
I want to enter the time as 23:46 or 04:57
Can anyone point me in the right direction, thanks
regards
Jai