Download MetaTrader 5

How to execute an EA every hour?

To add comments, please log in or register
mar
1147
mar  

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];
whroeder1
15576
whroeder1  
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());
mar
1147
mar  
Thank you!!
To add comments, please log in or register