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
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.
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?
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?
Yes.
Yes put the handles in an array.
Yes.
Thank you, I resolved my issue changing the design withe the following logic:
- Moved handle declaration in a function that I call in the OnInit
- 28 Handles, one for each of the 28 major pairs, are saved in an array so I can use loops on them
- Removed the SetIndexBuffer for the array as it is only an intermediary value, it is still set as Series though
- Defined a data matrix [][28] to store the values of the RSI for the 28 time series
- Called the CopyBuffer recursively leveraging the data matrix and handles array
- Used the CopyBuffer for an arbitrary number of candles in the first instance and then only for the last candle
- 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, I resolved my issue changing the design withe the following logic:
- Moved handle declaration in a function that I call in the OnInit
- 28 Handles, one for each of the 28 major pairs, are saved in an array so I can use loops on them
- Removed the SetIndexBuffer for the array as it is only an intermediary value, it is still set as Series though
- Defined a data matrix [][28] to store the values of the RSI for the 28 time series
- Called the CopyBuffer recursively leveraging the data matrix and handles array
- Used the CopyBuffer for an arbitrary number of candles in the first instance and then only for the last candle
- 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
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 .
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.
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.
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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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
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.