Download MetaTrader 5

Time

To add comments, please log in or register
Order the development and track its status via your mobile phone.
Abraham
74
Abraham 2011.09.04 07:25 

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
168
balazs321 2011.09.04 10:24  

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
74
Abraham 2011.09.04 11:11  

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 2011.09.04 12:08  
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
74
Abraham 2011.09.04 13:21  
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 2012.08.13 10:50  
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
14613
Biantoro Kunarto 2012.08.17 07:10  
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