How to execute an EA every hour?

 

Hello Forum,

usually I use the following code to avoid the execution of my EA on every tick because I calculate with closed bars:

void OnTick()
  {
   static datetime Time0;
   if (Time0 == Time[0]) return;
   Time0 = Time[0];

But now I want the EA to be executed once an hour. Is this code correct?

void OnTick()
  {
   static datetime Time0;
   if (TimeHour(Time0) == TimeHour(TimeCurrent())) return;
   Time0 = Time[0];
 
mar: Is this code correct?
  1. That fails on H4 and higher TF charts. You'd need:
    Time0 = TimeCurrent(); //Time[0];

  2. or the slightly more efficient:
    static int Hour0;
    if (Hour0 == TimeHour(TimeCurrent())) return;
    Hour0 = TimeHour(TimeCurrent());
 
Thank you!!