I'm trying to get my EA to run only during certain hours.. I am comparing time current with an assigned date time variable.. it seems to be a logical way.. but I'm having trouble with the date part of it.. is there a way to return current date with a set time to a datetime variable..
Or if there is any other way you can recommend to accomplish this..
- Getting current date without time
- How can i set an external datetime variable to the current time?
- How to initialize extern datetime with current time?
Chrissayman:
I'm trying to get my EA to run only during certain hours.. I am comparing time current with an assigned date time variable.. it seems to be a logical way.. but I'm having trouble with the date part of it.. is there a way to return current date with a set time to a datetime variable..
I'm trying to get my EA to run only during certain hours.. I am comparing time current with an assigned date time variable.. it seems to be a logical way.. but I'm having trouble with the date part of it.. is there a way to return current date with a set time to a datetime variable..
Or if there is any other way you can recommend to accomplish this..
simple function to access hour in the TimeCurrent():
int hour()
{
MqlDateTime stm;
datetime dt = TimeCurrent(stm);
return stm.hour;
}
Yashar Seyyedin #: simple function to access hour in the TimeCurrent():
int hour(){ return TimeCurrent() / 3600 % 24; }
When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.
See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register