Metatrader 5 command line backtesting

 
Hello,

I'm doing in Strategy Tester a lot of backtesting in "Fast genetic based algorithm".

I'm looking for a way that once finish the backtesting, to automatically "Start" again.

It could be possible to be done with Metatrader 5 Running from the Command Line? to create a .bat file with the command to execute and to use Task Scheduler?


If you have a way to do it, contact me :-)

Thank you


Platform Start - For Advanced Users - Getting Started - MetaTrader 5 Help
  • www.metatrader5.com
After installation, a group of programs of the trading platform is added to the Start menu, and the program shortcut is created on the desktop. Use...
 
DavidDomingo88:
Hello,

I'm doing in Strategy Tester a lot of backtesting in "Fast genetic based algorithm".

I'm looking for a way that once finish the backtesting, to automatically "Start" again.

It could be possible to be done with Metatrader 5 Running from the Command Line? to create a .bat file with the command to execute and to use Task Scheduler?


If you have a way to do it, contact me :-)

Thank you


You can try this.

import subprocess

def start_mt5_backtest(expert, symbol, timeframe, start_date, end_date):
    # Path to MetaTrader 5 terminal executable
    mt5_terminal_path = "C:/Path/To/Your/MetaTrader5/terminal64.exe"  # Update this with your actual path

    # Command line parameters for backtesting
    command_line_params = [
        mt5_terminal_path,
        "/config:Default",
        "/expert:\"{}\"".format(expert),
        "/symbol:\"{}\"".format(symbol),
        "/period:{}".format(timeframe),
        "/from:\"{}\"".format(start_date),
        "/to:\"{}\"".format(end_date),
        "/skipflp",
        "/skipwnd"
    ]

    # Start the MetaTrader 5 terminal process with the specified parameters
    subprocess.Popen(" ".join(command_line_params), shell=True)

if __name__ == "__main__":
    # Example parameters for backtesting
    expert_file = "YourExpert.ex5"  # Update this with the path to your expert advisor file
    symbol = "EURUSD"
    timeframe = 1440  # Daily timeframe
    start_date = "2020.01.01"
    end_date = "2021.01.01"

    # Start the backtest
    start_mt5_backtest(expert_file, symbol, timeframe, start_date, end_date)

I hope you manage. You can always change this or play around with the idea.

Replace "C:/Path/To/Your/MetaTrader5/terminal64.exe" with the actual path to your MetaTrader 5 terminal executable. Also, update "YourExpert.ex5" with the path to your expert advisor file.

To execute this script, save it as a .py file, navigate to its directory in the command line, and run python script_name.py . This will start the backtest process in MetaTrader 5 with the specified parameters.

 
Nardus Van Staden #:

You can try this.

I hope you manage. You can always change this or play around with the idea.

Replace "C:/Path/To/Your/MetaTrader5/terminal64.exe" with the actual path to your MetaTrader 5 terminal executable. Also, update "YourExpert.ex5" with the path to your expert advisor file.

To execute this script, save it as a .py file, navigate to its directory in the command line, and run python script_name.py . This will start the backtest process in MetaTrader 5 with the specified parameters.

Hello Nardus,

Thank you a lot for your help!

This is a good start, since I don't have experience in coding.

There are other parameters like Delays which I like 30ms, Modelling which I like "1 minute OHLC", "profit in pips for faster calculations", Deposit: $100, leverage 1:500, Optimization: "Fast genetic based algorithm" with "Custom max" and also the parameters of the EA.


Can you help with this? I'm more than happy to create a Freelance job if it's an option for you with payment. Basically I like that "Start" to be automatically and not waiting every 2 hours and click again to see more and more backtesting.

I think probably there are more people with this situation.


Thank you a lot!

 

you could watch this video to do it without learning to code,

https://www.youtube.com/watch?v=aUiLM3cang8&t=2s


This is an example how to do it automatically

"D:\MT5 - Eightcap\Eightcap - MT5\terminal64.exe" /config:"D:\StrategyName_AUDCAD.ini"
"D:\MT5 - Eightcap\Eightcap - MT5\terminal64.exe" /config:"D:\StrategyName_AUDCHF.ini"
"D:\MT5 - Eightcap\Eightcap - MT5\terminal64.exe" /config:"D:\StrategyName_AUDJPY.ini"
"D:\MT5 - Eightcap\Eightcap - MT5\terminal64.exe" /config:"D:\StrategyName_AUDNZD.ini"
"D:\MT5 - Eightcap\Eightcap - MT5\terminal64.exe" /config:"D:\StrategyName_AUDUSD.ini"
"D:\MT5 - Eightcap\Eightcap - MT5\terminal64.exe" /config:"D:\StrategyName_CADCHF.ini"
...

you can run it using task scheduler if you want to

How to automate optimizations in MT5 strategy tester
How to automate optimizations in MT5 strategy tester
  • 2023.02.23
  • www.youtube.com
A step by step guide for automatically executing different optimizations in the MT5 strategy tester.1. Creating .ini filesReport=opti-eurjpyReplaceReport=1Sh...
 
Luandre Ezra #:

you could watch this video to do it without learning to code,

https://www.youtube.com/watch?v=aUiLM3cang8&t=2s


This is an example how to do it automatically

you can run it using task scheduler if you want to

Hello Luandre,


I only can say thank you a lot!!! It is working and this is what I was looking for. Simply amazing. I hope I can help some day too. Thank you a lot :-)

@Luandre Ezra @Luandre Ezra

Luandre Ezra
Luandre Ezra
  • www.mql5.com
Trader's profile
Reason: