Can someone say why the compiler doesn't think these arrays are the right type for CopySeries?

 

On top of it all, the statements were working fine when I was asking just for close price. As soon as I added time, it started throwing up.

1005   double daNowPrce[]; 
1006   datetime dtaNowPrce[]; 
1007   ResetLastError();
1008
1009   double dNowPrce                        =  0;
1010
1011   int iBarIXSrs                          = iBarRegSeriesFlip(piBarIX,ArraySize(dbMA_PME));
1012   int iNowPrceCNTSrs                     = CopySeries(sSymb,IeTF,iBarIXSrs,1,COPY_RATES_CLOSE|COPY_RATES_TIME,daNowPrce,dtaNowPrce);
1013   double dPrcSRS                         = daNowPrce[0]; 
1014   int iNowPrceCNTReg                     = CopySeries(sSymb,IeTF,piBarIX,1,COPY_RATES_CLOSE|COPY_RATES_TIME,daNowPrce,dtaNowPrce);
1015   double dPrcReg                         = daNowPrce[0]; 

Compiler:

invalid array type, expected 'double' or 'float' type   MA Crossover MJM.mq5    1012    112
invalid array type, expected 'datetime' or 'long' type  MA Crossover MJM.mq5    1012    122
invalid array type, expected 'double' or 'float' type   MA Crossover MJM.mq5    1014    110
invalid array type, expected 'datetime' or 'long' type  MA Crossover MJM.mq5    1014    120

I added Time (exact copy of OnCalulate's "time[]") so that I can figure out why CopySeries is giving me recent prices for USDJPY when I'm currently processing the way far back in history portion of the data series.

iBarRegSeriesFlip simply "flips" a given index value from regular to reverse-indexed "series" and back each time it's called, based on the current size of the array being indexed. So, I wanted to try CopySeries both ways to confirm my hunch.

 

Why not add two lines instead:

   CopySeries(sSymb,IeTF,iBarIXSrs,1,COPY_RATES_CLOSE,prices_buf);
   CopySeries(sSymb,IeTF,iBarIXSrs,1,COPY_RATES_TIME,time_buf);


another thing to try is to switch the order order of the arrays:

CopySeries(sSymb,IeTF,iBarIXSrs,1,COPY_RATES_TIME|COPY_RATES_CLOSE,dtaNowPrce,daNowPrce);
 

The arrays must be passed in the order of the MqlRates structure:


struct MqlRates 
  { 
   datetime time;         // period start time 
   double   open;         // open price 
   double   high;         // high price for the period 
   double   low;          // low price for the period 
   double   close;        // close price 
   long     tick_volume;  // tick volume 
   int      spread;       // spread 
   long     real_volume;  // exchange volume 
  }

Per the documentationThe order of the arrays passed to the function must match the order of the fields in the MqlRates structure.


From what I can see, daNowPrce is of type double, while dtaNowPrce is of tipe datetime. However, the datetime array must be passed first. Invert the order they're passed to CopySeries and it should be good.

Documentation on MQL5: Timeseries and Indicators Access / CopySeries
Documentation on MQL5: Timeseries and Indicators Access / CopySeries
  • www.mql5.com
Gets the synchronized timeseries from the MqlRates structure for the specified symbol-period and the specified amount. The data is received into...
 
Emanuel Cavalcante Amorim Filho #:
The order of the arrays passed to the function must match the order of the fields in the MqlRates structure.

Another OMG! And now I remember reading that, but I'd totally forgotten. 

Another one solved by Mr. Filho!

Thanks so much, man!

Reason: