Download MetaTrader 5
To add comments, please log in or register
What is a social trading? Read the article to find that out!
bunnycat
75
bunnycat 2015.04.12 21:15 
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.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.04.13 04:13  
Show us your code. Use SRC (besides video icon) when posting codes.
Keith Watford
Moderator
7984
Keith Watford 2015.04.13 05:29  
bunnycat:
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. 

whroeder1
13641
whroeder1 2015.04.13 12:20  
If you want the extern to specify a time, but use current time if not specified, use zero and test for it.
extern datetime Next_News=0;
:
if(TimeCurrent() >= Next_News) ...
bunnycat
75
bunnycat 2015.04.15 00:37  

//---- input parameters 

extern bool       Trade_Disabled = true;
extern datetime   Trade_Time = D'2014.06.01 00:00';
extern bool       Close_Disabled = true;
extern datetime   Close_Time = D'2014.06.01 00:00';
extern ENUM_ORDER_TYPE  Type = 0;
extern double     Lots=1.0;
extern bool       Use_Max_Lots = false;
extern double  Max_Lots_Offset = 0.01;
extern int        TP = 0;

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. 

Keith Watford
Moderator
7984
Keith Watford 2015.04.15 01:08  

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.

bunnycat
75
bunnycat 2015.04.15 01:11  
hey... that's a solution I never thought of...  I will implement that for now in the absence of the alternative.  Thanks GumRai!!
Nathan5
7
Nathan5 2016.01.20 12:40  
bunnycat:
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.

/
To add comments, please log in or register