
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
In the free library from the article, work with the genotype. Work with phenotype in FF (as in example 2).
The above means that the library will work just as efficiently if the phenotype is processed in FF, but the number of iterations (FF runs) will be significantly higher than if the GA works with the phenotype directly (because the search space detail increases). In the limit, the search (without phenotype refinement) tends to a continuous search space.
Goodnight.
I would like to thank you for a great article.
It was a bit complicated for me at first, but I sort of figured it out.
Before I write something in this forum thread, I would like to clarify for myself whether I understood your article and the course of the UGA algorithm correctly:
1)Setting the input parameters of UGA for a particular task.
---UGA
2) Creating an initial colony of parents by randomly combining genes
2.2)Calculating the result of FF for each of this colony
2.3)Removal of clones.
3)Determining the best FF result from all individuals in that colony
4) Starting the cycle of creating a colony of descendants from the first colony. The descendants are created using the tools: Crossover,artificial and natural mutation, gene replication and gene borrowing, where
Crossover - exchange of parts of parent's chromosomes,
Artificial mutation - selection of genes out of range (gene of parent 1, gene of parent 2).
Est. Mutation - selection of genes from the range (Minimum of gene range , Maximum of gene range).
replication - selection of genes in the ranges close to the values of parental genes, but with a certain offset.
gene borrowing - creation of "assembled individual" from the number of parents equal to the number of genes.
5 )Deletion of clones
6 )Calculating the result of the FF for each of these colonies
7)Comparison of the results of the descendant individuals with the reference result, and its possible replacement. in case of replacement the counter "Epochs without changes of the reference value" is reset
8)Sorting of all individuals from best to worst
9) -->item 4
10)If epochs with no change in Y occurred, then terminate and output the found reference value.
I apologise in advance, perhaps this is a discussion thread rather than a tutorial, but I have nowhere else to ask for advice. I actually met GA for the first time in your article (Before your article I didn't even understand what the words "Fast(genetic algorithm)" mean in the terminal tester), so my knowledge and experience (I started programming in MQL5 about 2 months ago) is a bit limited.
If I understand your GA algorithm, I will try to transplant it to OOP. For what, in fact, I started to study it. I have already implemented trading models, self-optimising with direct search, but with GA not yet.( Models on the principle described in the article https://www.mql5.com/ru/articles/217 ).
Thanks in advance.
mi__x__an:
...I would like to clarify for myself whether I have understood your article and the course of the UGA algorithm correctly
Good day .
Thank you for your prompt reply.
Then I have some questions.
What is the Chromosome array here? Possible values of the optimised parameter?
So if, for example, we optimise "minimum lot size" in the range from 0.1 to 1 (with a minimum lot step of 0.1),
then the array will look like this:{0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}, number of genes in chromosome 1, minimum 0.1 maximum 1.0, step 0.1 ? Is it ?
And a related question, how to enter into such an array, for example: Optimised Stop Loss [10...500], Take Profit [10...500], Min. lot size [0.1...1.0] and Trailing flag (use trailing or not)[0...1]?
In general, how should the input data look like when optimising parameters with different types, minima and maxima of possible values?
Thanks in advance for the answer.
What is the Chromosome array here? The possible values of the optimised parameter?
So if, for example, we optimise "minimum lot size" in the range from 0.1 to 1 (with a minimum lot step of 0.1),
then the array will look like this:{0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}, number of genes in chromosome 1, minimum 0.1 maximum 1.0, step 0.1 ? Is it ?
And a related question, how to enter into such an array, for example: Optimised Stop Loss [10...500], Take Profit [10...500], Min. lot size [0.1...1.0] and Trailing flag (use trailing or not)[0...1]?
In general, how should the input data look like when optimising parameters with different types, minima and maxima of possible values?
Thanks in advance for the answer.
No,
Chromosome[] is exactly what the comment says.
The first index [0] is the fitness value of the individual. The others are optimised parameters within a given range. This is the genotype.
Work with phenotype (stop losses, take profits, volumes, indicators or something else) in FF (scaling of optimised parameters in the range of chromosome genes):
For example, genes are set in the range [-1;1], then
Index 0: FF value <---------------------------------------------------------[8;8]//pivot to Pi/2 eights.
1st index: Stop loss [10..500] <------------------------------------------------ [-1;1]
2nd index: Take profit [10..500] <--------------------------------------------- [-1;1]
3rd index: Min. lot volume [0.1...1.0] <--------------------------------------- [-1;1]
4th index: Trailing flag (to use trailing or not)[0..1] <------ [-1;1]
And furthermore, the Chromosome[] array has 5 cells. For example, a chromosome might look like this {0.2, 0.3, -0.8, 0.1, 0.9;}
But in this case processing of correctness of values of non real genes will have to be done in FF. I.e. if we optimise types long, double, and bool UGA will generate real values for all of them, including for bool there will be many variations of genes in the range from RangeMinimum to RangeMaximum, with the real possible use of only two values 1 and 0. Do I understand correctly? And already the selection of correct values will be done in FF?
Then the best way to get rid of this drawback, for me personally, would be to introduce a service function that corrects the chromosome gene values to the ones that can be used in the FF.
-->generation of descendants -->adjustment of gene values to actually usable values -->deletion of clones -->call of FF.
With this course of action, do you think it will have a big impact on UGA performance? After all, by idea, the number of FF runs should be reduced if the step for optimising one parameter is larger than for the other.
Right, if this is not suitable, then you should use a binary genetic algorithm (such as the one implemented in the tester). There is an article on it on the fourth forum.
No, the point is different. The algorithm can be used perfectly well for such cases as well.
mi__x__an:
But in this case processing of correctness of values, not real genes will have to be done in FF. I.e. if we optimise types long, double, and bool UGA will generate real values for all of them, including for bool there will be many variations of genes in the range from RangeMinimum to RangeMaximum, with the real possible use of only two values 1 and 0. Do I understand correctly? And already the selection of correct values will be done in FF?
All operations with phenotype should be done in FF. It is a matter of decoding from genotype to phenotype.
Ok, let's assume that the optimised parameter is of bool type and only two variants are possible: true and false. Then the decoding will be something like this:
where gene is a specific gene of a chromosome.
It turns out that with all the variety of possible variants of this gene (genotype) we will get only 2 phenotypes. This is also the case in living nature.
However, a natural consequence follows from this: more chromosome variants will be generated (and thus, more times the FF will be calculated) than it is necessary to solve the problem. That is, the optimisation will take longer. I have already mentioned this. It will be the same in case of binary encoding of chromosomes. You will still have to decode into a task-specific phenotype.
BUT. Both in case of binary coding and in case of genes representation by real numbers, it is very easy to avoid unnecessary FF calculations (to reduce the number of possible chromosome variants) by setting the SEARCH STEPS AND STEP for each oPTIMISED PARAMETER. I.e. cut off unnecessary chromosome variants in advance (this is already done in the standard optimiser with binary coding). This can also be done for the GA from the article, you just need to add the appropriate functionality to it - the ability to set the boundaries and step for each gene, i.e. to allow the GA to work directly with the phenotype.
but the need to specify bounds and step for each gene in the library will reduce its flexibility.
What is probably not the best or even the worst way I used in the trading models optimiser:
1 - class of the optimised parameter - CObject inheritor
2 - virtual function of the main general model :
virtual CList *OptimizatedParams()
it allows each specific model to create its own list of optimised parameters.
3. optimising function - it recursively enumerates all necessary values.
Any enumerated types can be handled by the optimising function.
Now the question: It would be rational to make CList as input data in which information about the optimised parameter is passed through this class of the optimised parameter, and the UGA Library itself creates as many boundaries and steps as necessary for each gene. This would give it more flexibility and reduce the number of unnecessary runs of FF to create not genetic but phenotypic clones.