Download MetaTrader 5

iTime function in EA make different results

To add comments, please log in or register
Somchai Jaidee
139
Somchai Jaidee  
if(CheckValueTime==iTime(NULL,TimeFrame,0)) return(0);

else CheckValueTime = iTime(NULL,TimeFrame,0);


I got this code from other forum and I have this code in my ea too.

And I got a different results between with and with out this code.

With this code it's can run optimization faster than without.

I am not sure with or without this code that make EA realistic.


Please anyone suggest to me or if anyone has a better like this code I would be appreciate.

Keith Watford
Moderator
9641
Keith Watford  

That code means that any code that follows will only be executed if a new bar opens in the stipulated timeframe.

Obviously a lot quicker than when the full code executes every tick

Somchai Jaidee
139
Somchai Jaidee  

Thank you GumRai.

I got a best result in backtest but bad results in demo.

You make me understand my EA better.


Thank you again.

Keith Watford
Moderator
9641
Keith Watford  

Many strategies, such as MA crosses or stochastic/RSI crossing certain levels are coded to only execute when a bar closes (ie new bar opens).

This is to avoid (what some people consider) false signals when a cross happens while the bar is still open, but crosses back before the bar has closed.

Somchai Jaidee
139
Somchai Jaidee  

I wonder why "CheckValueTime" variable remember previous value instant of  reset to zero when EA execute again.

I just declare in normal variable not global variable.

Keith Watford
Moderator
9641
Keith Watford  
prothemeus:

I wonder why "CheckValueTime" variable remember previous value instant of  reset to zero when EA execute again.

I just declare in normal variable not global variable.


If the variable is declared locally and not static, it will not be remembered and the code will not be effective.
To add comments, please log in or register