Download MetaTrader 5
To add comments, please log in or register
Subscribe to signals right in MetaTrader. It is easy!
Yochanan Gerbi
519
Yochanan Gerbi 2014.12.09 06:14 

Hello freinds,

I need your help.

I want the EA to check an operation every two minutes.

The simple way is to do:

  if (   TimeMinute(TimeCurrent()) != 2  && TimeMinute(TimeCurrent()) != 4  && TimeMinute(TimeCurrent()) != 6  && TimeMinute(TimeCurrent()) != 8  &&
         TimeMinute(TimeCurrent()) != 10 && TimeMinute(TimeCurrent()) != 12 && TimeMinute(TimeCurrent()) != 14 && TimeMinute(TimeCurrent()) != 16 &&
         TimeMinute(TimeCurrent()) != 18 && TimeMinute(TimeCurrent()) != 20 && TimeMinute(TimeCurrent()) != 22 && TimeMinute(TimeCurrent()) != 24 && 
         TimeMinute(TimeCurrent()) != 26 && TimeMinute(TimeCurrent()) != 28 && TimeMinute(TimeCurrent()) != 32 && TimeMinute(TimeCurrent()) != 34 &&
         TimeMinute(TimeCurrent()) != 36 && TimeMinute(TimeCurrent()) != 38 && TimeMinute(TimeCurrent()) != 40 && TimeMinute(TimeCurrent()) != 42 &&
         TimeMinute(TimeCurrent()) != 44 && TimeMinute(TimeCurrent()) != 46 && TimeMinute(TimeCurrent()) != 48 && TimeMinute(TimeCurrent()) != 50 &&
         TimeMinute(TimeCurrent()) != 52 && TimeMinute(TimeCurrent()) != 54 && TimeMinute(TimeCurrent()) != 56 && TimeMinute(TimeCurrent()) != 58  ) 


Can you think about simpler way to do it?

Edward Hirsch
689
Edward Hirsch 2014.12.09 11:09  

something like this:

#define ODD  1
#define EVEN 0

int PreviousMinute = ODD;

void OnTick() {
   int CurrentMinute = TimeMinute(TimeCurrent()) % 2;
   if ((PreviousMinute == ODD) && (CurrentMinute == EVEN)) {
      // check operation every two minutes
      Alert("Bi-Minute check ",TimeMinute(TimeCurrent()));
   }
   PreviousMinute=CurrentMinute;
}
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.12.09 11:50  
Use ontimer for a better timer.
whroeder1
13644
whroeder1 2014.12.09 13:21  
crossy: I want the EA to check an operation every two minutes.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. While
    if(TimeMinute(TimeCurrent()) % 2 == 0) ...
    would trigger every even minute. You probably only want one trigger per.
  3. What about when there is no ticks during that minute "Free-of-Holes" Charts - MQL4 Articles don't you want to trigger at the next tick?
    static datetime everyTwoMinutes = 0;
    datetime now = TimeCurrent();
    if(now >= everyTwoMinutes){
      everyTwoMinutes = now + 120;              // Every two.
      everyTwoMinutes -= everyTwoMinutes % 120; // Top of the minute.
      :

Yochanan Gerbi
519
Yochanan Gerbi 2014.12.09 14:03  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Whilewould trigger every even minute. You probably only want one trigger per.
  3. What about when there is no ticks during that minute "Free-of-Holes" Charts - MQL4 Articles don't you want to trigger at the next tick?
Yochanan Gerbi
519
Yochanan Gerbi 2014.12.09 14:03  
Thanks
/
To add comments, please log in or register