dealing with ODD or double numbers

 

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?

 

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;
}
 
Use ontimer for a better timer.
 
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.
      :

 
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?
 
Thanks
 
William Roeder:
  1. 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?

I have similar inquiry. I'm a newbie in MQL. I want to get 15m Stochastic value at 1H chart while saving the calculation workload. For this reason, I want to call iStochastic every 15 min to get the closed previous 15m stochastic value.

In this case, does your either #2 or #3 code actually work? I wonder if I can get the the value only when 1st tick of new 15min data is triggered. 

 
caseypark1: I wonder if I can get the the value only when 1st tick of new 15min data is triggered. 
  1. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

  2. Check for a new M15 bar.

    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
              New candle - MQL4 programming forum #3 2014.04.04

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum 2011.05.06