FrameAdd using data file

 

Hello all,

According to the MQL5 Official Documentation, the FrameAdd function can be called using two different sets of parameters.

The second one is actually easy to handle, as passing the data to an array is quite simple.

However, I'm interested in the first method, where, according to the Docs, it would be possible to pass optimization data to a data file.

I couldn't find neither in the Docs nor in the MQL5.com English Forum any single reference of how to use this function through a data file.

In the case, I would like to know three things:

1) which kind of file (format) should be used (maybe .CSV?). 

2) would it be possible to store and recall string values?

3) how exactly could this function be called and the data file be restored, once we don't have inside FrameNext the possibility to use data files?

Thanks in advance for any help!

Malacarne

Documentation on MQL5: Working with Optimization Results / FrameAdd
Documentation on MQL5: Working with Optimization Results / FrameAdd
  • www.mql5.com
Working with Optimization Results / FrameAdd - Reference on algorithmic/automated trading language for MetaTrader 5
 

1) which kind of file (format) should be used (maybe .CSV?).

Any file, a file is a file.

2) would it be possible to store and recall string values?

You can use any data.

3) how exactly could this function be called and the data file be restored, once we don't have inside FrameNext the possibility to use data files?

You create a file.

FrameAdd() call send the file in MQL5\Files (related to your terminal, in case you are using external agents).

TesterPass event is generated and OnTesterPass() handler called. Here you just have to open the file with FileOpen() and read your data.

 
Alain Verleyen:
Any file, a file is a file.
You can use any data.

You create a file.

FrameAdd() call send the file in MQL5\Files (related to your terminal, in case you are using external agents).

TesterPass event is generated and OnTesterPass() handler called. Here you just have to open the file with FileOpen() and read your data.

Hi Alain,

I'm not sure about what you posted... You can try yourself... try, for instance, to add a simple string array to FrameAdd:

//---
string data[2];
data[0] = "test_0";
data[1] = "test_1";

//---
FrameAdd("stats",1,0,data);

Then you get an error message:

'data' - string arrays and structures containing objects are not allowed

That's why I'm trying to export string values to a data file. However, when you use, for instance, 

if(!FrameAdd("stats",1,0,"datafile.csv"))
  {
   Print("Error while loading data file");
  }

it fails somehow while loading the data file.

Regarding the third question, I would like to be able to import the optimization data using dataframes, as I would like to be able to sepparate data for each pass. And this cannot be done if I export everything to the same file, as I cannot get the pass id inside the optimization itself. 

So I think the 3 questions above are still open... :-)

Regards,
Malacarne

 
Rodrigo Malacarne:

Hi Alain,

I'm not sure about what you posted... You can try yourself... try, for instance, to add a simple string array to FrameAdd:

//---
string data[2];
data[0] = "test_0";
data[1] = "test_1";

//---
FrameAdd("stats",1,0,data);

Then you get an error message:

'data' - string arrays and structures containing objects are not allowed

Yes I was talking about what can be passed inside a file. Sorry about misunderstanding.

That's why I'm trying to export string values to a data file. However, when you use, for instance, 

if(!FrameAdd("stats",1,0,"datafile.csv"))
  {
   Print("Error while loading data file");
  }

it fails somehow while loading the data file.

You have to create the file, did you ?

Regarding the third question, I would like to be able to import the optimization data using dataframes, as I would like to be able to sepparate data for each pass. And this cannot be done if I export everything to the same file, as I cannot get the pass id inside the optimization itself.

Of course, what is the problem ? Create your data file in OnTester(). Declare it with FrameAdd().

Inside OnTesterPass() open your data file and process it, in the same way you did with an array.

So I think the 3 questions above are still open... :-)

Regards,
Malacarne

No it's not open :-) You are searching for complex things when in fact it's really simple.

EDIT: Well after some checking it's seems not so easy :-D

The problem being there seems to have no way to open the data file in OnTesterPass()
 
Rodrigo I suggest you to contact the ServiceDesk.
 
Alain Verleyen:
Rodrigo I suggest you to contact the ServiceDesk.
 
Rodrigo Malacarne:

What is the result of the request to the service desk? I'm about to ask the same question.

For me, only binary file can be transferred. Text file is submitted to FrameAdd without an error, but receiving end gets an array full of zeros from FrameNext.

 
Stanislav Korotky:

What is the result of the request to the service desk? I'm about to ask the same question.

For me, only binary file can be transferred. Text file is submitted to FrameAdd without an error, but receiving end gets an array full of zeros from FrameNext.

I checked against following your post and finally figured out how it works :

//+------------------------------------------------------------------+
//| Optimization start                                               |
//+------------------------------------------------------------------+
void OnTesterInit()
  {
//--- If writing of optimization results is enabled
   Print(__FUNCTION__,"(): Start Optimization \n-----------",TerminalInfoString(TERMINAL_DATA_PATH));
  }
//+------------------------------------------------------------------+
//| Test completion event handler                                    |
//+------------------------------------------------------------------+
double OnTester()
  {
//--- If writing of optimization results is enabled
   int hl=FileOpen("filetest",FILE_CSV|FILE_WRITE);
   if(hl==INVALID_HANDLE)
     {
      printf("Error %i creating tester file",GetLastError());
     }
   else
     {
      int rndval=MathRand();
      FileWriteString(hl,StringFormat("this is a random test %i",rndval));
      FileClose(hl);

      //--- Create a frame
      if(!FrameAdd("Statistics",rndval,0,"filetest"))
         printf("FrameAdd failed with error %i",GetLastError());
      else
        {
         Print("Frame added");
        }
     }
//---
   return(0.0);
  }
//+------------------------------------------------------------------+
//| Next optimization pass                                           |
//+------------------------------------------------------------------+
void OnTesterPass()
  {
   ulong pass;
   string name;
   long id;
   double value;
   ushort data[];

   if(!FrameNext(pass,name,id,value,data))
      printf("Error #%i with FrameNext",GetLastError());
   else
      printf("%s : new frame pass:%llu name:%s id:%lli value:%f",__FUNCTION__,pass,name,id,value);

   string receivedData=ShortArrayToString(data);
   printf("Size: %i %s",ArraySize(data),receivedData);
   Comment(receivedData);
  }
//+------------------------------------------------------------------+
//| End of optimization                                              |
//+------------------------------------------------------------------+
void OnTesterDeinit()
  {
   Print("-----------\n",__FUNCTION__,"(): End Optimization");
  }
Thanks @Stanislav Korotky
 
Alain Verleyen:

I checked against following your post and finally figured out how it works :

Do you receive zeros as well? What is your output?
 
Stanislav Korotky:
Do you receive zeros as well? What is your output?

No, as I said it works, not for you ?

2017.05.21 20:00:48.107    FrameTest (EURUSD,M6)    OnTesterInit(): Start Optimization
2017.05.21 20:00:57.292    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:0 name:Statistics id:28820 value:0.000000
2017.05.21 20:00:57.292    FrameTest (EURUSD,M6)    Size: 28 this is a random test 28820
2017.05.21 20:00:57.309    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:16 name:Statistics id:28820 value:0.000000
2017.05.21 20:00:57.309    FrameTest (EURUSD,M6)    Size: 28 this is a random test 28820
...

2017.05.21 20:01:10.587    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:79 name:Statistics id:8492 value:0.000000
2017.05.21 20:01:10.587    FrameTest (EURUSD,M6)    Size: 27 this is a random test 8492
2017.05.21 20:01:10.720    FrameTest (EURUSD,M6)    -----------
2017.05.21 20:01:10.720    FrameTest (EURUSD,M6)    OnTesterDeinit(): End Optimization

Build 1596.
 
Alain Verleyen:

No, as I said it works, not for you ?

2017.05.21 20:00:48.107    FrameTest (EURUSD,M6)    OnTesterInit(): Start Optimization
2017.05.21 20:00:57.292    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:0 name:Statistics id:28820 value:0.000000
2017.05.21 20:00:57.292    FrameTest (EURUSD,M6)    Size: 28 this is a random test 28820
2017.05.21 20:00:57.309    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:16 name:Statistics id:28820 value:0.000000
2017.05.21 20:00:57.309    FrameTest (EURUSD,M6)    Size: 28 this is a random test 28820
...

2017.05.21 20:01:10.587    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:79 name:Statistics id:8492 value:0.000000
2017.05.21 20:01:10.587    FrameTest (EURUSD,M6)    Size: 27 this is a random test 8492
2017.05.21 20:01:10.720    FrameTest (EURUSD,M6)    -----------
2017.05.21 20:01:10.720    FrameTest (EURUSD,M6)    OnTesterDeinit(): End Optimization

Build 1596.
I think ShortArrayToString is the clue. I did not use it.
Reason: