Replace OnTick for every minute (OnTimer...?)

Back to topics list To post a new topic, please log in or register
avatar
3
markcornbill 2016.02.01 03: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. 

avatar
Moderator
3413
GumRai 2016.02.01 03: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.

avatar
3
markcornbill 2016.02.02 01: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!
avatar
3
markcornbill 2016.02.02 01:49 #
 
markcornbill:
That sounds like an excellent idea, thanks GumRai I'll give it a try!
That works perfectly. thanks :-)
Back to topics list  

To add comments, please log in or register