Store Custom Backtest Data in MQL5 Strategy Tester

 

I am developing a multi-strategy expert advisor and need to implement an effective money management system. My approach is to first define all strategies within a single expert and then run the strategy tester separately for each strategy. The results should be stored in a database or file so that, during live execution, the expert can access the backtest results for each strategy individually.

This method will allow me to develop a signal scoring system to manage the signals from all strategies in real-time. However, in addition to the standard backtest results provided by TesterStatistics , I also need to store custom data reports, and the structure of this additional data varies between different experts. Therefore, I need a way to save this data at the end of each backtest performed by the strategy tester.

Initially, I attempted to use MQL5 database functions, but they are restricted, as are file operations within the strategy tester. To overcome this, I developed a C++ DLL to store data in a database, but I have now realized that DLLs are also prohibited.

Is there any alternative solution to store custom backtest data when running the strategy tester?

 

I am developing a multi-strategy expert advisor and need to implement an effective money management system. My approach is to first define all strategies within a single expert and then run the strategy tester separately for each strategy. The results should be stored in a database or file so that, during live execution, the expert can access the backtest results for each strategy individually.

This method will allow me to develop a signal scoring system to manage the signals from all strategies in real-time. However, in addition to the standard backtest results provided by TesterStatistics , I also need to store custom data reports, and the structure of this additional data varies between different experts. Therefore, I need a way to save this data at the end of each backtest performed by the strategy tester.

Initially, I attempted to use MQL5 database functions, but they are restricted, as are file operations within the strategy tester. To overcome this, I developed a C++ DLL to store data in a database, but I have now realized that DLLs are also prohibited.

Is there any alternative solution to store custom backtest data when running the strategy tester?

Are dlls prohibited in the tester ? 

Try a structured save on the common folder which is where all terminals output files

for instance

at the start of one pass , on init , check if the file for the specific test exists 

so if XX represents an encoded name for the current specific test that is about to run , do this :

#define SYSTEM_FOLDER "myEA_Stats"
input string XX="variant_";//variant name
input int XX_id=1;//id
input string extention=".txt";//extention
bool TESTING=false;
int OnInit()
  {
  TESTING=(bool)MQLInfoInteger(MQL_TESTER);
  if(TESTING){
    //does this variant exist ?
      if(FileIsExist(SYSTEM_FOLDER+"\\"+XX+IntegerToString(XX_id)+extention,FILE_COMMON)){
        Print("Strategy tested already skipping");

        return(INIT_PARAMETERS_INCORRECT);
        }
    }
  return(INIT_SUCCEEDED);
  }

and then write the stats with this :

void OnDeinit(const int reason)
  {
  if(TESTING){
    Print("TESTER DEINIT");
    int f=FileOpen(SYSTEM_FOLDER+"\\"+XX+IntegerToString(XX_id)+extention,FILE_WRITE|FILE_BIN|FILE_COMMON);
    FileClose(f);
    }
  }
You can find the folder where these are written in the Editor -> Files -> Open Common Data Folder
 
Mobin Zarekar:

I am developing a multi-strategy expert advisor and need to implement an effective money management system. My approach is to first define all strategies within a single expert and then run the strategy tester separately for each strategy. The results should be stored in a database or file so that, during live execution, the expert can access the backtest results for each strategy individually.

This method will allow me to develop a signal scoring system to manage the signals from all strategies in real-time. However, in addition to the standard backtest results provided by TesterStatistics , I also need to store custom data reports, and the structure of this additional data varies between different experts. Therefore, I need a way to save this data at the end of each backtest performed by the strategy tester.

Initially, I attempted to use MQL5 database functions, but they are restricted, as are file operations within the strategy tester. To overcome this, I developed a C++ DLL to store data in a database, but I have now realized that DLLs are also prohibited.

Is there any alternative solution to store custom backtest data when running the strategy tester?

There are 2 distinct points in your message.

First, you want to store custom results in a file or DB - this is surely possible. Just send the required data from the tester agents to the terminal during optimization via frames. You can save the data as you wish and then load when neccessary.

Second, you want this to adapt in real time. You can't do this in the sense, that all scoring based on the results of previous optimization does not actually consider real-time changes in the market (until you run optimization again and save an updated version of your custom data). Actually, you can optimize and analyze strategies on the fly, but should use other means than the standard tester, that is something utilizing automation (cmd/bat files launching parallel copies of MT5 to optimize EA and obtain results from there) or custom solutions written in MQL5 itself, for example, like this.

 
Stanislav Korotky #:

There are 2 distinct points in your message.

First, you want to store custom results in a file or DB - this is surely possible. Just send the required data from the tester agents to the terminal during optimization via frames. You can save the data as you wish and then load when neccessary.

Second, you want this to adapt in real time. You can't do this in the sense, that all scoring based on the results of previous optimization does not actually consider real-time changes in the market (until you run optimization again and save an updated version of your custom data). Actually, you can optimize and analyze strategies on the fly, but should use other means than the standard tester, that is something utilizing automation (cmd/bat files launching parallel copies of MT5 to optimize EA and obtain results from there) or custom solutions written in MQL5 itself, for example, like this.

Thank you Stanislav for taking your time to answer. I just found that dll's can be use in backtest, problem solved. but about your idea to optimize on fly that was a good one , I read the article and will use it on my frame work. thanks again.

 
Lorentzos Roussos #:

Are dlls prohibited in the tester ? 

Try a structured save on the common folder which is where all terminals output files

for instance

at the start of one pass , on init , check if the file for the specific test exists 

so if XX represents an encoded name for the current specific test that is about to run , do this :

and then write the stats with this :

You can find the folder where these are written in the Editor -> Files -> Open Common Data Folder

Thank you for response , you were right , dlls are allowed in strategy tester . I got a system error and then just asked gpt if they are allowed or not and it said they are forbidden. :)) I fixed cpp dll errors and its working fine. thanks again