[SOLVED] Set current date as external variable in MT4

 

Hi everyone, I have a problem with my mt4 EA.

Basically it's designed to trade within a time window set by the user at startup (extern).


extern datetime StartTime;          
extern datetime EndTime;          
bool IsTradingTime = false;
//-----------------------------------
if (TimeLocal() >= StartTime && TimeLocal() < EndTime) IsTradingTime = true;
else IsTradingTime = false;
 


if I don't initialize my datetime variables they will be set by default to 0 (therefore 1/1/1970) and to set the correct day I have to click on "today" and do it manually.


screenshot


Here comes the question: is there any method to automatically change the value of Start and End time to current date instead of having 1970.01.01?

I already tried setting extern datetime StartTime = TimeLocal() but it doesn't work since the EA has to be initialized to read TimeLocal(), therefore it happens after EA's inputs are prompted.

Many thanks in advance to those who will help


Solution:

initialize variables as

extern datetime StartTime = D'';          //Start Time
extern datetime EndTime = D'';            //End Time
 Many thanks to  Alain Verleyen
 
nikoldrini: is there any method to automatically change the value of Start and End time to current date instead of having 1970.01.01?
If you had used this you would have found the answer is no.
 
whroeder1:
If you had used this you would have found the answer is no.

I might be new to this particular forum but I know how to search for similar topics or google before posting.

I read the rules before opening a new topic and I did it because I didn't find the answer for my specific problem anywhere else and to know if someone has found a workaround even outside metatrader environment.

I think this is the purpose of a community built around a specific programming language.

 
nikoldrini: t because I didn't find the answer for my specific problem anywhere else
You didn't try very hard. My first try Search - MQL5.community found (on the first two pages):
  1. Set current date as external variable in MT4
  2. Why TimeCurrent() doesn't initialize my external date with current date time ?
  3. User Defined Date and Time
 

you are good in searching but a bit less in reading the contents:

-first one is my topic

-second one is almost unanswered and only talks about external variables and their use, but not how to make them acquire informations from outside

-the third one is a not sure answer

I found these topics before posting but the answer didn't satisfy me as I think there may be a way through dll files etc. Maybe I'm not the first one having this problem and maybe someone has already solved it or will in the future.

I'm willing to learn from more experienced and skilled developers, I'm not willing to get trolled. Thank you very much

 

You are both right. No need for a dispute about that, the search engine is not always easy to found a relevant topic.

Here is the one https://www.mql5.com/en/forum/156393

I found it because I knew a already answered and still it takes me 3 minutes.
How to initialize extern datetime with current time?
How to initialize extern datetime with current time?
  • 2015.07.30
  • www.mql5.com
Hy guys... There is a way to initialize an external datetime variable with the current time...
 
Alain Verleyen:

You are both right. No need for a dispute about that, the search engine is not always easy to found a relevant topic.

Here is the one https://www.mql5.com/en/forum/156393

I found it because I knew a already answered and still it takes me 3 minutes.


You're a mod... Is there anything you can do about the bot account that goes by the name wheoeder1 that's constantly replying with repetitive and often hostile remarks?
 
nicholishen:


You're a mod... Is there anything you can do about the bot account that goes by the name wheoeder1 that's constantly replying with repetitive and often hostile remarks?
No, but against provocateur yes.
 
Alain Verleyen:
No, but against provocateur yes.


So is there strategy to be as rude as possible to encourage newbies to use freelance service instead of learning mql? Because this is generally the rudest "help" forum I've ever had the pleasure of visiting.
 
nicholishen:


So is there strategy to be as rude as possible to encourage newbies to use freelance service instead of learning mql? Because this is generally the rudest "help" forum I've ever had the pleasure of visiting.

I do agree the rudest without any doubt. We all have to deal with people we don't like or understand, that's life. 

WHRoeder is not using freelance service (AFAIK) and has helped more people alone than all other users together.

 
Alain Verleyen:

I do agree the rudest without any doubt. We all have to deal with people we don't like or understand, that's life. 

WHRoeder is not using freelance service (AFAIK) and has helped more people alone than all other users together.

I wasn't just referring to that user

Reason: