Download MetaTrader 5
To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
Mark Cornbill
11
Mark Cornbill 2016.02.01 02:11 

Hi Guys

 

I have an EA running but it is evaluating entry conditions every tick, and I simply want it to check only once per minute, preferably at the close of a 1 minute bar.

On reading through the guides I guess this can be done by using OnTimer in place of OnTick, but I'm a little stuck now.

Can anybody help please?  Here is the code I need to replace: 

 

void OnTick()
  {
// Calculate Buy or Sell Signal
   int signal=LongSignal()+ShortSignal();
   processSignal(signal);
  }

 

Thanks in advance. 

Keith Watford
Moderator
7947
Keith Watford 2016.02.01 02:28  

Why not just code it to do the calculations at the open of a new M1 bar?

void OnTick()
  {
   static datetime bar_time=0;
   datetime this_bar_time=iTime(Symbol(),PERIOD_M1,0);
   if(bar_time!=this_bar_time)
     {
      bar_time=this_bar_time;
      // Calculate Buy or Sell Signal
      int signal=LongSignal()+ShortSignal();
      processSignal(signal);
     }
  }

 I don't know that you can get OnTimer to execute exactly at a bar close.

Mark Cornbill
11
Mark Cornbill 2016.02.02 00:34  
GumRai:

Why not just code it to do the calculations at the open of a new M1 bar?

 I don't know that you can get OnTimer to execute exactly at a bar close.

That sounds like an excellent idea, thanks GumRai I'll give it a try!
Mark Cornbill
11
Mark Cornbill 2016.02.02 00:49  
markcornbill:
That sounds like an excellent idea, thanks GumRai I'll give it a try!
That works perfectly. thanks :-)
/
To add comments, please log in or register