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:
int ArrayCopyRates(
MqlRates& rates_array[], // MqlRates array, passed by referencestring symbol=NULL, // symbolint timeframe=0// timeframe
);
# In the first variant of the function it performs the virtual data copying to the array ofMqlRatestype. 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.
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:
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.
//+-----------------------------------------------------------------------------------------------------------------------------+//| METHOD: getBarShift()//+-----------------------------------------------------------------------------------------------------------------------------+int CAccessTimeseries::getBarShift(ENUM_TIMEFRAMES TF,datetime mytime) {
int ret = iBarShift(mSymbol,TF,mytime,false)-1;
if(ret < 0) ret = 0;
if(ret > iBars(mSymbol,TF)) ret = iBars(mSymbol,TF);
for(int j = ret; j < iBars(mSymbol,TF); j++)
if(iTime(mSymbol,TF,j) < mytime) return((j-1 >= 0) ? j-1 : 0);
return(-1);
} // End of method getBarShift()
//+-----------------------------------------------------------------------------------------------------------------------------+//| METHOD: copySeriesTHL()//| APPLICATION: To get synchronized time series Time, High, and Low data//+-----------------------------------------------------------------------------------------------------------------------------+int CAccessTimeseries::copySeriesTHL(ENUM_TIMEFRAMES pTimeFrame,datetime pStartTime,datetime pStopTime,
datetime &pTime[],double &pHigh[],double &pLow[]) {
ulong rates_mask = COPY_RATES_TIME|COPY_RATES_HIGH|COPY_RATES_LOW;
int copiedBars = 0;
int start_pos = getBarShift(pTimeFrame,pStartTime); // Index of Bar on pTimeFrame and at pStartTimeint stop_pos = getBarShift(pTimeFrame,pStopTime); // Index of Bar on pTimeFrame and at pStartTimeint count = start_pos - stop_pos + 1; // Include Index[0] bar in Count
copiedBars = CopySeries(mSymbol,pTimeFrame,start_pos,count,rates_mask,pTime,pHigh,pLow);
return(copiedBars);
} // End of method copySeriesTHL()
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.
//+-----------------------------------------------------------------------------------------------------------------------------+//| METHOD: copySeriesTHL()//| APPLICATION: To get synchronized time series Time, High, and Low data//| Instead of using CopySeries() which uses idxStart and idxStop, we shall used CopyType() with timeStart and timeStop//+-----------------------------------------------------------------------------------------------------------------------------+bool CAccessTimeseries::copySeriesTHL(ENUM_TIMEFRAMES pTimeFrame,datetime pStartTime,datetime pStopTime,
datetime &pTime[],double &pHigh[],double &pLow[],int &pBarsCopied) {
string vMethod = "[" + mSymbol + "," + EnumToString(pTimeFrame) + "] " + __FUNCTION__;
int count = Bars(mSymbol,pTimeFrame,pStartTime,pStopTime); // No of bars between pStartTime and pStopTimeArrayResize(pTime,count); ArrayResize(pHigh,count);
ArrayResize(pLow,count);
if(count <= 0 ||
CopyTime(mSymbol,pTimeFrame,pStartTime,pStopTime,pTime) != count ||
CopyHigh(mSymbol,pTimeFrame,pStartTime,pStopTime,pHigh) != count ||
CopyLow(mSymbol,pTimeFrame,pStartTime,pStopTime,pLow) != count) {
PrintFormat("%s: Error[%i] Copying Time,High and Low data",vMethod,GetLastError());
pBarsCopied = count;
return(false);
}
pBarsCopied = count;
return(true);
} // End of method copySeriesTHL()
We can now track, if bars copied (pBarsCopied) are in sync or bars not copied correctly as method returns true/false.
You should check _LastError for != ERR_SUCCESS as well.
Also you don't need the ArrayResize calls.
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."
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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."