[SOLVED] Set current date as external variable in MT4 12

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 dateime 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.


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.

initialize variables as

extern datetime StartTime = D;          
extern datetime EndTime = D;            

have you tried searching the existing topics first? i think is answered already

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.

You didn’t try very hard. My first try Search - MQL5.community found (on the first two pages):

1.Why TimeCurrent() doesn’t initialize my external date with current date time ?
2. User Defined Date and Time

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

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

-the second 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 it was already answered and still it takes me 3 minutes.