The attached shows the close bar shows 1.10374 for the second last candle. Assuming based on the code is states that it is the current bar but the previous bar or none of the others close by seem to have a closing price of 1.10397.This is on metatrader 5.
My question is, is this a code issue or a data issue with my mt5? I had issues with this the last couple days which i thought i resolved by resizing the arrays. This is also making my back test inaccurate/ I'd like to also add when testing on real data it does the same thing where the current bar shows the previous closing price and the previous bar shows the current closing price.
The area below shows the section of code, I have back tested on visual and have the print statements showing the incorrect price but now stumped, any help would be much appreciated:
MqlRates rates[];
// Get the rates
int copiedRates = CopyRates(Symbol(), PERIOD_H4, 0, 2, rates);
if(copiedRates < 2)
{
Print("CopyRates failed, error = ", GetLastError());
return;
}
else
{
Print("Copied ", copiedRates, " rates.");
}
// Resize the arrays
ArrayResize(rates, 2);
//Then somewhere down the line
// Print an error message
Print("CopyBuffer failed, error = ", GetLastError());
}
//Test - Print the bar time
Print("Current bar time: ", TimeToString(rates[0].time));
Print("Previous bar time: ", TimeToString(rates[1].time));
// Print the closing prices for the current and previous bars
Print("Current bar closing price: ", rates[0].close);
Print("Previous bar closing price: ", rates[1].close);
I pasted print statements showing the opening time and price and they are both consistently wrong. I am drawing out the rates[0] and rates[1] for now to see if the data works but obviously it does not show the correct open/close pricing.