Help: array out of range, though in do...while loop I have tried to check error and exit - page 4
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I mean ArrayCopyRates. It's always the slowest method (which is logical as it gets all data of a given symbol/period).
This is retrieving 50000 bars on 28 symbols, 1 timeframe, on MT4.
What variant of the function are you talking about?
I'm talking about this function variant:
#
In the first variant of the function it performs the virtual data copying to the array of MqlRates type. It means that if timeseries data has been updated, rates_array[] array always will refer to the actual data.
Judging by your screenshot, you most likely measured the time of the very first function call. The first call always takes a relatively long time. But I neglect this (the very first call), for me it’s like initialization.
Moreover, after the very first call, an error will most likely be generated (unless this chart is opened in another window). After the error, I start waiting 30 seconds for the quotes to load, continuing to call ArrayCopyRates with each tick. During these 30 seconds the advisor will not use quotes.
That's why I neglect the time spent on the first calls. The time spent will become much less after a couple of dozen ticks.
Pay attention to the very first call and to calls starting from tick 17.
The first 17 ticks (in this test), that is, approximately the first 30-45 seconds, are preparation for work. Starting from tick 17, 9 calls to ArrayCopyRates + one call to RefreshRates takes an average of 15 microseconds.
The code looks like this:
Inside ratesMgr.update() there are 9 calls to ArrayCopyRates + a call to RefreshRates (because there are 9 charts in this test). You can see the number of bars on the charts in the error messages before tick #1.
I am writing this because you most likely measured this:
Although the actual time taken will be on average 15 microseconds, not 60000
Will try it and revert.
did you used it?!
as i see your code's problem is running yet!
did you used it?!
as i see your code's problem is running yet!
Hi @Mahdi Ebrahimzadeh
Sorry for my delayed response as was stuck with alternate suggestions on the forum.
I have tried your suggestion now and wooola it seems to working fine. THANKS A TON :)
I would therefore inform the forum to treat this thread as 'resolved'.
I have posted below the code used, which may be useful for other members.
THANKS A TON :)
:) u r welcome,
Hi
I have an update on previously mentioned copySeriesTHL() method. It does not gives correct bars within given startTime and StopTime.
I have revised it to following code, and it seems to be working correctly.
We can now track, if bars copied (pBarsCopied) are in sync or bars not copied correctly as method returns true/false.
Hi
I have an update on previously mentioned copySeriesTHL() method. It does not gives correct bars within given startTime and StopTime.
I have revised it to following code, and it seems to be working correctly.
We can now track, if bars copied (pBarsCopied) are in sync or bars not copied correctly as method returns true/false.
Thanks Dominik.
These are useful suggestions. I will incorporate them.
ArrayResize I have included for the reason "To copy a predetermined amount of data, it is recommended to use a statistically allocated buffer to avoid unnecessary memory reallocation."