Request for Help

unaizams

Newbie
Messages
6
Likes
0
Hi,

Can somebody explain to me what the following block of MQL4 code means and what it does in an expert?

datetime timeprev=0;

//---------------------

if(timeprev==Time[0])
return(0);
timeprev=Time[0];

Thanks.
 
Hi,

This code will execute ALL instructions after return(0); only once per bar, not for every tick like normaly, just once when new candle is formed.

Time[0] - current candle open time.

Code:
// store previous open time
datetime timeprev=0; // global or static variable

// ------------

// check if previous open time is equal to current open time
if(timeprev == Time[0])
{
    // it is equal, so lets skip this tick
    return(0);
}

// not equal? so this mean new candle is formed
// lets save current open time
timeprev=Time[0];

// code to be executed only once per candle
...
 
Top