I've 3 different input parameters : P1 [1..10], P2 [1..10] and P3 [3..10]. The constraints are the following : P1 < P2 < P3.
Some potential solutions should be discarded right away when the constraints are not respected. For instance when P1 = 2, P2 = 1 and P3 = 4.
Is there a way to accomplish such thing with MetaTrader optimization ? (eventually using OnTesterPass function ?)
I'm losing a lot of time during my optimization because of that and I'd like to find a way to discard or skip directly the potential solution when the constraints are not respected.
Thanks for your help
Not possible inside MetaTrader.
You can build .set files with the exact parameters you need then call MT using a config file from the command line to run the tester.
See section "Running with a Custom Configuration File" sub-section "[Tester]."
Forum on trading, automated trading systems and testing trading strategies
Stop running EA on invalid inputs (Especialy on tester)
Alain Verleyen, 2013.11.23 16:57
Place your test in OnInit() and return INIT_FAILED or INIT_PARAMETERS_INCORRECT. Like :
//--- check for input
if(P1>=P2 || P2>=P3) return(INIT_PARAMETERS_INCORRECT);
As the documentation says:
The result string containing this return code (INIT_PARAMETERS_INCORRECT) is highlighted in red in the general optimization table. Testing for the given set of parameters of the Expert Advisor will not be executed.
UPDATE: Alain were faster :D
So if I understand correctly I set my own parameters inside "MQL5\Profiles\Tester\MyEA.set".
But then this means I can only have one correct set of parameters per run (because if I use start, step and stop I will end up with the same problem as before).
And so I need to somehow write my own optimization algorithm from outside MetaTrader ?
Thanks Alain and Petr, I think that's exatly what I'm looking for.
To break this down:
1. You have specific variable combinations that are valid based upon:
P1 [1..10], P2 [1..10] and P3 [3..10]
You can generate these values external to MT5. For example, you might do this in python.
2. Build a .set file with P1,P2,P3 that fit your constraints.
3. Run the strategy tester (in tester mode, not optimization mode, with visualization turned off) and append the values you want to a CSV file.
It's fairly straightforward to calculate the same statistics that the optimizer supplies, i.e. Recovery factor, Sharpe ratio, etc. You can also any add additional statistical metrics you desire.
4. Once you have generated all the statistics for your combinations of P1, P2, P3, you can run your analysis upon the CSV file. Use Excel or gnuplot or gnumeric or whichever tools you desire to determine which combination of P1,P2,P3 delivered the optimum result.
Granted, it's a long-term solution.
Well, then, your current problem is solved with a simpler solution. That's cool.
This is also true.
While I like MT5 very much, I didn't want to become overly invested in one platform. Having some of my tools outside MT5 gives me options for the future if, for example MetaQuotes goes out of business or if a new platform emerges that is far superior in features. My gamble is that that python will remain viable in the future.
So after implementing the constraints in OnInit I now face another challenge.
I'm trying to optimize my current EA that contains approximately 40 different inputs with MetaTrader genetic algorithm.
The inputs have constraints such as I1 < I2 < I3, I24 > 0, ... For total of about 20 constraints.
The problem is then the following : no viable solutions are found after the first 512 iterations and the optimization stops (same happens with the non genetic optimizer).
If I remove the constraints the algorithm will run and optimize the solutions but then those solutions will not respect the constraints.
Has anyone already faced similar issues ? Currently I think I'll have to use an external tool to optimize but this does not feel right