Download MetaTrader 5
To add comments, please log in or register
How to launch your trading signal and become a provider
mar
1143
mar 2014.07.11 15:27 

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
13610
whroeder1 2014.07.12 13:01  
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
1143
mar 2014.07.12 17:35  
Thank you!!
/
To add comments, please log in or register