Build 1940 - Bars() returns zero - Error 4401 - Requested history not found

 

I'm currently using build 1940 of Metatrader 5.  

I was having major problems with a custom indicator in some earlier builds due to the Bars() function seeming to 'lock up' for some time, after which it would return zero when there are actually >0 bars on the requested symbol/timeframe.  This issue made my indictor unusable (it worked perfectly in earlier builds).

In Build 1940, I can use the indicator, but I notice that the Bars() function still returns zero many times when it shouldn't.  I know this as I perform a Print (see code below) when this occurs and I see the 'Experts' tab on the platform full of the print messages with an error code ERR_HISTORY_NOT_FOUND - 4401 - Requested history not found.

Eventually, my indictor will stop working completely and I'll have to switch timeframes to get it to work again.  This usually fixes the problem however, some times, the indicator won't start working again for some time, even after repeated timeframe switches.

Does anyone know if this is a known bug or what the status of a fix is?

Many thanks.


The code I use which generates continual prints while my indicator runs.

   //--- check for data
   int BarsMATF = Bars(Symbol(), PTimeframe);
   if (BarsMATF < PPeriod)
   {
      Print("Not enough bars on MA timeframe (",BarsMATF," bars). Error:",GetLastError());
      return(0);
   }
 
AaronJStuart:

I'm currently using build 1940 of Metatrader 5.  

I was having major problems with a custom indicator in some earlier builds due to the Bars() function seeming to 'lock up' for some time, after which it would return zero when there are actually >0 bars on the requested symbol/timeframe.  This issue made my indictor unusable (it worked perfectly in earlier builds).

In Build 1940, I can use the indicator, but I notice that the Bars() function still returns zero many times when it shouldn't.  I know this as I perform a Print (see code below) when this occurs and I see the 'Experts' tab on the platform full of the print messages with an error code ERR_HISTORY_NOT_FOUND - 4401 - Requested history not found.

Eventually, my indictor will stop working completely and I'll have to switch timeframes to get it to work again.  This usually fixes the problem however, some times, the indicator won't start working again for some time, even after repeated timeframe switches.

Does anyone know if this is a known bug or what the status of a fix is?

Many thanks.


The code I use which generates continual prints while my indicator runs.

I have noticed this as well, but I think it happened prior to Build 1940.

In this case, I simply have an infinite loop and keep checking until Bars() doesn't give 0. Note the commented "break" below.

bool isSynchronized = false;
while ( ! isSynchronized && ! IsStopped() )
{
    isSynchronized = true;        // until proven guilty

    // Loop over all symbols
    for ( int j=0; j<NUM_CURRENCIES;j++ )
    {
        if(IsStopped()) return false; //Checking for stop flag

        // https://www.mql5.com/en/docs/series/bars
        // Returns the number of bars count in the history for a specified symbol/period.
        // ERR_HISTORY_NOT_FOUND 4401 Requested history not found
        // not all data may be calculated
        int bars;
        ResetLastError();
        bars=Bars(currency[j].symbol,g_chartTimeFrame);

        // sometimes happens for some reason
        if ( bars == 0 )
        {
            if ( DEBUG ) PrintFormat("[%s] 0 bars for some reason", currency[j].symbol);
            isSynchronized = false;
            //break;
        }

    . . .
 
Anthony Garot:

I have noticed this as well, but I think it happened prior to Build 1940.

In this case, I simply have an infinite loop and keep checking until Bars() doesn't give 0. Note the commented "break" below.

We had a discussion somewhere about that, not ?

It would be nice to know when this error 4401 returns, to be sure it's normal behaviour or potential bug. I don't have much time to investigate for now.

 
Alain Verleyen:

We had a discussion somewhere about that, not ?

It would be nice to know when this error 4401 returns, to be sure it's normal behaviour or potential bug. I don't have much time to investigate for now.

Yes. It was here:

https://www.mql5.com/en/forum/284832/page2#comment_9085219

Our discussion was interleaved within a few other related topics, so it gets sort of messy to read the whole thread.

Anyway, I never was able to sort out why Bars() or BarsCalculated() would sometimes return 0 bars, even when it had already returned a non-zero count within the same loading of the same indicator. So I just ignore it when it happens.

Am I wrong or is it the new mql5 build 1915?
Am I wrong or is it the new mql5 build 1915?
  • 2018.10.20
  • www.mql5.com
It's just a tiny little indicator to check the local existence of the bars that is started on GBPUSD H1 of the MQ-Demo account: this prints: So why...
 
Anthony Garot:

Yes. It was here:

https://www.mql5.com/en/forum/284832/page2#comment_9085219

Our discussion was interleaved within a few other related topics, so it gets sort of messy to read the whole thread.

Anyway, I never was able to sort out why Bars() or BarsCalculated() would sometimes return 0 bars, even when it had already returned a non-zero count within the same loading of the same indicator. So I just ignore it when it happens.

Thanks. We will try to sort it out when I will have some time to invest.
Reason: