What RefreshRates() updates - page 7

 
Mikhail Nazarenko:

Thanks, that's spot on. Does the terminal really give a 4066 error after accessing an unupdated timeseries via iTime? I've encountered iClose giving unupdated information instead of zero.

That's the thing, that's the key point that's causing your hitch.

Error 4066 - when there is no history for this TF, it is not ready, you need to contact the server.

And when you already have it, but it is updated only when you access it, ie, does not give an error, just give you what is now, and simultaneously with the request begins to update the time-series.

If you access it infrequently and irregularly, sometimes you get old stuff. If you request each necessary TF regularly, up to each tick - then everything is OK.

If the chart of this TF is open, it is regularly updated on the chart. By the way, it is probably possible to open charts of all necessary TFs from EAs, if the access is not regular, but it is unreliable, because they can close/change TFs manually.

 
Evgeniy Chumakov:


Why add 0 to [i + 0] ?

instead of zero I substituted 1 and 2, 1 or 2. I left 0, i.e. 1 bar. I haven't cleaned up the code, it's not important for logic.

 
Aleksey Mavrin:

That's the point, it's the key point that's causing you to get stuck.

Error 4066 is when there is no history for this TF, it is not ready, you need to contact the server.

And when you already have it, but it is updated only when you access it, ie, does not give an error, just give you what is now, and simultaneously with the request begins to update the time-series.

If you access it infrequently and irregularly, sometimes you get old stuff. If you request each necessary TF regularly, up to each tick - then everything is OK.

If the chart of this TF is open, it is regularly updated on the chart. By the way, it is probably possible to open charts of all necessary TFs from EAs, if access is not regular, but it is not reliable, because they can close/change TFs manually.

When there should be an error it gives back the old data, great. This is one of the reasons why brokers love MT4 and do not switch to MT5)).

I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?

 
Mikhail Nazarenko:

When it should get an error it gives back the old data, great. This is one of the reasons why brokers like MT4 and do not switch to MT5)).

I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?

Almost. Here is a ready function:

bool IsTFDataReady(ENUM_TIMEFRAMES eTF)
{
   ResetLastError();
   iTime(NULL, eTF, 1);
   return GetLastError() == ERR_NO_ERROR;
}
Insert it in OnTick() and, if it returns true, the eTF timeframe can be accessed, the data is valid.
 
Mikhail Nazarenko:

When there should be an error it gives back the old data, great. This is one of the reasons why brokers like MT4 and do not switch to MT5)).

I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?

Of course, it is better to use sleep only in OnInit, and it is necessary only in indicators. In other cases, OnTick, as Igor mentioned above, is enough.

Depending on the task, you can manoeuvre your way to the best option. Usually, when checking if there is a new bar, iTime is already accessed on every tick for all used timeframes, which is enough to keep them up to date.

s.w. And if you use Igor's function not on every tick, but on some rare conditions, there will also be a lag.
Основы тестирования в MetaTrader 5
Основы тестирования в MetaTrader 5
  • www.mql5.com
В чем различия между тремя режимами тестирования в MetaTrader 5 и на что обратить внимание? Как происходит тестирование эксперта, торгующего одновременно на нескольких инструментах? Когда и как вычисляются значения индикаторов при тестировании и как обрабатываются события? Как синхронизировать бары с разных инструментов при тестировании в режиме "Только цены открытия"? Статья призвана дать ответы на эти и многие другие вопросы.
 
Aleksey Mavrin:

sleep is better used only in OnInit, of course, and it is only needed in the indicators. In other cases, it is enough to use OnTick, as Igor mentioned above.

Depending on the task, you can manoeuvre your way to the best option. Usually, when checking if there is a new bar, iTime is called at every tick for all used timeframes, it is enough to keep them up to date.

s.e. And if Igor's function is used not on every tick, but on some rare conditions, it will also be out of sync.

Sleep does not work in indicators

 
Ihor Herasko:

Almost. Here's a ready-made function:

Insert it in OnTick() and if it returns true, you can access the eTF timeframe, data is valid.

It's brilliantly simple. Thank you. Why don't the developers describe this in the manual on the iClose functions etc?Or correct the logic of MT4 quote updates so as not to create conspiracy theories.

 
Mikhail Nazarenko:

When there should be an error it gives back the old data, great. This is one of the reasons why brokers like MT4 and do not switch to MT5)).

I.e. ask for the correct timeframe every tick or sleep, until the error 4066. Did I get it right?

In MT5 it is much more difficult.

In F4 it is enough to request iTime from all used TFs every 2 minutes, and all data will be actual.

 
Mikhail Nazarenko:

Everything is brilliantly simple. Thank you. Why don't the developers describe this in the manual on iClose functions and so on?Or correct the logic of MT4 quote updates so as not to create conspiracy theories.

Because almost all EAs do checks for the right conditions on every tick and everything updates by itself.

 
Vitaly Muzichenko:

Sleep does not work in indicators

It works if you really need it :)

void SleepA(int msec)
 {
   uint now=GetTickCount();
   while (GetTickCount()<(now+msec))
      {
      for(int i=0;i<10000;i++)
         {
          double f=1;
          f*=f;
          f+=f;
         }
       }
   return;
 }  
Andrey Khatimlianskii:

In MT5 it is much more complicated.

In 4 it is enough to request iTime from all used TFs every 2 minutes, and all data will be actual.

Exactly