How can I force the expert wait two candles, Then call the Function.

 
Hi
How can I force the expert wait two candles, Then call the Function.

I checked the closing price of two candles 1 and 2, then I want expert wait for two Candle Appear then check the closing price of candles x and x 1.

Candle X And X+1 Still Not Exist(I Attached an Image)

if(Bid<=downvalue)
   {
        if(Close[1]>Close[2])
        {
         Print("true 100%");

                if(Open[x+1]>Close[x])  //I Want Expert Wait Here For two Candle Appear, Then do this Command
                {
                Comment(Close[2]);
                }
        }
  }

I Found NewBar() Function that force expert to run only on each new bar and found WaitXBars() Function that force expert to wait x bars.

but not working. maybe I should use another method.

int WaitXBars = 3;
datetime NotBefore = TimeCurrent()+WaitXBars*_Period*60; // to wait x bars
...
if (TimeCurrent()<NotBefore) return; // to skip.. 



=============================



bool NewBar()
  {
   static datetime time=0;
   if(time==0)
     {
      time=Time[0];
      return false;
     }
   if(time!=Time[0])
     {
      time=Time[0];
      return true;
     }
   return false;
  }
Files:
x.jpg  56 kb
 
v mail: How can I force the expert wait two candles, Then call the Function.
static datetime waiting;
if(condition){ waiting=TimeCurrent(); return; }
if(iBarShift(_Symbol, _period, waiting) == 2) Function();
Is that so hard you couldn't attempt it?
 
v mail:

I wrote this simple code with your function to see that the expert waits as long as two candlesticks but it did not work

if(Open[1]<=Open[2] || Open[1]>=Open[2] )

How can this ever be anything but true?

 
v mail: in my code first if run without problem and i want 2candle wait for run second if but second if never run
      waiting=TimeCurrent(); return;
      if(iBarShift(_Symbol,PERIOD_CURRENT, waiting) == 2) 

            {
             Comment(Close[2]);
            }
     }

Of course, it never runs — no code ever will after the return.

 
int num=0;
⋮
     num++;     
     if(num==0)
If it is initially zero and you increment it, when will that test ever be true?
 
William Roeder:
If it is initially zero and you increment it, when will that test ever be true?

thank you

I wrote code below and it's working.

int num=0;
⋮
     num++;     
     if(num==1){num++; waiting=Time[0]; return;}
     if(iBarShift(_Symbol,PERIOD_CURRENT, waiting) == 2) 

      
Reason: