arraycopyrates trouble

 

hello,

I have basically pasted the example in for arraycopyrates and cannot get it to return any bars. What am I doing wrong??

double array1[][6];

error = ArrayCopyRates(array1,"EURUSD", PERIOD_H1);

if(error==-1)

Print("copying rates failed");

else

{

Print("values copied", error);

}

"2011.12.22 18:43:05 Data_Export EURUSD.fxs2,H1: values copied0"

And there is all 0's in the array

.......

I have also tried initializing array 1 with:

double array1[10][6];

and I get the exact same thing. What am I doing wring???

 
Maybe your symbol name for EURUSD is not "EURUSD" . . . or maybe you have no H1 data for EURUSD
 

Try calling GetLastError() and check what the return error code is.

Remember that ArrayCopyRates will not necessarily return data right away. If the data is not already resident in memory, it will return error code 4066 and start the process of downloading the requested data.

ArrayCopyRates is a really complex, messy piece of software, with a lot of undocumented behavior and requirements. For instance, it (supposedly) returns a pointer to where the data is actually stored. However, I have found that the pointer changes every time ArrayCopyRates is called. Saving a local copy in the DLL for later access does not work -- the "pointer" returned by ArrayCopyRates (ACR) is not persistent. To be more exact, the pointer returned by ACR does seem to be persistent across multiple calls of the same indicator in which ACR was called. But if the DLL stores the pointer and then tries to access that array later, access violations may occur even though ACR was not called again and the pointer value was not changed.

 

Buffers are constantly increasing in size as new bars form. Why would you ever expect the pointer to be constant between ticks.

Call ArrayCopyRates once in init. Not every tick in start.

 
WHRoeder:

Buffers are constantly increasing in size as new bars form. Why would you ever expect the pointer to be constant between ticks.

Certainly not on every tick or every new bar. The pointer points to the oldest bar, new bars are appended at the end of the array. It won't reallocate on every new bar, it seems it always allocates sufficiently more than currently needed and if it really must reallocate it will try to keep the old pointer if it can (to avoid copying the memory around) and most often this succeeds.

Of course this is not guaranteed and at some point it might change the pointer without further notice but since it does not cost any noticeable time to always pass the pointer to your dll functions on every call you should just do it. I am using ArrayCopyRates() only once and remember the returned array as a global variable. Then I pass this array to every dll function that needs it. Should the pointer to the underlying memory location ever silently change it will be transparent towards mql4 (the array (now simply pointing to the new location) will still continue to work from within mql4 after such an event) and therefore always passing this array variable to the dll on every call will also always continue to work.

Reason: