Starting strategy tester through command line parameters? - page 2

 

Thank you so much Phil! You have opened my eyes. I have been looking for a fully automated solution and a command line (bash) will help me to save my time by checking trading oportunities on a weekly basis. Let me share with you guys my idea. My Mt4 is running on Wine32 and the first step is to create the file paramset.set by clicking on "Expert properties / Inputs / Save".

// now you can find the file paramset.set in path MetaTrader/tester
// you can spead up Testings by unmark the option "Visual mode"
// please close MetaTrader before (!!) you start the command line
cd MetaTrader
gedit myini.ini  // you may copy/paste the Phil's data up there ; start strategy tester TestExpert=Moving Average.ex4 ...
wine terminal.exe myini.ini // it will run one test on a Symbol specified in myini.ini

// to test all requested Symbols would be better to run a bash. Echo makes the ini file and then starts Mt4 and so on for all symbols.
gedit tester.sh  // copy/paste the code below
chmod u+x tester.sh  // make it executable
bash tester.sh  // That's all. Any tests are running now and you can find all results in folder MetaTrader/tester/files On H1 it takes a few minutes;-))



#!/bin/bash declare -a symbol=("EURUSD+" "USDJPY+" "AUDUSD+" "EURJPY+" "GBPUSD+" "USDCAD+") spread=(8 12 13 18 18 19) ## you have to change name of each “Symbol()” and it's spred used in your platform. Value 0 for each Symbol means use the current spread myExpert="Moving Average.ex4" ## update your expert's name ini="myini.ini" fromDate=2021.02.22 toDate=2021.02.28 Nr=0 ## do not touch this counter ## now loop through the above array for i in "${symbol[@]}" do echo "; start strategy tester" > $ini echo "TestExpert=$myExpert" >> $ini echo "TestExpertParameters=paramset.set" >> $ini echo "TestSymbol=$i" >> $ini echo "TestPeriod=H1" >> $ini ##you may change timeframe echo "TestModel=1" >> $ini ##you may change test model 0 1 2 echo "TestSpread=${spread[$Nr]}" >> $ini echo "TestOptimization=false" >> $ini echo "TestDateEnable=true" >> $ini echo "TestFromDate=$fromDate" >> $ini echo "TestToDate=$toDate" >> $ini echo -e "TestReport=tester/files/$symbol""report" >> $ini echo "TestReplaceReport=true" >> $ini echo "TestShutdownTerminal=true" >> $ini wine terminal.exe $ini let "Nr++" echo "************ I'm just testing $i poz. $Nr of ${#symbol[@]}" mkdir -p tester/files/"$(printf %02d $Nr) $i" mv tester/files/*.* tester/files/"$(printf %02d $Nr) $i" done echo "Test of ${#symbol[@]} symbols finished."

I hope that helps somebody.

Good luck!


P.S. This article is dedicated to the memory of DJ Thomas Coastline. He has succumbed to cancer at the age of 35.

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Command line arguments and custom configuration files are described in detail here:

https://www.metatrader5.com/en/terminal/help/start_advanced/start#configuration_file

At the bottom of the page you find an example config file to start a strategy test/optimization.

Platform Start - For Advanced Users - MetaTrader 5 Help
Platform Start - For Advanced Users - 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...
 
diffij:

Thank you so much Phil! You have opened my eyes. I have been looking for a fully automated solution and a command line (bash) will help me to save my time by checking trading oportunities on a weekly basis. Let me share with you guys my idea. My Mt4 is running on Wine32 and the first step is to create the file paramset.set by clicking on "Expert properties / Inputs / Save".

I hope that helps somebody.

Good luck!


P.S. This article is dedicated to the memory of DJ Thomas Coastline. He has succumbed to cancer at the age of 35.

Thank you !! it helps a lot.

here is my adjusted code (Working on Win10) ,

Have a good day!

#!/bin/bash
declare -a symbol=("UKOUSD" "USOUSD" "AUDUSD" "EURUSD" "USDJPY" "USDCHF" "USDHKD" "BARC.L" "BATS.L" "HSBA.L" "LLOY.L" "BABA.N" "TWTR.N" "MAR.OQ" "ORCL.N" "UBER.N" "AMD.OQ" "BDEV.L" "REP.MC" "DAI.DE" "AAL.OQ" "SPOT.N" "VOW.DE" "BRKB.N" "ORA.PA" "TSM.OQ" "PLTR.N" "SNOW.N" "JPN225" "BTCUSD" "LTCUSD" "ETHUSD" "RPLUSD" "GBPUSD" "BCHUSD" "CME.OQ" "FOX.OQ" "KHC.OQ" "NWS.OQ" "TXN.OQ" "DELL.N" "RACE.N" "SCHW.N" "SPGI.N" "BRBY.L" "RDSA.L" "RDSB.L" "SBRY.L" "STAN.L" "TSCO.L" "ULVR.L" "ALV.DE" "BMW.DE" "CBK.DE" "CON.DE" "DB1.DE" "DTE.DE" "DWS.DE" "NSU.DE" "PUM.DE" "SHL.DE" "ACA.PA" "AIR.PA" "BNP.PA" "CDI.PA" "GLE.PA" "RMS.PA" "RNO.PA" "SAN.PA" "XPEV.N" )
spread=(0 0 0 0 0 0)
## you have to change name of each “Symbol()” and it's spred used in your platform. Value 0 for each Symbol means use the current spread
 
myExpert="EA_TEST" ## update your expert's name

configPath="C:/Users/XXXX/AppData/Roaming/MetaQuotes/Terminal/C348917D9E28C59E863914247686464D/config/"
fromDate=2020.01.01
toDate=2021.04.28
Nr=0 ## do not touch this counter

## now loop through the above array
for i in "${symbol[@]}"
do
  
   echo "; start strategy tester" > $i.ini
   echo "TestExpert=$myExpert" >> $i.ini
   echo "TestSymbol=$i" >> $i.ini
   echo "TestPeriod=H1" >> $i.ini ##you may change timeframe
   echo "TestModel=2" >> $i.ini  ##you may change test model 0 1 2
# echo "TestSpread=${spread[$Nr]}" >> $i.ini  User current spread.
   echo "TestSpread=0" >> $i.ini
   echo "TestOptimization=false" >> $i.ini
   echo "TestDateEnable=true" >> $i.ini
   echo "TestFromDate=$fromDate" >> $i.ini
   echo "TestToDate=$toDate" >> $i.ini
   echo -e "TestReport=$i""report" >> $i.ini
   echo "TestReplaceReport=false" >> $i.ini
   echo "TestShutdownTerminal=true" >> $i.ini 

         mv $i.ini  $configPath
        
        ./terminal.exe config/$i.ini
        let "Nr++"
        echo "************ I'm just testing _$i $i poz. $Nr of ${#symbol[@]}"
        
        #mkdir -p tester/files/"$(printf %02d $Nr) $i"
        #mv tester/files/*.* tester/files/"$(printf %02d $Nr) $i"
done
echo "Test of ${#symbol[@]} symbols finished."
 
agavaqif #:

guys I can start MT5 from command line like "path\terminal64.exe" config: "configpath" 
But this just starts mt5 it does not run strategy tester. Is there any way to directly run ST from command line?

You need to add a section to ini file with [TesterInputs], than the test should be started, mine looks like this:


[Tester]
Expert=Market\Some_EA.ex5
Symbol=XAUUSD
Period=M5
Optimization=3
Model=1
FromDate=2021.01.25
ToDate=2021.01.29
ForwardMode=0
Deposit=10000
Currency=EUR
ProfitInPips=0
Leverage=500
ExecutionMode=120
OptimizationCriterion=0
Report=M1-W3.xml
ReplaceReport=1
ShutdownTerminal=1

[TesterInputs]
fNS=true||false||0||true||N
fTrBuy=true||false||0||true||N
fTrSell=true||false||0||true||N
fHO=false||false||0||true||N
Flag_Use_hedge=true||false||0||true||N
iMO=10||10||1||100||N


But there is a bug in Metatrader 5, when Optimization is used to thest all assets in market overview than the XML report is always empty, that sucks and needs to be fixed soon :(


https://www.metatrader5.com/en/terminal/help/start_advanced/start

Platform Start - For Advanced Users - MetaTrader 5 Help
Platform Start - For Advanced Users - 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...
 
fischeye #:

You need to add a section to ini file with [TesterInputs], than the test should be started, mine looks like this:


[Tester]
Expert=Market\Some_EA.ex5
Symbol=XAUUSD
Period=M5
Optimization=3
Model=1
FromDate=2021.01.25
ToDate=2021.01.29
ForwardMode=0
Deposit=10000
Currency=EUR
ProfitInPips=0
Leverage=500
ExecutionMode=120
OptimizationCriterion=0
Report=M1-W3.xml
ReplaceReport=1
ShutdownTerminal=1

[TesterInputs]
fNS=true||false||0||true||N
fTrBuy=true||false||0||true||N
fTrSell=true||false||0||true||N
fHO=false||false||0||true||N
Flag_Use_hedge=true||false||0||true||N
iMO=10||10||1||100||N


But there is a bug in Metatrader 5, when Optimization is used to thest all assets in market overview than the XML report is always empty, that sucks and needs to be fixed soon :(


https://www.metatrader5.com/en/terminal/help/start_advanced/start

You should not mix MT4 and MT5.
 

This is sensational information - Thanks all for providing commentary in this thread, just what I was looking for (was hoping such a thing was possible!). 

I'm not particularly accross such scripting coding and although I'm going to research further, is there syntax to run through a number of EA's, perhaps in a given directory, for a single FX pair for backtesting purposes whilst spitting out a backtesting report per EA? 

Eg. I'm hoping to automate backtests of a bulk of EA's within MT5 and having a *.htm *.html file output alike what you can manually generate. As you can imagine, this is a time consuming exercise doing manually! 


Thanks in advance ... its appreciated!

 

where do you place this binbash script? Does this work on OSX?


It is not clear to me which of this code in the thread is for MT4 or MT5, can someone help me understand how to backtest multiple ea's on specific pairs on my Mac?


Thanks