Very important bug in MT5

 

Hi,

I've developed a EA on MT5 and I run it on two VPS (same VPS provider, same VPS configuration, same broker, same instrument (DAX)) and I notice some diffence in the entry, that is one EA place the order but the other not.

After some debug I discover that the CopyHigh, CopyClose, CopyOpen, CopyLow function on daily bars fail to give me the right info. In one VPS the result is ok, in the other VPS the result is shifted by one day.

This is the code:


double DayOpen[], DayClose[], DayHigh[], DayLow[];
ArraySetAsSerie(DayOpen,true);
ArraySetAsSerie(DayClose,true);
ArraySetAsSerie(DayHigh,true);
ArraySetAsSerie(DayLow,true);
if (CopyOpen(Symbol(), PERIOD_D1, 0, 7, DayOpen)<7) return false;
if (CopyHigh(Symbol(), PERIOD_D1, 0, 7, DayHigh)<7) return false;
if (CopyLow(Symbol(), PERIOD_D1, 0, 7, DayLow)<7) return false;
if (CopyClose(Symbol(), PERIOD_D1, 0, 7, DayClose)<7) return false;

Randomically happens that the result bar is shifted by one, so DayOpen[1] is not the yesterday bar but the day before yesterday (the same bug affect also the other array and the shift is also for the other elements of the arrays).



 

What MT5 build ? On which timeframe is your code running ?

Can you provide a log showing the values ?

What are the specifications of the VPS where the problem appears ?

 
Did you check others VPS date settings?
 
Alain Verleyen:

What MT5 build ? On which timeframe is your code running ?

Can you provide a log showing the values ?

What are the specifications of the VPS where the problem appears ?

The MT5 Version is 5.0.0 build 1932 - 29 Oct 2018

This is the log that the EA writes showing the OHLC values of the previous days:

(see Selection_263.png)

As you can see, the date of the log is 2018.12.11 and the DAY1 should be the data of the 2018.12.10, that is:

(see Selection_268.png)

Focusing on open price, the value is 10647.63, but the log reports for the DAY1 Open the value of 10927.62 that is the day before yesterday value (2018-12-07 because we have a weekend, but the problem apperars also in a non weekend situation), as you can see:

(see Selection_269.png)

The VPS is a Windows Server  2012 R2 with 4GB RAM and 1 CPU, but the same issue appers on another VPS Windows Server 2008 R2 Datacenter with 2GB Ram and 1 CPU.

The EA is attached on a GER30Cash Symbol on H1 timeframe; my provider is XM.COM.



 

"Bug in MT5"... "Very important"...

Use CopyRates() and copy by time, not by index.

And definitely not in OnInit();

 

My personal opinion:

These functions (CopyOpen, CopyHigh.....) they are slow, unreliable and unpredictable. From time to time they return wrong values (or zero) and no one knows why.  This can cause serious problems (and big losses) in automated systems.

I'm happy that they finally added in MT5 the original functions (iOpen, iHigh...) these are fast and very reliable! (Proven over the last 10+ years) And if needed you can create your own array with them. It works great.

 
kypa:

"Bug in MT5"... "Very important"...

Use CopyRates() and copy by time, not by index.

And definitely not in OnInit();

The Copy function are not in OnInit but on a function called inside the OnTick().

Using the CopyRates() should be a workaround (I'll try) but the bug still remains.

Thanks.

 
Tsvetan Tsvetanov:

My personal opinion:

These functions (CopyOpen, CopyHigh.....) they are slow, unreliable and unpredictable. From time to time they return wrong values (or zero) and no one knows why.  This can cause serious problems (and big losses) in automated systems.

I'm happy that they finally added in MT5 the original functions (iOpen, iHigh...) these are fast and very reliable! (Proven over the last 10+ years) And if needed you can create you own array with them. It works great.

Thanks for the tip! 
 
Francesco Pinta:
Thanks for the tip! 
Tsvetan Tsvetanov:

My personal opinion:

These functions (CopyOpen, CopyHigh.....) they are slow, unreliable and unpredictable. From time to time they return wrong values (or zero) and no one knows why.  This can cause serious problems (and big losses) in automated systems.

I'm happy that they finally added in MT5 the original functions (iOpen, iHigh...) these are fast and very reliable! (Proven over the last 10+ years) And if needed you can create your own array with them. It works great.

The problem appears also using hte iOpen, iHigh, ... functions. Same script, same provider, same instrument, same VPS configuration.

In the Selection_272.png we can view the rollover after the midnight, in the Selection_271.png the DAY0 values remain the same.

Files:
 
Francesco Pinta:

The problem appears also using hte iOpen, iHigh, ... functions. Same script, same provider, same instrument, same VPS configuration.

In the Selection_272.png we can view the rollover after the midnight, in the Selection_271.png the DAY0 values remain the same.

Can you provide a complete testcase code please ? One that I can just compile and run to reproduce your issue.
 

UPDATE:

I've modified the script in order to printing in the debug also the date and time of the bar.

As I guessed, also the time value remains to the old value. In the picture (Selection_273.png), before the 2018.12.17 the DAY0 time is "2018.12.14 00:00" and after midnight, at 2018.12.17, the DAY0 time still remains "2018.12.14 00:00".

Files:
Reason: