Resource Management for Expert Advisor Private Data

Hi all!


I'm trying to deal with resource management and/or path resolution when consuming resources that are supposed to be shipped with the Expert Advisor or are supposed to be used during Backtesting. This is in the context of me writing my own Expert Advisor. Not someone elses.


For example: I have a CSV File of historical Economic Calendar Events that I want to consume and use since when I run try to use CalendarEvent lookups in backtests it refuses to consume the Countries, Events or Values I ask it to consume.

Any form of PATH lookups for files doesn't let me load something relative to the EA or from the EA Experts binary directory and only provides me the terminal directory.

This makes filtering for known blackswan events a little more difficult since I know I will want to take advantage of EC announcements to avoid unnecessary volatility. Unfortunately that's not possible it seems.

My asks are:

- Is there a way to ask for an EA Binary relative path on execution, not on compile to load a CSV file of my choice?

- Resources equally expects me to hardcode a full directory path rather than use a relative path if I so chose. Is there a better solution?

Alternative Approaches:

- Throwing the file as a resource into the resources directory away from my repository/project directory, which is annoying and clunky, especially for collaborative projects.

- Setting an Input field to paste the full path into, which is ugly and clunky in my opinion. If I can't bootstrap the project with minimal setup from a cloned project repository, I'm failing on-boarding and quick deployment, turnaround times and QA for a project. But maybe that is just my high standard.

Any help would be appreciated.

The tester runs on an agent with its own sandbox, so relative paths to the EA folder won't work. Put the CSV in MQL5\Files and add this to the EA, the tester then copies it to the agent:

#property tester_file "events.csv"

int h = FileOpen("events.csv", FILE_READ|FILE_CSV|FILE_ANSI, ',');

Also the Calendar* functions don't return anything in the tester anyway, so loading your own CSV is the right way to go.

Andreas Marschke:

Hi all!


I'm trying to deal with resource management and/or path resolution when consuming resources that are supposed to be shipped with the Expert Advisor or are supposed to be used during Backtesting. This is in the context of me writing my own Expert Advisor. Not someone elses.


For example: I have a CSV File of historical Economic Calendar Events that I want to consume and use since when I run try to use CalendarEvent lookups in backtests it refuses to consume the Countries, Events or Values I ask it to consume.

Any form of PATH lookups for files doesn't let me load something relative to the EA or from the EA Experts binary directory and only provides me the terminal directory.

This makes filtering for known blackswan events a little more difficult since I know I will want to take advantage of EC announcements to avoid unnecessary volatility. Unfortunately that's not possible it seems.

My asks are:

- Is there a way to ask for an EA Binary relative path on execution, not on compile to load a CSV file of my choice?

- Resources equally expects me to hardcode a full directory path rather than use a relative path if I so chose. Is there a better solution?

Alternative Approaches:

- Throwing the file as a resource into the resources directory away from my repository/project directory, which is annoying and clunky, especially for collaborative projects.

- Setting an Input field to paste the full path into, which is ugly and clunky in my opinion. If I can't bootstrap the project with minimal setup from a cloned project repository, I'm failing on-boarding and quick deployment, turnaround times and QA for a project. But maybe that is just my high standard.

Any help would be appreciated.

Navid's tester_file answer is right for testing. If the EA is going to the Market, there is one more catch: buyers only get the .ex5, so a CSV in MQL5\Files will not be on their machine. You can compile the file into the EA instead:

#resource "\\Files\\events.csv" as string g_events_csv

Then split g_events_csv by "\n" and "," in OnInit. No file access is needed at runtime, it works in the tester and on the agent, and the data cannot be edited by the user. The limit is that you have to recompile to update the data, so for a calendar file that changes often, ship the resource as a fallback and read a newer file from MQL5\Files when it exists.

For a fixed historical CSV, Amul’s resource suggestion works. To keep the file alongside your source, we tested this layout inside MQL5\Experts :

MyEA\ MyEA.mq5 events.csv

Add this at the top of your EA:

#resource "events.csv" as string g_events_csv

The CSV contents are then available in g_events_csv for your code to parse. You don’t need FileOpen() to read the embedded data.

We checked this on build 6230: after compiling, we renamed the original CSV and ran the EX5 in the local Strategy Tester. It still printed the CSV contents correctly. So you only need to distribute the EX5.

Updating the embedded data means recompiling. One caveat: the same relative-path examples failed to compile outside the MQL5 folder in our test, so the layout above is the one we verified.