Download MetaTrader 5

Time

To add comments, please log in or register
Abraham
89
Abraham  

hi,

I want to initiate an action dependent on tiem and it is driving me crazy... how do I do it?

For example:

if(time()=="1200") { x=1;}

Can somebody tell me the correct format please and save me from my headache?

Thanks in advance.

balazs321
169
balazs321  

if(Timecurrent() == "0000.00.00. 00:00:00") { }

 Or you can use MqlDate, like

MqlDate mydate;
int hours = mydate.hour;

Or something like that, look it in the documentation :) 

Abraham
89
Abraham  

Thanks... the problem is that the documentation is very bare on this subject and I am not an expert in C++. Also all the examples provided in MQL5 are regarding printing the time, not using it as a variable. I tried this:

if(datetime Timecurrent() == "2011.09.02 12:00:00") {GraphBuffer[i]=1; } else {GraphBuffer[i]=2;}

and the error was 'Timecurrent' - class type expected

However I don't want the effect for a specific day, I would like it for ANY day. Pleeeease somebody explain why I can't write:

if(datetime Timecurrent() == "12:00:00") {GraphBuffer[i]=1; } else {GraphBuffer[i]=2;}

Can I write something like this without the date?

Jimmy
490
Jimmy  
Abraham:

Thanks... the problem is that the documentation is very bare on this subject and I am not an expert in C++. Also all the examples provided in MQL5 are regarding printing the time, not using it as a variable. I tried this:

if(datetime Timecurrent() == "2011.09.02 12:00:00") {GraphBuffer[i]=1; } else {GraphBuffer[i]=2;}

and the error was 'Timecurrent' - class type expected

However I don't want the effect for a specific day, I would like it for ANY day. Pleeeease somebody explain why I can't write:

if(datetime Timecurrent() == "12:00:00") {GraphBuffer[i]=1; } else {GraphBuffer[i]=2;}

Can I write something like this without the date

#define ONEDAY  86400

#define NOON    43200

if( TimeCurrent() % ONEDAY > NOON ) {

    // do stuff when it is afternoon

}

else {

  // do stuff when it is before noon

}



Abraham
89
Abraham  
fireflies:

#define ONEDAY  86400

#define NOON    43200

if( TimeCurrent() % ONEDAY > NOON ) {

    // do stuff when it is afternoon

}

else {

  // do stuff when it is before noon

}



thanks very much fireflies, you are officially a life saver
kaloian kaloianov
445
kaloian kaloianov  
Abraham:
thanks very much fireflies, you are officially a life saver

excuse me what means the % sign? i cant find it in the documentation, thanks.

 

 

if( TimeCurrent() % ONEDAY > NOON ) { 

Biantoro Kunarto
17042
Biantoro Kunarto  
onlysolo:

excuse me what means the % sign? i cant find it in the documentation, thanks.

 

 

if( TimeCurrent() % ONEDAY > NOON ) { 

You can find in the documentation. Language Basics-Operations and Expressions-Arithmetic Operations :

It means divisions reminder, example : minutes = time % 60;


To add comments, please log in or register