Download MetaTrader 5

Problem CopyTime for other symbols

To add comments, please log in or register
Paladin80 2015.05.11 17:31 

I prepared simple script, which prints the open time of current M1 candles for 3 symbols:

#property strict
void OnStart()
   string   CurrPair[3]={"EURUSD","EURGBP","EURJPY"};
   datetime CurrTime[3];
   datetime TimeArr[1];
   for(int i=0;i<3;i++)
      if(CopyTime(CurrPair[i],PERIOD_M1,0,1,TimeArr)!=1) break;
   for(int i=0;i<3;i++) Print(CurrPair[i],": TimeOpen = ",CurrTime[i]);

I ran it 2 times with different results:

At 18:47:09 (my computer time) the correct result was for EURUSD only, but for other 2 curencies were not (19:44:00, broker's server time, marked red). After 5 seconds, at 18:47:16 (my computer time) open time of M1 candles for all 3 currencies were correct (19:47:00, broker's server time).

Could anyone tell me why it happened and what to do the program copy data for current candle with index [0], not for some previous candle. In general I need to find open price of current candles for several currencies.

Keith Watford
Keith Watford 2015.05.11 21:46  

The time is correct for EURUSD because you attached the script to EURUSD M1 chart and you do not have the other 2 M1 charts opened

When you attach the script the first time, it MT4 starts to update the other 2 values, but returns the non-updated values

The next time you attach the script, the values have updated 

To add comments, please log in or register