MQL Code for Controlling of MT4 Strategy Tester

 
Hello dear traders,

Could you please help me with my task for the MT4 Strategy Tester? I need a code that would go through my directory containing prepared setfiles and perform these operations for each setfile:

1. Load expert properties from the i-th setfile
2. Run the backtest
3. Save the Report (named i.htm)

Thank you so much in advance!
 
mqleurope: Could you please help me with my task for the MT4 Strategy Tester? I need a code that would go through my directory containing prepared setfiles and perform these operations for each setfile:

1. Load expert properties from the i-th setfile
2. Run the backtest
3. Save the Report (named i.htm)

Please note that this site is about MetaTrader and MQL programming and not necessarily programming command-line batch files for the operating system.

You might get lucky if someone already has something of their own which is similar and is willing to share it with you. However, if not, please consider the fact that you should hire someone to do it for you as I doubt anyone will go to the trouble to make it for free.

 
Fernando Carreiro:

Please note that this site is about MetaTrader and MQL programming and not necessarily programming command-line batch files for the operating system.

You might get lucky if someone already has something of their own which is similar and is willing to share it with you. However, if not, please consider the fact that you should hire someone to do it for you as I doubt anyone will go to the trouble to make it for free.

Hello Fernando,

Thank you for your answer. Since I am not experienced in MQL, I do not know if it is possible to control the Strategy Tester within MQL itself. Is it possible please?

Thanks a lot.

 
mqleurope: Thank you for your answer. Since I am not experienced in MQL, I do not know if it is possible to control the Strategy Tester within MQL itself. Is it possible please?

Not in pure MQL! You would have to use Windows API from within MQL and that will be even more difficult for you than programming command-line batch files.

 
Fernando Carreiro:

Not in pure MQL! You would have to use Windows API from within MQL and that will be even more difficult for you than programming command-line batch files.

Thanks, I really appreciate your help. If I would discard the demand to manipulate with setfiles, would it be possible to perform this task directly from MT4 please? I mean this code structure:


1. Run a backtest in Strategy Tester using EA settings listed directly here in the code

2. Save the Report

3. Run a backtest in Strategy Tester using different EA settings listed directly here in the code

4. Save the Report

5. etc.


I assume not. If not, do you know about any manual or instructions how to control MT4 by command-line batch files please? Thanks so much!

 

mqleurope: Thanks, I really appreciate your help. If I would discard the demand to manipulate with setfiles, would it be possible to perform this task directly from MT4 please? I mean this code structure:

1. Run a backtest in Strategy Tester using EA settings listed directly here in the code

2. Save the Report

3. Run a backtest in Strategy Tester using different EA settings listed directly here in the code

4. Save the Report

5. etc.

I assume not. If not, do you know about any manual or instructions how to control MT4 by command-line batch files please? Thanks so much!

Please read the documentation on the subject: https://www.metatrader4.com/en/trading-platform/help/service/start_conf_file

Configuration at Startup - Tools - MetaTrader 4 Help
Configuration at Startup - Tools - MetaTrader 4 Help
  • www.metatrader4.com
The client terminal can be launched with some predefined settings. For this purpose, the configuration file name will be passed to the client...
 
Fernando Carreiro:

Please read the documentation on the subject: https://www.metatrader4.com/en/trading-platform/help/service/start_conf_file

Hello Fernando,

Thank you very much, you helped me a lot. However, I have a serious problem when trying to control the MT4 Strategy Tester from the command line. I need to backtest one compiled EA which can be run on trade accounts whose names contain my personal name only. The trouble is that if I start MT4 and its Strategy Tester from the command line, the backtest starts to run slightly BEFORE MT4 finishes its logging to my trade account. This results to the state where EA is unable to verify that this is really my account and the backtesting is interrupted. Do you have any idea what to do please? For example, would it be possible to create a new EA that would wait for 10 seconds and then call the original EA? I am not experienced in MQL programming at all. 

Thank you so much!

 
mqleuropeThank you very much, you helped me a lot. However, I have a serious problem when trying to control the MT4 Strategy Tester from the command line. I need to backtest one compiled EA which can be run on trade accounts whose names contain my personal name only. The trouble is that if I start MT4 and its Strategy Tester from the command line, the backtest starts to run slightly BEFORE MT4 finishes its logging to my trade account. This results to the state where EA is unable to verify that this is really my account and the backtesting is interrupted. Do you have any idea what to do please? For example, would it be possible to create a new EA that would wait for 10 seconds and then call the original EA? I am not experienced in MQL programming at all. 

There is no need for a second EA. Just start the terminal up with no testing, just with initial setup, so that it carries out the login into your account, and then wait a while, and then call it up again with the testing setup.

I have not tested this myself, but it should work. Just experiment with it a bit. As long as you call it up form the same location and environment and don't shutdown the first instance, it should reuse the existing one and not spawn another instance.

I repeat. I have not tested this myself, but I do believe it will work that way. If it does not, just report it here and we can discuss another option.

 
Starting strategy tester through command line parameters?
Starting strategy tester through command line parameters?
  • 2010.07.27
  • www.mql5.com
Is there a possibility to start a backtest from the command line? Something like "terminal.exe -tester EAxyz EURUSD 5min 2000.01.01 2010.01...
 
Fernando Carreiro:

There is no need for a second EA. Just start the terminal up with no testing, just with initial setup, so that it carries out the login into your account, and then wait a while, and then call it up again with the testing setup.

I have not tested this myself, but it should work. Just experiment with it a bit. As long as you call it up form the same location and environment and don't shutdown the first instance, it should reuse the existing one and not spawn another instance.

I repeat. I have not tested this myself, but I do believe it will work that way. If it does not, just report it here and we can discuss another option.

Hi Fernando, thank you for your answer. I tried the solution you suggested. After I called the terminal for the second time, it really gained a focus but nothing happened afterwards. It does not seem that the already running terminal is able to accept new commands this way:

@echo off

"c:\Program Files (x86)\MetaTrader 4\terminal.exe" "tester\tester.ini"

exit

I really appreciate your willingness to help!

 
Gyula Szajlai:

Check this: https://www.mql5.com/en/forum/127577

Thank you very much, Gyula. I studied this thread but I was not able to find a solution for my special issue. Thanks a lot.
Reason: