What RefreshRates() updates - page 3

 
Artyom Trishkin:

If you suspect errors in iXXXXX functions, use SymbolInfoXXXXXX functions

Can an example of replacing iXXXXX with SymbolInfoXXXXXX.

 
Mikhail Nazarenko:

My code is similar. Error in OnTick

it should be

If we have the current timeframe M5 we should compare M5 with H1 and M1

The current timeframe M5 is displayed correctly. The problem was with H1 and M1.

I checked on Alpari real EURCHF M5 only instead of Print I drew horizontal bars at each of the levels.

Yes, I did put H1 that way at first, but then decided it would be too rare comparisons. So I changed it to M5.

Mikhail Nazarenko:

May I give you an example of replacing iXXXXXXX by SymbolInfoXXXXXX.

Artyom made a little mistake...

Instead of iClose you can use

int  CopyClose( 
   string           symbol_name,       // имя символа 
   ENUM_TIMEFRAMES  timeframe,         // период 
   int              start_pos,         // откуда начнем  
   int              count,             // сколько копируем 
   double           close_array[]      // массив для копирования цен закрытия 
   );

something like this

double close_M5[];
    CopyClose(_Symbol, PERIOD_M5, 1, 1, close_M5);

This way you can get values of several bars with one move of a magic wand.

The function returns true or false, but I didn't check it in this example. You can guess it yourself...

 
Alexey Viktorov:
Yeah, that's how I first put H1, but then I decided it would be too rare comparisons. So I changed it to M5.

I finished your code there and posted it above. I put your version in mine and the result is the same. There is a mismatch on almost every M5 candle. What are your results?

 
Mikhail Nazarenko:

I finished your code there and posted it above. I put your version in mine and the result is the same. There is a mismatch on almost every M5 candle. What are your results?

Here we need to change

if(NewBar(PERIOD_M5))

to

if(NewBar(PERIOD_H1))
 
Alexey Viktorov:

Here we have to change

to

No, better _Period. Because we will forcibly wait for the zero quotation from H1, while the current period is correctly updated. The data should be received at the first seconds of the hour, not when the hour is updated.

I want to add to the example and check
double close_H1,close_M5,
       close_M1;

/*******************Expert initialization function*******************/
int OnInit()
 {
  return(INIT_SUCCEEDED);
 }/*******************************************************************/

/************************Expert tick function************************/
void OnTick()
 {
  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);
    
    double ARRAY_M1[];
    CopyClose(_Symbol, PERIOD_M1, 1, 1, ARRAY_M1);
    double ARRAY_H1[];
    CopyClose(_Symbol, PERIOD_H1, 1, 1, ARRAY_H1);
    
    if(ARRAY_H1[0] != close_M5)
      Print(ARRAY_H1[0], " CopyClose H1 != M5 ", close_M5);
    if(ARRAY_M1[0] != close_M5)
      Print(ARRAY_M1[0], " CopyClose M1 != M5 ", close_M5);
   
     Comment(
               close_H1, " H1\n",
               close_M1, " M1\n",
               close_M5, " M5\n",
               ARRAY_H1[0], " CopyCloseH1\n",
               ARRAY_M1[0], " CopyCloseM1\n"
            );
         
  }       
 }/******************************************************************/

/**********************Expert OnDeinit function**********************/
void OnDeinit(const int reason)
 {
  Comment("");
 }/******************************************************************/

bool NewBar(ENUM_TIMEFRAMES tf)
  {
   static datetime nt = 0;
   datetime tm = iTime(_Symbol, tf, 0);
   if(tm == 0)
      return false;
   if(tm != nt)
     {
      nt = tm;
      return true;
     }
   return false;
 }/******************************************************************/ 

 
Alexey Viktorov:

Here we have to change

to

The result is the same as with iClose(); iClose and CopyClose seem to take data from the same place.

Документация по MQL5: Доступ к таймсериям и индикаторам / iClose
Документация по MQL5: Доступ к таймсериям и индикаторам / iClose
  • www.mql5.com
iClose - Доступ к таймсериям и индикаторам - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Mikhail Nazarenko:

No, better _Period. Because we will forcibly wait for the zero quotation from H1, while the current period is correctly updated. The data should be received at the first seconds of the hour, not when the hour is updated.

I want to add to the example and check

It seems that you don't understand at all how the function of new bar appearing works.

bool NewBar(ENUM_TIMEFRAMES tf)
  {
   static datetime nt = 0;
   datetime tm = iTime(_Symbol, tf, 0);
   if(tm == 0)
      return false;
   if(tm != nt)
     {
      nt = tm;
      return true;
     }
   return false;
 }/******************************************************************/ 

And consequently.

Mikhail Nazarenko:

The result is the same as when iClose(); iClose and CopyClose seem to take data from the same place.

When receiving bar closure values and\or others from OHLC when a new TIKA value is received, there is always no problem.
 
Alexey Viktorov:

You don't seem to understand how the new bar function works at all.

And consequently.

When getting bar close values and\or others from OHLC when a new TIKA arrives the values are always without problems.

Answer the question. Why on a new candle does the iClose(1) function give back outdated information and not updated or an error? This is a bug.

 
Mikhail Nazarenko:

Answer the question. Why on a new candle does the iClose(1) function return outdated information and not updated or an error? This is a bug.

If it's a bug, then everyone, or almost everyone, should have it. If it is only you, then it is a problem in the code.

I have my EA on M15 with determination of a new bar H1

/************************Expert tick function************************/
void OnTick()
 {
  if(NewBar(PERIOD_H1))
   {
    close_H1 = iClose(_Symbol, PERIOD_H1, 1);
    CopyClose(_Symbol, PERIOD_M5, 1, 1, close_M5);
    close_M1 = iClose(_Symbol, PERIOD_M1, 1);
    if(close_H1 != close_M1)
      Print(close_H1, " != ", close_M1);
   }
  Comment(close_H1, "\n",
          close_M5[0], "\n",
          close_M1, "\n"
         );
 }/******************************************************************/

And this is what the comment says.

There is no discrepancy.

 
OK, thanks to all the developers for their attention, I'm off to create crutches like NewBar.))) Topic closed.
Reason: