What RefreshRates() updates - page 2

 
iClose: zero - error. The function does not give an error. It gives a value which is currently obsolete.
 
I read here that " iClose() gets the value from broker's server" If the data of these functions is generated by honest brokers, then everything falls into place.))) It turns out we can only trust the current tick.
 
Artyom Trishkin:
No, it is not. What is written in the function help about the return value?
iClose

Returned value

Value of bar close price (specified by shift parameter) of the corresponding chart or 0 in case of error. Call GetLastError() to get more information about the error.

It says that if it's not 0, then there's no error. But the value doesn't change either..., so it doesn't update without RefreshRates();, which surprised me.
 
Mikhail Nazarenko:

And if you change the timeframe to a different one than the current one, the data will not update in time even with RefreshRates(). So the fundamental functions of iClose etc. in MT4 produce irrelevant bullshit. I'm sure that 80% of the infos do not take into account these unique features of MT4. How to live?)))

Changing the timeframe will not do anything. The current iClose value is equal to the Bid value regardless of the chart period.
 
Alexey Viktorov:
The change off will not give anything. The current value of iClose equals the Bid value regardless of the chart period.

I have made an EA and run it on M5 for a day. At the hour change it draws horizontal lines for each of the values: iClose(symbol,PERIOD_H1,1),iClose(symbol, PERIOD_ M5,1), iClose(symbol, PERIOD_ M1,1 ),Close[1],Bid

  1. iClose(symbol, PERIOD_ M5,1 ),Close[1] - it showed exactly as on the chart
  2. Bid was close, this is the next tick
  3. iClose(symbol,PERIOD_H1,1),iClose(symbol, PERIOD_ M1,1) - sometimes they were the same, and sometimes, especially in the evening hours, they showed a complete shit, even after RefreshRates() was connected.

Question to the developers. Why do we need theiClose function in MQL4, if it doesn't give the correct information and there is no way to update its data?

 
Mikhail Nazarenko:

I have made an EA and run it on M5 for a day. At the hour change it draws horizontal lines for each of the values: iClose(symbol,PERIOD_H1,1),iClose(symbol, PERIOD_ M5,1), iClose(symbol, PERIOD_ M1,1 ),Close[1],Bid

  1. iClose(symbol, PERIOD_ M5,1 ),Close[1] - it showed exactly as on the chart
  2. Bid was close, this is the next tick
  3. iClose(symbol,PERIOD_H1,1),iClose(symbol, PERIOD_ M1,1) - sometimes they were the same, and sometimes, especially in the evening hours, they showed a complete shit, even after RefreshRates() was connected.

Question to the developers. Why do MQL4 neediClose functions, if they don't give reliable information and there is no way to update their data?

This is nonsense. The RefreshRates() call is necessary only if the execution was delayed for any reason. Such cases as long cycle or just updating prices at the moment of sending an order to open an order. There should not be any problems in your variant. Better post an example of code that gets price values so wrong.

I'm running the following code now

double close_H1,
       close_M1;

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

/************************Expert tick function************************/
void OnTick()
 {
  if(NewBar(PERIOD_M5))
   {
    close_H1 = iClose(_Symbol, PERIOD_M5, 1);
    close_M1 = iClose(_Symbol, PERIOD_M1, 1);
    if(close_H1 != close_M1)
      Print(close_H1, " != ", close_M1);
   }
  Comment(close_H1, "\n",
          close_M1, "\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;
 }/******************************************************************/
In fact, the minute closure should coincide with any high period on the chart. I will check later to see if there is anything written in the log.
 
Mikhail Nazarenko:

And if you change the timeframe to a different one from the current one, the data will stop updating in time, even with RefreshRates().

Is there any test code to confirm this statement? I haven't noticed it myself. When switching TF, we simply wait for history to be swapped and then work.


So, iClose and other fundamental functions in MT4 produce irrelevant nonsense.

This is too loud an assertion. Sometimes it's possible, but that's what error codes are for. If you don't check them you will never know if you can use the result you get.


I'm sure that 80% of infoproducts do not take into account these unique features of MT4. How to live?)))

I will say more: almost all programs do not take these features into account. That is why their new versions are released. As soon as a product is no longer supported, it is rendered unusable.

Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений
Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений
  • www.mql5.com
Коды ошибок и предупреждений - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Viktorov:

This is nonsense. It is only necessary to call RefreshRates() if there has been a delay in execution for whatever reason. Cases like a long cycle or just updating prices at the time of sending an order to open an order. There should not be any problems in your variant. Better post an example of code that gets price values so wrong.

I am running such code now

In essence the minute close should coincide with any high period on the chart. Later I will see if there is anything written in the log.

My code is similar to this one. There is an error in OnTick.

close_H1 = iClose(_Symbol, PERIOD_M5, 1);

It should be

close_H1 = iClose(_Symbol, PERIOD_H1, 1);
close_M5 = Close[1];
 if(close_H1 != close_M5)
	 Print(close_H1, " != ", close_M5);
if(close_M1 != close_M5)
	 Print(close_M1, " != ", close_M5);


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 it on Alpari real EURCHF M5, but instead of Print I drew horizontal bars at each of the levels.

 
Ihor Herasko:

Is there any test code to support this statement? I haven't noticed this with myself. When switching TFs, we just wait for the history to swap and then work.


This is too loud a statement. In some cases this is possible, but that's what the error codes are for. If you don't check them, you will never know if you can use the result you get.


Let me say more: almost all programs don't take something into account. That's why their new versions are released. As soon as a product is no longer supported, it is incapable of being used.

Here's the code, put it in and check it out. I don't have a match on every candle. Alpari real EURCHF M5.

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);
   
     Comment(
               close_H1, " H1\n",
               close_M1, " M1\n",
               close_M5, " M5\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;
 }/******************************************************************/

 
Mikhail Nazarenko:
iClose: zero - error. The function does not report an error. Outputs a value which is currently obsolete.

If you suspect errors in the iXXXXXXX functions, use the SymbolInfoXXXXXX functions

Reason: