What RefreshRates() updates - page 4

 
Mikhail Nazarenko:
Okay, thanks to all developers for attention, I will create crutches like NewBar))) Topic closed.

You don't need to create them. I gave you a fully working function. Use it.

 

Here comes a new hour...


The values are one and the same...

 
Mikhail Nazarenko:

No, better _Period. Because we will forcibly wait for the zero quotation from H1, while the current period is correctly updated. It is necessary to get the data at the first seconds of the hour, not when the hour is updated.

if(NewBar(PERIOD_M5))
   {
    close_H1 = iClose(_Symbol, PERIOD_H1, 1);
    close_M1 = iClose(_Symbol, PERIOD_M1, 1);
    close_M5 = Close[1];
    
    
    if(close_H1 != close_M5)
      Print(close_H1, " H1 != M5 ", close_M5);
    if(close_M1 != close_M5)
      Print(close_M1, " M1 != M5 ", close_M5);

//...

I want to add to the example and check


I don't understand why you expect to see the same close price in completely different bars?

When there is a new bar on M5, on M1 there is also a new bar, but on H1 only in one case out of 12 there will be a new bar and in the other 11 there will be no bar.

 
PapaYozh:

I don't understand why. you expect to see the same closing price on completely different bars?


Noticed that too, thought I had it wrong.

 

Apparently I don't explain the problem very well, sorry. I wrote and tried the promised crutches. I wrote it here because it should be implemented in the code of MQL4. If you are interested, please take it. The topic is now closed.

//Функция отслеживания появления обновленных котировок по таймфрейму, где max_tf таймфрейм +1 до которого включительно будет требоваться обновление
bool isRefresh(int max_tf = 0,int min_sleep = 1000){
   
   //Массив с таймфреймами
   int tf[9] = {1,5,15,30,60,240,1440,10080,43200};
   
   //Если максимальное 0 то текущее значение
   max_tf = (max_tf <= 0) ? _Period : max_tf;
   
   //Текущее время
   datetime period,tc = TimeCurrent();
   
   for(int i = 0; i < 9; i++){
         
      period = tf[i]*60;
      
      if(iTime(_Symbol,tf[i],1) != (int(tc/period)-1)*period){
         Sleep(min_sleep);
         return false;   
      }
      if(max_tf < tf[i])//Если таймфрейм больше максимального и тоже обновлен то выходим
         break;
   }
   Sleep(min_sleep);
   RefreshRates();
   
   return true;
}
 
Mikhail Nazarenko:

Apparently I don't explain the problem very well, sorry. I wrote and tested the promised crutches. I wrote it here because it should be implemented in the code of MQL4. If you are interested, please take it. The topic is now closed.

1. Perhaps, yes.

2. Why sleep a second before returning from a function if it has no effect on the returned result?

 

For candlesticks from other periods/symbols to be generated in time, they need to be constantly "pulled", otherwise the MT updates them "as they have to".
It's a truism, it's been discussed many times on the forum)

ps. If your code runs on timer and accesses quotes for other timeframes only once per hour (or once per day), then you need to create a separate function for update. Or wait a couple of seconds after the next request.

 
PapaYozh:

1. Apparently, yes.

2. Why sleep a second before returning from a function, if the returned result is not affected in any way?

This is all by experience. If you don't believe me, remake it and don't sleep). The whole thing is voluntary.

 

It's ***there in its purest form.

Why sleep in a function when you can come back from it and do something useful?

 
PapaYozh:

It's ***there in its purest form.

Why sleep in a function when you can come back from it and do something useful?

It's ***t pure and simple. Tell me what you didn't understand in my previous reply? One more time. Don't sleep and do something useful.))