I just cannot get this figured out!

 

I have written an EA and it seemed to work just fine until i noticed some wrong trades when tested or run on a demo account. I have put a delay on the next transaction after one has been executed by using a variable int HoursDelay. The value of this variable is set as HoursDelay = 4.

The variables I calculate in the code keeps on giving zero values which I think is impossible. Here is an extract of some of the code:

input int      HoursDelay = 4;

int         BuyTransTimeRT;
int         SellTransTimeRT;
int         BuyTransTimeRS;
int         SellTransTimeRS;

BuyTransTimeRS = TransHour + HoursDelay;
if(BuyTransTimeRS > 24) BuyTransTimeRS = BuyTransTimeRS - 24;

And here is what is reported in the Journal:

 

Is there anybody willing to help me out there? I will greatly appreciate it!

Thanking you in advance!

 

What is TransHour?

Show the code that Prints to the log.

 
Keith Watford:

What is TransHour?

Show the code that Prints to the log.

TransHour = TimeHour(TimeCurrent());

Print("TransHour is ", TransHour, " BuyTransTimeRS is ", BuyTransTimeRS, " SellTransTimeRS is ",SellTransTimeRS);
 
BuyTransTimeRS = TransHour + HoursDelay;
if(BuyTransTimeRS > 24) BuyTransTimeRS = BuyTransTimeRS - 24;

You want a delay. Time does not go backwards.

static datetime BuyDelay = date() + (TransHour + HoursDelay) * 3600; // \ Or perhaps: TimeCurrent() + HoursDelay * 3600
⋮                                                                    // / set when order opens.
if(TimeCurrent() < BuyDelay) return;
          Find bar of the same time one day ago - MQL4 programming forum
 
William Roeder:

You want a delay. Time does not go backwards.

          Find bar of the same time one day ago - MQL4 programming forum

What would we have done without you William? You have been helping programmers over many many years. Know from me that it is greatly appreciated! I will certainly follow your advice and hopefully my problems will be resolved. Thank you again!

Reason: