MetaTrader 5 Platform update build 3660: Improvements and fixes - page 9

 

One simple script for MT5 b.3744 and four questions & problems:

#define DoWi(t) ((int)(((t-259200)%604800)/86400))       // (int)Day of Week Su=0,Mo=1,...
#define _t2s(t) TimeToString(t,TIME_DATE|TIME_MINUTES)
#define  BoW(t) ((t)-((t-172800)%604800 - 86400))        // Begin of Week.. Su 00:00:00: 604800=168h=7*24; 172800=35.5h; 86400=24h

void OnStart()
  {
//---

   datetime arrTme[],tC = D'2022.02.03 00:00:00';//TimeCurrent();
   datetime tB = BoW(tC) + 300;
   int b = CopyTime("EURUSD",PERIOD_H1,BoW(tB),1,arrTme);
   PrintFormat("%-20s %i %s\n%-20s %i %s\n%-20s %i %s\n%-20s %i %s",
               "timeCurrent:",      DoWi(tC),         _t2s(tC),
               "\nBeg of Week:",    DoWi( (BoW(tC)) ),_t2s(BoW(tC)),
               "\nBoW + 300 Sekt:", DoWi(tB),         _t2s(tB),
               "\narrTme[0]:",      DoWi(arrTme[0]),  _t2s(arrTme[0]));
  }

This is printed:

2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       timeCurrent:         4 2022.02.03 00:00
2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       
2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       Beg of Week:        0 2022.01.30 00:00
2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       
2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       BoW + 300 Sekt:     0 2022.01.30 00:05
2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       
2023.05.24 18:18:33.285 test_CopyTime (EURUSD,H1)       arrTme[0]:          5 2022.01.28 23:00

My questions and problems:

  1. Why is there an extra empty line?
  2. Why is there an additional blank after timeCurrent:?
  3. Why - and this is my main problem - does CopyTime return the time of the previous bar which is the theoretical last bar of Friday (theoretical as the last quotes have the time stamp like 22:59:59)
    instead of the first bar on Sunday/Monday?
    To be save I added 5 minutes but still get something wrong - or am I wrong?
  4. Do we have to check all the other integrated Copy.. functions on a weekend?
Files:
 
Carl Schreiber #:

One simple script for MT5 b.3744 and four questions & problems:

This is printed:

My questions and problems:

  1. Why is there an extra empty line?

Because you added it.

PrintFormat("%-20s %i %s\n%-20s %i %s\n%-20s %i %s\n%-20s %i %s",
               "timeCurrent:",      DoWi(tC),         _t2s(tC),
               "\nBeg of Week:",    DoWi( (BoW(tC)) ),_t2s(BoW(tC)),
               "\nBoW + 300 Sekt:", DoWi(tB),         _t2s(tB),
               "\narrTme[0]:",      DoWi(arrTme[0]),  _t2s(arrTme[0]));

  1. Why is there an additional blank after timeCurrent:?
Same as 1. It was not an additional blank after timeCurrent, but a missing blank for the 3 next ones.


  1. Why - and this is my main problem - does CopyTime return the time of the previous bar which is the theoretical last bar of Friday (theoretical as the last quotes have the time stamp like 22:59:59)
    instead of the first bar on Sunday/Monday?
    To be save I added 5 minutes but still get something wrong - or am I wrong?

Yes you are wrong.

int b = CopyTime("EURUSD",PERIOD_H1,BoW(tB),1,arrTme);

BoW(tB) is D'2022.01.30 00:00:00'. There is no bar at that time, so it returns the time of the previous existing bar. All is good and expected. CopyTime is looking BACK, it will never returns a bar in the future of the start parameter.

As I tried to explain you in your German forum topic, it's important to understand how it works, not how you think it should work.

 

add 1: Ok my bad - now I see it, sorry.
           Funny feature if I eliminate the "\n" at "\nBeg..", "\nBoW..", ... the additional blank in the first line disappears?
add 2: This part: "%-20s %i %s" is for every 'line' the same so there is 1 and only 1 blank between '...20s' and '%i' - so where is the additional blank, Alain?

 
Alain Verleyen #:

Because you added it.

Same as 1. It was not an additional blank after timeCurrent, but a missing blank for the 3 next ones.

Yes you are wrong.

BoW(tB) is D'2022.01.30 00:00:00'. There is no bar at that time, so it returns the time of the previous existing bar. All is good and expected. CopyTime is looking BACK, it will never returns a bar in the future of the start parameter.

As I tried to explain you in your German forum topic, it's important to understand how it works, not how you think it should work.

Am I? D'2022.02.03 00:00:00' is a valid h1 bar, it has quotes:


The next one to the left is (Fr.) 5 2022.01.28 23:00 from above.

 
Carl Schreiber #:

add 1: Ok my bad - now I see it, sorry.
           Funny feature if I eliminate the "\n" at "\nBeg..", "\nBoW..", ... the additional blank in the first line disappears?
add 2: This part: "%-20s %i %s" is for every 'line' the same so there is 1 and only 1 blank between '...20s' and '%i' - so where is the additional blank, Alain?

I already answered :

It was not an additional blank after timeCurrent, but a missing blank for the 3 next ones.

The "\n" was "eaten" as a character.

 
Carl Schreiber #:

Am I? D'2022.02.03 00:00:00' is a valid h1 bar, it has quotes:


The next one to the left is (Fr.) 5 2022.01.28 23:00 from above.

Yes you are. You starting date in CopyTime is not D'2022.02.03 00:00:00, it's D'2022.01.30 00:00:00'.
 
Alain Verleyen #:
Yes you are. You starting date in CopyTime is not D'2022.02.03 00:00:00, it's D'2022.01.30 00:00:00'.

Yes, you are right, my bad again, I need to take the cucumber slices off my eyes.
Thank you!

 

It wasn't my bad. MQ must have changed something, as previously CopyTime didn't had a problem with server times of the future e.g. to place objects on the chart for the next day ...

Now this fails and CopyTime returns the last known server time :(

This is quite inconvenient, because CopyTime returns the last opening time of a bar before a price gap such as a weekend, but the first opening time after such a gap can then only be determined by trial and error. This now makes it much more difficult to automatically determine the broker's offset time.

Files:
 

I found something strange in the latest update, now the backtest is slower and the backtest results can only be 32%, even though before I was able to get 100% real tick history. I don't know what was changed, but it seems to concern the history data.

beforeupdate afterupdate

 
Sugianto #:

I found something strange in the latest update, now the backtest is slower and the backtest results can only be 32%, even though before I was able to get 100% real tick history. I don't know what was changed, but it seems to concern the history data.

There are no differences in the pictures.

Reason: