Order at the opening of a new bar

 
I am trying to place an order exactly at the opening of a new 1-hour bar. The only way I thought of this in EA is:
if(iTime(NULL,PERIOD_H1,0) == iTime(NULL,PERIOD_M1,0))
then send the order.

any other accurate way to this? (also, the Tester cannot work with this method, so a method that the Tester can understand woudl be helpful).
 
No , there is exist more properly way - compare Time of current bar. For example:
bool NewBar=false;
....
if (currOpenTime!=Time[0])
{
currOpenTime=Time[0];
NewBar=true;
}
if (NewBar) 
{
///  check conditions for opening new position and OrderSend() if it needed
}
 
Thanks a lot. this seems very good.

what is the difference between Time[] and iTime() ?
as I understood from the doc, Time[0] = iTime(NULL,0,0), am I right?
 
You're welcome.
Yes, you are right. See documentation https://docs.mql4.com/series/iTime
 
lalilo:
Thanks a lot. this seems very good.

what is the difference between Time[] and iTime() ?
as I understood from the doc, Time[0] = iTime(NULL,0,0), am I right?


I need some help with the iTime function. I am very new to this but need to collaborate with someone on getting some code done....any takers?

D

Reason: