# CopyRates problem

890
2014.08.18 03:13

When i do a copy rates with start index=0, count=2, then rates[1] seems to be the latest bar as i tested by a small script.

```void test2(void)
{
MqlRates                                        rates[];
int copied=CopyRates(Symbol(),Period(),0,2,rates);
if(copied > 0)
{
for(int i=0;i < copied;++i)
{
Print(StringFormat("%d o=%.8f c=%.8f %s",i,rates[i].open,rates[i].close,TimeToString(rates[i].time)));

}
}

}```

This is the contrary to what i read in the MQL5 Help:

"The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar."

According my test, the current bar is stored in 1 not in 0.

Can anyone confirm this ?

Moderator
9892
2014.08.18 05:56

When i do a copy rates with start index=0, count=2, then rates[1] seems to be the latest bar as i tested by a small script.

This is the contrary to what i read in the MQL5 Help:

"The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar."

According my test, the current bar is stored in 1 not in 0.

Can anyone confirm this ?

if you want your array to be copied from present to the past, you have to explicitly use

`ArraySetAsSeries(rates,true);`
Moderator
30723
2014.08.18 09:55

When i do a copy rates with start index=0, count=2, then rates[1] seems to be the latest bar as i tested by a small script.

This is the contrary to what i read in the MQL5 Help:

"The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar."

According my test, the current bar is stored in 1 not in 0.

Can anyone confirm this ?

It's exactly what is described in MQL5 documentation.

Your problem comes from the indexation of your result array, as Malacarne said you.

890
2014.08.18 16:21

Hello Angevoyageur,

don't understand this.

From Doc:

"The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar."

So according what Documentation says: 0 in the target array (ordering of the copied data) is current bar but it is NOT.

1 is the index of the current bar.

So, i mean, without using

`ArraySetAsSeries`

it should carry the current bar in index=0 and not in index=1.

Moderator
9892
2014.08.18 16:47

Hello Angevoyageur,

don't understand this.

From Doc:

"The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar."

So according what Documentation says: 0 in the target array (ordering of the copied data) is current bar but it is NOT.

1 is the index of the current bar.

So, i mean, without using

it should carry the current bar in index=0 and not in index=1.

you are copying 2 bars of data. In this case, the standard indexation of bars in C++ (and MQL5) is to set 0 as the oldest bar and 1 as the current bar.

If you want to invert the indexation, you have to use

`ArraySetAsSeries(rates,true);`

After doing that, the MT5 terminal will interprete 0 as the current and, of course, 1 as he oldest bar.

Moderator
30723
2014.08.18 18:29

Hello Angevoyageur,

don't understand this.

From Doc:

"The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar."

So according what Documentation says: 0 in the target array (ordering of the copied data) is current bar but it is NOT.

1 is the index of the current bar.

So, i mean, without using

it should carry the current bar in index=0 and not in index=1.

You misunderstood the documentation. It means the source data are always copied from present to past, BUT you are accessing the target array and there it depends of the indexation. See explanation of Malacarne above.

890
2014.08.18 21:51
ok, seems to be so.