Time calculations

 

I have an EA that looks for a signal to buy. When this signal is found it waits for a confirmation that the price is moving in a proftible direction. If the price has not changed in a good direction for a certan amounts of seconds. It signale is discarded. This check is done every tick, but. Im trading in H1 so the signal to buy is recorded for example at 2015.02.21 05:00. 

So to check if the signal is invalid i do a calculation for example one hour.

if( signalTime + 3600 > currentTime)
// signal is invalid

 I have trouble getting the exact time in my ea. I get this message when i do debug prints 

Signal invalid to long time has passed, BidTime (signal recorded time) 2014.08.14 05:00, dueTime 2014.08.14 06:00, currentTime 2014.08.14 05:00

 

As you can see the dueTime is one hour ahead and it still returns true in the if statement. i dont understand why.

 

If i have a function that is running every tick, should it not be showing me different times than whole hours? Why for example am i never getting 05:23 as a time? I use the CopyTime function to record the signalTime. 

What function should i use to get the currentTime, realtime. So that i can follow the price in realtime? I have been using TimeCurrent, and also the MqlTick.Time.

 

Thank you 

 
Please show a comprehensive snippet of your code, otherwise it's impossible to answer you.
 

Hello Alain

Okay, here we go this snipped runs one every bar, that is once every hour at this point

  if(/* ...*/ ) // check for buy signals
      if(/*...*/)  // check for buy signals
      {
       MqlTick last_tick;
       signalToBuy = true;                 // signal is trigged
       SymbolInfoTick(Symbol(),last_tick);  
       buyBid = last_tick.bid; // save the bidthat trigged the signal, for later compareing
       bidTime = last_tick.time; // save the time when the signal was trig
       
       printf("Buysignal @buyBid:%f & @bidTime:%s",buyBid,TimeToString(bidTime));
     }

 Here is the code that runs for ever tick.

 

   SymbolInfoTick(Symbol(),last_tick);      
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); 
   datetime dueTime = buySignalDueTime + bidTime;

      if( signalToBuy ) // buy signal has been trig
      {
         
         if(dueTime > Time[0] )
         {
           double dir = last_tick.bid - buyBid;
           dir = Bid - buyBid;
           double points = dir/Point();
           signalToBuy = false; // signal is due, terminate    
           printf("Signal is due, BidTime:%s, dueTime:%s, curTickTime %s, points: %f", 
                           TimeToString(bidTime),TimeToString(dueTime),TimeToString(Time[0]) ,points );
         }
 
dudknoen:

Hello Alain

Okay, here we go this snipped runs one every bar, that is once every hour at this point

 Here is the code that runs for ever tick.

 

How is initialized Time[0] ?

Anyway your condition should be :

 if(TimeCurrent()>dueTime) // or eventually Time[0]>dueTime

Your logic is reversed.

Reason: