Creation date of Indicator

 

Hello,

is it possible to get creation date of a specific indicator (mql5/indicators/<file> ?

This code seems not to work:

  string path=TerminalInfoString(TERMINAL_PATH);

            string fn=StringFormat("%s\\mql5\\indicators\\%s",path,__FILE__);
            StringReplace(fn,".mq5",".ex5");
            
            ResetLastError();                     
            int handle=FileOpen(fn,FILE_READ | FILE_BIN);
            if(handle > 0)
            {
                 datetime dt=(datetime) FileGetInteger(handle,FILE_CREATE_DATE);
                 PrintFormat("created=%s",TimeToString(dt));
            }
            else
            {
                 PrintFormat("le=%d",GetLastError());
            }                
            

__FILE__ is the indicator about which i need creation date info.

Thank you

 
  1. Of course, it fails. Perhaps you should read the manual. File Functions
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  2. You can only open files in MQLx/Files. FileOpen
    For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means, cannot be outside the file sandbox.
  3. string fn=StringFormat("%s\\mql5\\indicators\\%s",path,__FILE__);
    You are trying to open “C:\Users\«user»\AppData\Roaming\MetaQuotes\Terminal\«hex»\MQL4\files\C:\Users\«user»\AppData\Roaming\MetaQuotes\Terminal\«hex»\MQL4\indicators\«filename» ” which, of course, does not exist.

  4. Perhaps you should use the predefine macro __DATETIME__

 
William Roeder:
  1. Of course, it fails. Perhaps you should read the manual. File Functions
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  2. You can only open files in MQLx/Files. FileOpen
  3. You are trying to open “C:\Users\«user»\AppData\Roaming\MetaQuotes\Terminal\«hex»\MQL4\files\C:\Users\«user»\AppData\Roaming\MetaQuotes\Terminal\«hex»\MQL4\indicators\«filename» ” which, of course, does not exist.

  4. Perhaps you should use the predefine macro __DATETIME__

So the short answer is: No (because you can only open files in mql5/files). Thank you for this.


Can not reproduce what you mean in 3.

Full script to demonstrate that your point 3. is not coming from my code:

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
            string path=TerminalInfoString(TERMINAL_PATH);
            string fn=StringFormat("%s\\mql5\\scripts\\%s",path,__FILE__);
            StringReplace(fn,".mq5",".ex5");
            
            PrintFormat("File to open=%s",fn);
            ResetLastError();                     
            int handle=FileOpen(fn,FILE_BIN);
            if(handle > 0)
            {
                 datetime dt=(datetime) FileGetInteger(handle,FILE_CREATE_DATE);
                 PrintFormat("created=%s",TimeToString(dt));
            }
           else
            {
                 PrintFormat("#error: script error. code=%d",GetLastError());
            }              
  }
//+------------------------------------------------------------------+
 

chinaski:

So the short answer is: No (because you can only open files in mql5/files). Thank you for this.


Can not reproduce what you mean in 3.

Full script to demonstrate that your point 3. is not coming from my code:

The answer is yes. It is very possible.


As already stated, use __DATETIME__


 
Dominik Egert:

The answer is yes. It is very possible.


As already stated, use __DATETIME__


Perhaps i need to improve my english, but the answer in 2 was:

"You can only open files in MQLx/Files. FileOpen"

I was not able to open the file at all.  Can't see why changing qualifier to __DATETIME__  should solve it, because

FileGetInteger

is used after FileOpen ?


I'd like to know creating date of an indicator file. So a file outside mqlx/Files.

After my understanding Mr. Roeder said "not possible", you say, "yes, it is very possible".

If you have a working solution for this, i would appreciate a code snippet.

Many thanks.

Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
chinaski:

Perhaps i need to improve my english, but the answer in 2 was:

I was not able to open the file at all.  Can't see why changing qualifier to __DATETIME__  should solve it, because

is used after FileOpen ?


I'd like to know creating date of an indicator file. So a file outside mqlx/Files.

After my understanding Mr. Roeder said "not possible", you say, "yes, it is very possible".

If you have a working solution for this, i would appreciate a code snippet.

Many thanks.

Using __DATETIME__ gives you the creating date of the indicator ex5 (the compilation date/time). Look at the documentation please.

So you don't need to use FileOpen at all, as anyway it's not possible to get information about an ex5 this way.

 
To clarify.

Are you trying to get the date of your! Indicator, or are you trying to get the date of an external, precompiled, as binary provided indicator??

This is very different in approach.

Your code can get that info by utilizing __DATETIME__

An external indicator cannot be read this way.

So, maybe No, maybe Yes...

Clarify your task, please.
 
Dominik Egert:
To clarify.

Are you trying to get the date of your! Indicator, or are you trying to get the date of an external, precompiled, as binary provided indicator??

This is very different in approach.

Your code can get that info by utilizing __DATETIME__

An external indicator cannot be read this way.

So, maybe No, maybe Yes...

Clarify your task, please.

It's clear ;-)

string fn=StringFormat("%s\\mql5\\indicators\\%s",path,__FILE__);
Reason: