Bug in working with resources (#resource).

 

Hi, 

I am facing an issue in working with resources (#resource) . When I include a csv as string resource, compile and then test it in the tester the string resource is only available once. After that, the string is empty unless I restart MT5 (or recompile). The problem affects only the backtest but not optimization. With optimization enabled it works. 


Looks like a bug or am I missing something? (I'm not experienced with #resource). 


Here an example that illustrates the issue (example.csv file needs to be in same folder as EA):

//+------------------------------------------------------------------+
//|                                   issue_workingWithResources.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#resource "example.csv" as string example_resource
string example_arr[];
int example_arr_size;

input bool example_setting = true;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

   StringSplit(example_resource, '\n', example_arr); 
   example_arr_size=ArraySize(example_arr);
   if(example_arr_size > 0)
     {
       Print("example_resource contains a string: \n", example_resource);
       ArrayPrint(example_arr);
     } 
   else
     {
      Print("example_arr is empty");
      Print("example_resource contains:", example_resource);
     }
//---
   return(INIT_SUCCEEDED);
  }

//custom_max returns 1 if resource is available.
double OnTester(void)
  {
   int ret = 0;
   if(example_arr_size > 0)
     {  
       ret = 1;
     }    
   Print("example_resource contains a string: \n", example_resource);
   return(ret);
  }
Files:
example.csv  1 kb
 

It's a bug and contrary to what you said, it happens also on optimization ( you need more passes than agents to see it).

Reported to Metaquotes.

 
Alain Verleyen:

It's a bug and contrary to what you said, it happens also on optimization ( you need more passes than agents to see it).

Reported to Metaquotes.

Hi, many thanks for the reply. Yes you are right, optimization is also failing, I just re-tested it. 

Well in this case hopefully they have a fix with the next (beta) release. 

Regards, Julian
 

Thank you for report.

Fixed. Please wait for updates.

You can use Visual mode to avoid this wrong behavior in the current build