Download MetaTrader 5
To add comments, please log in or register
You don't know MQL5 but you do know how to sell? The affiliate program is at your service!
filipefr
58
filipefr 2015.01.25 00:22 

I created a script to write a file with some fields, and one of them is TimeCurrent(). But the problem is that it is returning to me a number that I cannot translate to date in other programs (e.g. R, Excel, Calc OpenOffice).

 This a sample of the numbers that it returns:

1422013200
1422013801
1422014100
1422014401
1422014701

 

And these are some outputs from Google Spreadsheets and Open Office. Neither of them represent the true date which shoud been (jan,21,15 or jan,20,15) 

Google Spreadsheet date format

1/1/1970
1/1/1970
1/1/1970
1/1/1970
1/1/1970

Calc Open Office date format

11/25/15
07/18/17
05/13/18
03/10/19
01/04/20

 This is my code: 

if (OrderSelect(tkt, SELECT_BY_TICKET) == true) {
          filehandle=FileOpen("opens.csv",FILE_CSV|FILE_READ|FILE_WRITE, ";");
          if(filehandle!=INVALID_HANDLE)
          {
            if(FileSeek(filehandle, 0, SEEK_END)) {
              
              Print("appending to file");
              
              FileWrite(filehandle,
              ticket,
              TimeCurrent(),
              MagicNumber,
              OrderType(),
              Symbol(),
              OrderOpenPrice(),
              EnumToString(ENUM_TIMEFRAMES(_Period)));
              
              FileClose(filehandle);
              data_return=1;
                               
            }
          }
Keith Watford
Moderator
7875
Keith Watford 2015.01.25 01:30  
filipefr:

I created a script to write a file with some fields, and one of them is TimeCurrent(). But the problem is that it is returning to me a number that I cannot translate to date in other programs (e.g. R, Excel, Calc OpenOffice).

 This a sample of the numbers that it returns:

 

1422013200
1422013801
1422014100
1422014401
1422014701

 

I think that you are probably looking at the value for ticket here, not TimeCurrent()
filipefr
58
filipefr 2015.01.25 02:12  

This is the list of fields in my file:

2009475830      1422015001      12345   1       EURUSD  1.12239 PERIOD_M5
2009476703      1422015300      12345   1       EURUSD  1.12336 PERIOD_M5
2009477514      1422015610      12345   1       EURUSD  1.12341 PERIOD_M5

 

 From my code, timecurrent() should be the second column, right? 

Keith Watford
Moderator
7875
Keith Watford 2015.01.25 05:35  

My Excel is quite old now so not sure if there is a difference with newer versions.

But your code that you posted will not separate the data into different columns.

It will if you change the delimiter to a "," 

filehandle=FileOpen("opens.csv",FILE_CSV|FILE_READ|FILE_WRITE, ",");

Also, TimeCurrent()is output to file as a string, not a number , so how is it appearing in your file as a number?

It should be output as  2015.01.23 12:10:01

 

This makes me think that the code that you have posted is not the code that you have used.

Alain Verleyen
Moderator
28520
Alain Verleyen 2015.01.25 12:02  
GumRai:

My Excel is quite old now so not sure if there is a difference with newer versions.

But your code that you posted will not separate the data into different columns.

It will if you change the delimiter to a ","

Doesn't matter, it depends of regional settings.

Also, TimeCurrent()is output to file as a string, not a number , so how is it appearing in your file as a number?

It should be output as  2015.01.23 12:10:01

Remove #property strict, and it will write a number. Which is also the answer to OP question
whroeder1
13597
whroeder1 2015.01.25 14:16  

filipefr: I created a script to write a file with some fields, and one of them is TimeCurrent(). But the problem is that it is returning to me a number that I cannot translate to date in other programs (e.g. R, Excel, Calc OpenOffice).

This a sample of the numbers that it returns:

1422013200
1422013801
1422014100
1422014401
1422014701
  1. 1422014100 is Fri, 23 Jan 2015 11:55:00 GMT according to Online Conversion - Unix time conversion
  2. So stop outputting a number. Convert the datetime to a string that the other programs can read.
Keith Watford
Moderator
7875
Keith Watford 2015.01.25 20:06  
angevoyageur:

Remove #property strict, and it will write a number. Which is also the answer to OP question


Yet another example of the documentation being incomplete!

Numbers of the datetime type are displayed as "YYYY.MM.DD HH:MI:SS". 

Nowhere does it state that it will display a number if #property strict is removed. 

Alain Verleyen
Moderator
28520
Alain Verleyen 2015.01.25 21:37  
GumRai:

Yet another example of the documentation being incomplete!

Numbers of the datetime type are displayed as "YYYY.MM.DD HH:MI:SS". 

Nowhere does it state that it will display a number if #property strict is removed. 

You are certainly right about the documentation, but this is how datetime where "displayed" before build 6xx, and not using #property strict means you will use the "old" compiler.

/
To add comments, please log in or register