When i do a copy rates with start index=0, count=2, then rates seems to be the latest bar as i tested by a small script.
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 ?
if you want your array to be copied from present to the past, you have to explicitly use
It's exactly what is described in MQL5 documentation.
Your problem comes from the indexation of your result array, as Malacarne said you.
don't understand this.
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
After doing that, the MT5 terminal will interprete 0 as the current and, of course, 1 as he oldest bar.
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.