Error 4806 Requested data not found when CopyBuffer

Luca  

Hi Traders/Devs,

I am trying to create quite a complex indicator that pulls data from the 28 major pairs and I keep getting error 4806 when I try to copy the handle data to the buffer, can you see what is wrong?

Pairs is an array with lists of pairs, in this case I tried to get the RSI value for all the pairs in a recursive manner, that is why I am not defining the handle in the OnInit but I do in the loop. I tried with different indicators and they do the same.

The RSI function is called every tick through the OnCalculate, j is a candle shift

double RSI(string Curr, string& Pairs[],int j){
   double Tot=0;
   for(int i=0;i<ArraySize(Pairs);i++){
      if(Pairs[i]!=NULL){
         int k=j;
         double RSI[];
         SetIndexBuffer(99,RSI,INDICATOR_CALCULATIONS);
         int RSIHandle=iRSI(Pairs[i],Period(),14,PRICE_CLOSE);
         if(RSIHandle==INVALID_HANDLE){
            Print(Pairs[i]," - Handle ",RSIHandle," - RSI Handle not valid - ",GetLastErrorText(GetLastError())," ",GetLastError());
            return NULL;
         }
         int c=NULL;
         c=CopyBuffer(RSIHandle,0,0,k+1,RSI);
         IndicatorRelease(RSIHandle);
         ArraySetAsSeries(RSI,true);
         if(c<0){
            Print(Pairs[i]," - Handle ",RSIHandle," - Error copying indicator data - ",k," - ",c," - ",GetLastErrorText(GetLastError())," - ",GetLastError());
            return NULL;
         }
      }
   }
   return Tot;
}


doesn't matter if I am online or offline, market open or closed, the log shows that many pairs don't load the data,

