Download MetaTrader 5

CopyRates function gives wrong values for datetime

To add comments, please log in or register
Lasith Hettiarachchi
22
Lasith Hettiarachchi  

Hi,

I am trying to update a CSV file with live rates. For this I am using CopyRates function.

I came across this problem while using this function. In brief, the error is CopyRates function's datetime and the rates does not match when the market is closed.

For an example let's say now GMT time is - 2016.06.04 14:03  which means now the market is closed.

   MqlRates rates[];
   CopyRates(Symbol(),PERIOD_M1,0,Bars(symbol,PERIOD_M1),rates);
   ArraySetAsSeries(rates,true);
   MqlRates mostRecent = rates[0];
   MqlRates secondMostRecent = rates[1];
   Print("time= "+ServerTimeToGMTTime(mostRecent.time)+" | open= "+mostRecent.open);
   Print("time= "+ServerTimeToGMTTime(secondMostRecent.time)+" | open= "+secondMostRecent.open);

 If I make a request now using the above code this is the output I get from the CopyRates

 rates[0] -> time= 2016.06.04 14:02:47 | open= 1.13659 which is the open time for the market closed minute 2016.06.03 23:59

 rates[1] -> time= 2016.06.04 14:01:47 | open= 1.1367 which is the open time for the (market closed minute - 1) 2016.06.03 23:58

So as you can see price for the time 2016.06.03 23:58 comes for 2016.06.04 14:01

Any idea what I'm doing wrong here? 

 Thanks in advance...

Lasith Hettiarachchi
22
Lasith Hettiarachchi  
The error was inside the ServerTimeToGMTTime finction. Problem solved
To add comments, please log in or register