Confused over which datetime to use

 

I wrote a program before using hours() & minutes() to find session times.It worked correctly. Now I've a aproblem using th same, and documentation sems to say that it is the time my ea ha been runing. And hours(timecurrent()) & minutes is the one to use. In my program I want to close trades at the close of the bar -10 minutes before. It always closes on the 4 hour interval. No matter which code I use. Im using 4 hour charts. Any help you can give me would be greatly appreciated. Thank-You.

Files:
hltimes1.mq4  11 kb
 
datetime Ten_Min_before_End_Of_Bar = Time[0] + ((Period() * 60) - (10 * 60));
 
deetrader999:
I want to close trades at the close of the bar -10 minutes before.
datetime barStart  = Time[0],
         nextBar   = barStart + Period() * 60,
         closeTime = nextBar - 10 * 60;
if (TimeCurrent() >= closeTime) CloseAllOrders();
 
WHRoeder:
Thank-You both for your reply. That's an awesome answer. But there must have been something wrong with my computer about the two datetime hour codes. They both print out the current time of trade or question. And Hour() does work. All this today I find out. But your answer is very nice and quick. Thank-You very much. Deetrader999
Reason: