MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading and Strategy Testing Forum

MultiTimeFrame DeMarkerMultiTimeFrame DeMarker Try product
MultiTimeFrame DeMarker
Author: basisforex
Subscribe to signal
Market Maker
57.19%, 15 325.92 RUR
Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5 Pinbar Detector Indicator
Pinbar Detector
Author: GODZILLA
Screenshot
EURUSD, M15
Demo

// Time

To add comments, please log in or register
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.



How to Develop an Expert Advisor using UML Tools
This article discusses creation of Expert Advisors using the UML graphical language, which is used for visual modeling of object-oriented software systems. The main advantage of this approach is the visualization of the modeling process. The article contains an example that shows modeling of the structure and properties of an Expert Advisor using the Software Ideas Modeler.
balazs321
137
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
344
fireflies 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
287
onlysolo 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
1210
biantoro 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