Chaining genetic algorithm optimization mql5

 

hi,

i have 2 custom meteics to optimize my algo with.


First I want to backtest optimize using genetic algo using custom metric 1 and then using threshhold x , i want to optimise using custom metric 2. 

So my expectation is that when i start the optimization process it will first optimize on custom metric 1 then all those configurations it found with value >x it will optimise using custom metric 2 max. 


how to achieve this?

Essentially in first set of optimisations we have all possible combinations of inputs, but for 2nd set of optimisations the pool of config is down to only those with custom metric1>x. 
This ensures our algo is good in both custom metric 1 and 2. 

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
To obtain information about the currently running mql5 program, constants from ENUM_MQL_INFO_INTEGER and ENUM_MQL_INFO_STRING are used. For...
 

can you estimate their bounds ?

if you can then normalize the 2 metrics and multiply them to one score

 
I have considered addition and multiplication and other combinations but i feel since 2nd metric is relatively more important it feels like performing optimisation twice makes more sense.  to bring out the configurations in the easily interpretable order of custom metric 2.
 
Varun Maithani #:
I have considered addition and multiplication and other combinations but i feel since 2nd metric is relatively more important it feels like performing optimisation twice makes more sense.  to bring out the configurations in the easily interpretable order of custom metric 2.

What are the metrics if you dont mind ?

 
they might be meaningless to other people but first metric is focusing on measuring roughly average profitability for every few weeks while 2nd metric is meant to surface configurations which are consistently profitable over every month. So i am trying to find configuration that have decent average rolling werkly profitability while having low drawdown but the ranking of the configurations need to reflect those which are profitable over most of the months in yhe backtesting period to rule out those configurations that have good custommetric1 value due to really good performing few months.
 
Varun Maithani #:
they might be meaningless to other people but first metric is focusing on measuring roughly average profitability for every few weeks while 2nd metric is meant to surface configurations which are consistently profitable over every month. So i am trying to find configuration that have decent average rolling werkly profitability while having low drawdown but the ranking of the configurations need to reflect those which are profitable over most of the months in yhe backtesting period to rule out those configurations that have good custommetric1 value due to really good performing few months.

That's clever . You are also implying to the genetic algorithm that you want a certain density of activity . Interesting.

But you have a problem with 0 no ? 0 is more profitable than taking some losing trades

 

My custom metrics take into account edge cases already like that. Also i fix any abnormal metric values when i notice during backtesting.

my custom metric logics are ready with code i am looking for a way to chain them. I already have backtested optimised configuration combinations using custom metric 1 but i  need to chain it as i cannot manually check so many configuration candidates. it requires a second level of genetic algo optimisation.

 
Varun Maithani #:

My custom metrics take into account edge cases already like that. Also i fix any abnormal metric values when i notice during backtesting.

my custom metric logics are ready with code i am looking for a way to chain them. I already have backtested optimised configuration combinations using custom metric 1 but i  need to chain it as i cannot manually check so many configuration candidates. it requires a second level of genetic algo optimisation.

The monthly is the most important ?

If you set a max risk and gain $ per week then you can do

double weeklyValue=MathMin((MathMax(maxRisk,weeklyPL)-maxRisk)/(maxGain-maxRisk),1.0);

and by doing the same for the monthly but raising it to 3 or smth to denote importance

 

Can you describe these terms in your equation so i dont have some incorrect subjective interpretation.



yeah monthly is important because i want a monthly paycheck lol

 
Varun Maithani #:
Can you describe these terms in your equation so i dont have some incorrect subjective interpretation.

yeah , lets say

you set a max risk of -500$ , per week thats the maxRisk

you set a max gain of 1500$ , per week thats the maxGain

and imagine 4 senarios for your weekly PL (which is what the current opt pass did for a week (you then add the scores together and avg them from all weeks))

1. weeklyPL -500$ -> score = 0.0

2. weeklyPL 1500$ -> score = 1.0

3. weeklyPL -700$ -> score = 0.0

4. weeklyPL 3000$ -> score = 1.0

The disadvantage is that by bounding the $ values you make the "solution" less walkable

 

By max risk u mean that once trading has resulted in -500 loss or more it will be immediately put in the bucket of 0

basically to put all configurations which exceed a threshold drawdown or something like that in the 0 bucket.

i guess ill try something like that.

Or also maybe i could make the custom metric1 value to 0 or negative if certain % of months are not profitable that way they will not be considered by the descendant generations in genetic algo opt process and leave only those configs which i desire.


i will experiment a bit.