- How can i set an external datetime variable to the current time
- How can i set an external datetime variable to the current time?
- datetime question
Hi, is this possible? Really don't want to constantly change every part of the date/time/year/ every time i need a little adjustment. I want the default when I start the EA to be the current datetime. Can anyone help with this? Thanks.
If you want the default to be the current time, why use an external variable?
If it is an extern, you can simply change the value to TimeCurrent() in init, then it will reset every time it is initialized. If you don't want it to reset when changing chart time-frame you will have to set other conditions as well.
extern datetime Next_News=0; : if(TimeCurrent() >= Next_News) ...
//---- input parameters
extern bool Trade_Disabled = true;extern int Slippage = 50;
Hi, thanks guys. Maybe I need to be clearer. So when I run this, I almost always am setting a time very soon in the future. I never want it to actually use the current time, but when I go in to set the variable, I don't want to have to change date/month/hour etc. It's usually just minutes that I want to change. Maybe GumRai provided a solution that would do this, but I don't quite understand it. I am also not sure if it's possible, but I hope so.
An easier option may be to just add a number of minutes to the current time when the EA is initiated
//Globalscope extern int Plus_Minutes=5; datetime Trade_Time; //init Trade_Time=TimeCurrent() + ((Plus_Minutes*60);
Of course this will be reset if you change time-frames or re-initialize for any other reason.
hey... that's a solution I never thought of... I will implement that for now in the absence of the alternative. Thanks GumRai!!
I don't like this as a solution.
My EA takes in 6 times, which is essential for its operation. Each time requires the date as well, so every time I run/test it I have to re-enter all six dates plus the specific times I want.
That's just not on.
So I thought of another solution.
I accept that the date can always be today's date. Get the times in string format (e.g. "13:25"), and then include this function in the program:
datetime TimeOnlyConvert(string usertime) { int vyy=Year(); int vmm=Month(); int vdd=Day(); int vhh=Hour(); int vmi=Minute(); string datestring=IntegerToString(vyy)+"."+IntegerToString(vmm)+"."+IntegerToString(vdd)+" "+usertime; datetime datebuild=StringToTime(datestring); return datebuild; }
Now for every time input (only the time) in text format, you can get an accurate datetime variable to use in the program.
I don't like this as a solution.
My EA takes in 6 times, which is essential for its operation. Each time requires the date as well, so every time I run/test it I have to re-enter all six dates plus the specific times I want.
That's just not on.
So I thought of another solution.
I accept that the date can always be today's date. Get the times in string format (e.g. "13:25"), and then include this function in the program:
Now for every time input (only the time) in text format, you can get an accurate datetime variable to use in the program.
Or much simpler:
datetime dtEvent = StrToTime("13:25"); // Returns the current date with the given time
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use