I also see in the CopyBuffer documentation (https://www.mql5.com/en/docs/series/copybuffer)that 

When requesting data from the indicator, if requested timeseries are not yet built or they need to be downloaded from the server, the function will immediately return -1, but the process of downloading/building will be initiated.

When requesting data from an Expert Advisor or script, downloading from the server will be initiated, if  the terminal does not have these data locally, or building of a required timeseries will start, if data can be built from the local history but they are not ready yet. The function will return the amount of data that will be ready by the moment of timeout expiration.


PN      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   EURAUD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
MR      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   EURGBP - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
DE      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   AUDUSD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
EI      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   AUDJPY - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
DM      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
HP      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   AUDNZD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
PE      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
GI      0       22:29:36.147    MQL5TEST (AUDCAD,M15)   AUDCHF - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
DM      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   EURAUD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
IQ      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   EURGBP - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
PD      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   AUDUSD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
QH      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   AUDJPY - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
PL      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
LQ      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   AUDNZD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
DD      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
KH      0       22:29:36.196    MQL5TEST (AUDCAD,M15)   AUDCHF - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
IL      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   EURAUD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
DP      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   EURGBP - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
MS      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   AUDUSD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
LG      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   AUDJPY - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
MK      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
QN      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   AUDNZD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
IS      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
RG      0       22:29:36.238    MQL5TEST (AUDCAD,M15)   AUDCHF - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
RK      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   EURAUD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
KO      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   EURGBP - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
FR      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   AUDUSD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
CF      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   AUDJPY - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
FJ      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
JO      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   AUDNZD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
RR      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   AUDCAD - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
IF      0       22:29:36.246    MQL5TEST (AUDCAD,M15)   AUDCHF - Handle 10 - Error copying indicator data - 0 - -1 - Requested data not found - 4806
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Counting of elements of copied data (indicator buffer with the index buffer_num) from the starting position is performed from the present to the past, i.e., starting position of 0 means the current bar (indicator value for the current bar). When copying the yet unknown amount of data, it is recommended to use a dynamic array as a buffer[]...
Luca  
Alain Verleyen:
Always the same question and issue, did you make a search on the forum before asking ? No you didn't.

Hi Alain, 

I could make a post with all the articles I browsed about my search on "4806 error" and "Requested data not found" and still not an answer, lot of unanswered and unresolved issues and posts just abandoned because people gave up.

But if you could point me in the right direction that would be appreciated. Thanks

Alain Verleyen  
Luca:

Hi Alain, 

I could make a post with all the articles I browsed about my search on "4806 error" and "Requested data not found" and still not an answer, lot of unanswered and unresolved issues and posts just abandoned because people gave up.

But if you could point me in the right direction that would be appreciated. Thanks

Yeah. You didn't search very well in this case.

You have 2 main issues :

1° You initialize the indicator (create the handle) and on the next statement you call CopyBuffer(), that will never work as the indicator need some time to be launched and calculated. You NEED to declare in OnInit(). (Strictly speaking it's not mandatory but it's way simpler when you don't know and understand all the process very clearly).

2° For multi-symbols (and/or multi-timeframes), you can ALWAYS get an error 4806 at some point because MT5 doesn't wait the data to be calculated, so it happens that the data are not ready on other symbols/timeframes. You have to deal with it, the simpler is just return and wait next tick.

Secondary issues :

3° You are using SetIndexBuffer() wrongly, placing it in a loop with constant parameters.

4° Your way to use CopyBuffer() asking 1 candle value at a time is totally inefficient (for the current "live" candle it's ok of course, but for history data it will be very slow).

I am sure 100% these topics have already been discussed and solved, as I myself participated in some of them. One problem is everyone is creating his own topic, instead of using what already exists on the exact same subject, so after 10 years we have dozens of topics, some being useless and the good ones being flooded in the noise.

Luca  
Alain Verleyen:

Yeah. You didn't search very well in this case.

You have 2 main issues :

1° You initialize the indicator (create the handle) and on the next statement you call CopyBuffer(), that will never work as the indicator need some time to be launched and calculated. You NEED to declare in OnInit(). (Strictly speaking it's not mandatory but it's way simpler when you don't know and understand all the process very clearly).

2° For multi-symbols (and/or multi-timeframes), you can ALWAYS get an error 4806 at some point because MT5 doesn't wait the data to be calculated, so it happens that the data are not ready on other symbols/timeframes. You have to deal with it, the simpler is just return and wait next tick.

Secondary issues :

3° You are using SetIndexBuffer() wrongly, placing it in a loop with constant parameters.

4° Your way to use CopyBuffer() asking 1 candle value at a time is totally inefficient (for the current "live" candle it's ok of course, but for history data it will be very slow).

I am sure 100% these topics have already been discussed and solved, as I myself participated in some of them. One problem is everyone is creating his own topic, instead of using what already exists on the exact same subject, so after 10 years we have dozens of topics, some being useless and the good ones being flooded in the noise.


Thank you Alain, I did really search and could find some generic answer but not very specific. I also found this that clarifies better the process and error  https://www.mql5.com/en/docs/series/timeseries_acces

I knew it is better to declare the handles in OnInit and I wanted to design it that way but at the same time I wanted to be able to loop with the handles, do you have any suggestion on how to do that? For example a matrix of handles, basically I need to have ready some indicators for each of the 28 pairs, I am building a custom currency strength...

I didn't really want to set a buffer in the loop, also because it is only an intermediary value in my algorithm, I did it because I wanted to iterate the array as a series

I see what you mean, you see only part of the code, in the real algo the logic would be to copy buffer all the uncalculated values in the first run and then only update with the last value, I think that's how it should be?

Alain Verleyen  
Luca:


Thank you Alain, I did really search and could find some generic answer but not very specific. I also found this that clarifies better the process and error  https://www.mql5.com/en/docs/series/timeseries_acces

I knew it is better to declare the handles in OnInit and I wanted to design it that way but at the same time I wanted to be able to loop with the handles, do you have any suggestion on how to do that? For example a matrix of handles, basically I need to have ready some indicators for each of the 28 pairs, I am building a custom currency strength...

Yes put the handles in an array.

I didn't really want to set a buffer in the loop, also because it is only an intermediary value in my algorithm, I did it because I wanted to iterate the array as a series

I see what you mean, you see only part of the code, in the real algo the logic would be to copy buffer all the uncalculated values in the first run and then only update with the last value, I think that's how it should be?

Yes.

Luca  
Alain Verleyen:
Yes put the handles in an array.

Yes.

Thank you, I resolved my issue changing the design withe the following logic:

  1. Moved handle declaration in a function that I call in the OnInit
  2. 28 Handles, one for each of the 28 major pairs, are saved in an array so I can use loops on them
  3. Removed the SetIndexBuffer for the array as it is only an intermediary value, it is still set as Series though
  4. Defined a data matrix [][28] to store the values of the RSI for the 28 time series
  5. Called the CopyBuffer recursively leveraging the data matrix and handles array
  6. Used the CopyBuffer for an arbitrary number of candles in the first instance and then only for the last candle
  7. Managed the error 4806, which still happens sporadically, so that if that occurs the data for that candle will be recalculated at the next tick
Thank you for the suggestions
Alain Verleyen  
Luca:

Thank you, I resolved my issue changing the design withe the following logic:

  1. Moved handle declaration in a function that I call in the OnInit
  2. 28 Handles, one for each of the 28 major pairs, are saved in an array so I can use loops on them
  3. Removed the SetIndexBuffer for the array as it is only an intermediary value, it is still set as Series though
  4. Defined a data matrix [][28] to store the values of the RSI for the 28 time series
  5. Called the CopyBuffer recursively leveraging the data matrix and handles array
  6. Used the CopyBuffer for an arbitrary number of candles in the first instance and then only for the last candle
  7. Managed the error 4806, which still happens sporadically, so that if that occurs the data for that candle will be recalculated at the next tick
Thank you for the suggestions
Great :-)
Botrous Thrwat  
Alain Verleyen #:

Yeah. You didn't search very well in this case.

You have 2 main issues :

1° You initialize the indicator (create the handle) and on the next statement you call CopyBuffer(), that will never work as the indicator need some time to be launched and calculated. You NEED to declare in OnInit(). (Strictly speaking it's not mandatory but it's way simpler when you don't know and understand all the process very clearly).

2° For multi-symbols (and/or multi-timeframes), you can ALWAYS get an error 4806 at some point because MT5 doesn't wait the data to be calculated, so it happens that the data are not ready on other symbols/timeframes. You have to deal with it, the simpler is just return and wait next tick.

Secondary issues :

3° You are using SetIndexBuffer() wrongly, placing it in a loop with constant parameters.

4° Your way to use CopyBuffer() asking 1 candle value at a time is totally inefficient (for the current "live" candle it's ok of course, but for history data it will be very slow).

I am sure 100% these topics have already been discussed and solved, as I myself participated in some of them. One problem is everyone is creating his own topic, instead of using what already exists on the exact same subject, so after 10 years we have dozens of topics, some being useless and the good ones being flooded in the noise.


Thank you very very much for that info .... i already did tens of searches and i can't find one answer that collect the problems with suggestions like this ..

Thank you again sir for your answer and your help .

FahadTech  
Alain Verleyen #:

Yeah. You didn't search very well in this case.

You have 2 main issues :

1° You initialize the indicator (create the handle) and on the next statement you call CopyBuffer(), that will never work as the indicator need some time to be launched and calculated. You NEED to declare in OnInit(). (Strictly speaking it's not mandatory but it's way simpler when you don't know and understand all the process very clearly).

2° For multi-symbols (and/or multi-timeframes), you can ALWAYS get an error 4806 at some point because MT5 doesn't wait the data to be calculated, so it happens that the data are not ready on other symbols/timeframes. You have to deal with it, the simpler is just return and wait next tick.

Secondary issues :

3° You are using SetIndexBuffer() wrongly, placing it in a loop with constant parameters.

4° Your way to use CopyBuffer() asking 1 candle value at a time is totally inefficient (for the current "live" candle it's ok of course, but for history data it will be very slow).

I am sure 100% these topics have already been discussed and solved, as I myself participated in some of them. One problem is everyone is creating his own topic, instead of using what already exists on the exact same subject, so after 10 years we have dozens of topics, some being useless and the good ones being flooded in the noise.

Thanks, your input is appreciated.

Very important thing I understood by the info given is that in MT5, handled indicators and coded script are running side by side independently and that sometimes the handled indicator's data lags from the main script and you get a 4806. Explains why this error doesn't recur regularly.
Belpu Prajwal Rao  
Alain Verleyen #:

Yeah. You didn't search very well in this case.

You have 2 main issues :

1° You initialize the indicator (create the handle) and on the next statement you call CopyBuffer(), that will never work as the indicator need some time to be launched and calculated. You NEED to declare in OnInit(). (Strictly speaking it's not mandatory but it's way simpler when you don't know and understand all the process very clearly).

2° For multi-symbols (and/or multi-timeframes), you can ALWAYS get an error 4806 at some point because MT5 doesn't wait the data to be calculated, so it happens that the data are not ready on other symbols/timeframes. You have to deal with it, the simpler is just return and wait next tick.

Secondary issues :

3° You are using SetIndexBuffer() wrongly, placing it in a loop with constant parameters.

4° Your way to use CopyBuffer() asking 1 candle value at a time is totally inefficient (for the current "live" candle it's ok of course, but for history data it will be very slow).

I am sure 100% these topics have already been discussed and solved, as I myself participated in some of them. One problem is everyone is creating his own topic, instead of using what already exists on the exact same subject, so after 10 years we have dozens of topics, some being useless and the good ones being flooded in the noise.

Thank you so much. You are like God to me here. This was really helpful. I could not understand why it works sometimes and sometimes doesn't and I was scolding the MT5 creators, how bad the software Devs have been doing. I had a knowledge gap and now I'm able to understand this.