ArrayCopyRates bug - direct subtraction of time values is zero - page 2

 
RaptorUK:
OK, maybe not typecasting . . . maybe a memory issue.


Agree. Because the ACR data structure is a bit of a fudge (making datetime look like doubles), I think the MQL expression parser is getting confused.
 
ydrol:

Agree. Because the ACR data structure is a bit of a fudge (making datetime look like doubles), I think the MQL expression parser is getting confused.
Anyway it's a bug. Did you report it to the Service Desk ?
 
angevoyageur:
Anyway it's a bug. Did you report it to the Service Desk ?

Nope, I have a workaround :) I will next time I find myself logging onto mql5 site..

EDIT: Reported now !

 

Here is the response from the Support Team, no acknowledgement of the bug, and tell me to go learn about doubles! ( not sure why I bothered....)


From Support Team:

Use explicit casting for such cases, try this

int start()
  {
//----
   int fld = 0;
   double a[][6];
   double d1,d2;
   int num = ArrayCopyRates(a,Symbol(),PERIOD_D1);
   Print("We copied "+num+" rates");
   if (num > 1) {
      d1 = a[0][fld];
      d2 = a[num-1][fld];
      Alert("old: "+a[num-1][fld]);
      Alert("new :"+a[0][fld]);
      Alert("diff1 new-old = "+(a[0][fld]*1.0-a[num-1][fld])*1.0);
      Alert("diff2: "+(d1-d2));
   }

   return(0);   
//----
  }
Read also the article Working with Doubles in MQL4
 
ydrol:

Here is the response from the Support Team, no acknowledgement of the bug, and tell me to go learn about doubles! ( not sure why I bothered....)


From Support Team:


Please don't complain, be happy you got a reply
 
And a very quick one too! :)
 
ydrol:

Here is the response from the Support Team, no acknowledgement of the bug, and tell me to go learn about doubles! ( not sure why I bothered....)


From Support Team:


Being serious . . . why do you need to explicitly type cast a double, the array is a double ? to a double ? I guess it's because the array isn't actually a double array but some kind of pointer/redirect to the actual history data and that returns a datetime.

Perhaps the ideal solution to this kind of issue would be to cover this kind of anomaly in the documentation . . . assuming it can't be fixed to work as expected.
 

Thats a strange bug, you shouldnt even need to typecast datetimes to perform calculations on them. Is it bad practice to treat datetimes as integers ?

Alert("Time[0] = ", Time[0]);
Alert("Time[1] = ", Time[1]);
Alert("Time[0] - Time[1] = ", Time[0] - Time[1]);

output:
2013.09.18 20:18:18 test EURUSD,M1: Alert: Time[0] - Time[1] = 60
2013.09.18 20:18:18 test EURUSD,M1: Alert: Time[1] = 1379564220
2013.09.18 20:18:18 test EURUSD,M1: Alert: Time[0] = 1379564280

Now an ArrayCopyRates test

   double array[][6];
   int d1,d2;
   ArrayCopyRates(array,Symbol(),PERIOD_M1);
   
   // check array values
   Alert("array[0][0] = ",array[0][0]);
   Alert("array[1][0] = ",array[1][0]);
   //try to perform subtraction directly on array values
   Alert("array[0][0] - array[0][1] = ",array[0][0] - array[1][0]);
   
   //array values to integers
   d1 = array[0][0];
   d2 = array[1][0];
   //perform subtraction
   Alert("d1 - d2 = ",d1 - d2);

   return(0);

output:

2013.09.18 20:48:36 arraycopyrates test EURUSD,M1: Alert: d1 - d2 = 60 //calculation works fine when values are copied out of the array into integers.


2013.09.18 20:48:36 arraycopyrates test EURUSD,M1: Alert: array[0][0] - array[0][1] = 0 //calculation directly on array values returns zero as reported by ydrol


2013.09.18 20:48:36 arraycopyrates test EURUSD,M1: Alert: array[1][0] = 1379566020
2013.09.18 20:48:36 arraycopyrates test EURUSD,M1: Alert: array[0][0] = 1379566080 // array does contain correct values

 
SDC: you shouldnt even need to typecast datetimes to perform calculations on them. Is it bad practice to treat datetimes as integers ?
Yes it is. They are unsigned integers. As signed integers they have been negative for a while.
Reason: