Page 1 of 2

MetaTrader4 - genetic algorithm optimizer available!

Posted: Tue May 16, 2006 10:54 pm
by michal.kreslik
Hello,

the main issue that made me to use Tradestation instead of NeoTicker or MetaTrader4 was that only Tradestation offered genetic algorithms for strategy optimizing to date.

Since genetic strategy optimization brings me real cold cash by trading the strategies optimized genetically, I had no intent to change the platform :)

But, right now I have been told by the MetaQuotes representative that they are working on genetic algorithms in MetaTrader 4! Approximate release date is first of July, 2006. I hope that "approximate release date" means "approximate release date" unlike with Tradestation Securities where "in about six months" translates to "in about 3 years" (personal experience with forex automation within Tradestation).

This means that MetaTrader4 will support this functionality very soon. Given the fact that MetaTrader4 is free (as compared to Tradestation) and its programming language is better than EasyLanguage, I will seriously think about switching to MetaTrader4 afterwards.

Coincidentally, last week I also found out that The Grail genetic optimizer (which is the one I am using and coding for) is going to have a version for NeoTicker in a matter of months.

Thus, MetaTrader4 and NeoTicker are my options beside Tradestation. I am really looking forward to the aspTrader's NeoTicker presentation!

Have a very nice day!

Michal

Re: MetaTrader4 - genetic algorithm optimizer available!

Posted: Wed May 17, 2006 7:59 am
by michal.kreslik
Well, it seems that MetaTrader4 won't allow for custom fitness functions with its built-in genetic optimizer:


Originally posted by Lenar, MetaQuotes:
Michal, genetic optimization wont be controlable. Everything will covered inside Tester. The best parameters will be determined by the main result - the accounts` balance.


Optimizing on NetProfit only isn't a very good idea. This approach often produces a jagged equity curve which is not much usable for applying the position sizing algorithms.

Michal

Posted: Wed May 17, 2006 1:04 pm
by albruno
where is a good place to find more information on genetic optimization?
is that the equiv of the input parameter ranges on Tradestation Strats?

Posted: Wed May 17, 2006 1:26 pm
by michal.kreslik
albruno,

it's not only the equivalent to finding the best parameter values, but genetic algorithm (GA) can also find the best trading model.

Let's have a look at this strategy snippet:

Code: Select all

inputs:
   iMAType( 1 ), // 1 to 4
   iMALength( 50 ); // 10 to 90

vars:
   vMAValue( 0 );

if          iMAType = 1 then vMAValue = Average(close, iMALength)
   else if iMAType = 2 then vMAValue = Xaverage(close, iMALength)
   else if iMAType = 3 then vMAValue = WAverage(close, iMALength)
   else if iMAType = 4 then vMAValue = TriAverage(close, iMALength);
   
Buy ("average long") next bar at vMAVAlue stop;


This way, the optimizer will not only find the best value for the iMALength, but also will choose the best MA type iMAType. I call these parameters the model parameters.

This example code is quite plain and it might be optimized by a standard exhaustive optimization methods available in Tradestation. But imagine that you've got 10 input parameters, 5 of them are model parameters and you are trying to come up not only with the best model, but with the best (read: the most robust, not the best profit) parameters, too.

Optimizing only 5 parameters with 100 values for each parameter needs 100^5 = 10 000 000 000 combinations. This cannot be done with exhaustive optimization in Tradestation. On the other hand, genetic algorithm will find a near-optimal solution in a matter of hours.

I will post links to the genetic algorithm resources on the internet in the genetic optimization forum. Anyway, feel free to ask about anything concerning GA.

Michal

Re: MetaTrader4 - genetic algorithm optimizer available!

Posted: Thu May 25, 2006 9:20 am
by Lenar
michal.kreslik wrote:Well, it seems that MetaTrader4 won't allow for custom fitness functions with its built-in genetic optimizer:


Originally posted by Lenar, MetaQuotes:
Michal, genetic optimization wont be controlable. Everything will covered inside Tester. The best parameters will be determined by the main result - the accounts` balance.


Optimizing on NetProfit only isn't a very good idea. This approach often produces a jagged equity curve which is not much usable for applying the position sizing algorithms.

Michal


Hi, Michal,

We decided to make some changes. Now genetic optimizator will be contrable. You will be able to choose between:
1. Balance
2. Profit Factor
3. Expected Payoff
4. Maximal Drawdown
5. Drawdown Percent

I`ve attached working screenshot of setup of genetci optimization. After release, this window will be redisigned.

So this option will allow to optimize your stratgies more accurately.

Re: MetaTrader4 - genetic algorithm optimizer available!

Posted: Thu May 25, 2006 2:58 pm
by michal.kreslik
Lenar, great,

this drop-down menu looks cute. BUT, this is not the best way to select the fitness function. This resembles the predefined, Tradestation-like style of work too much. And you want to do better than Tradestation does, right? :)

Obviously, there should be a number of predefined fitness functions, like:

- NetProfit/MaxDrawDown
- NetProfit/Margin
- VanTharp Expectancy
- PROM (Pessimistic Return on Margin)
- Profit Factor
- Equity Curve Linear Regression Max Error/StdDev
- Sharpe Ratio
etc.

But to lift MetaTrader to higher grounds and smash the competition flat :), you have to give your user the freedom to calculate his own fitness funtion.

If you present the user with only a list of several available options in that cute drop-down menu, it is like going to the supermarket and being able to only choose between:

- package 1: cheese, milk, bread, rice
- package 2: cornflakes, 4 apples, wine, sugar
- package 3: potatoes, beef, ice cream, bacon

Now you're smiling, aren't you? But you offer your user precisely these predefined packages without the option the choose milk and ice cream only.

Fortunately, the solution is quite trivial: instead of offering user the entire formulas as a fitness function, give him the ability to use the building blocks to calculate the fitness instead.

What are building blocks?
- TotalProfit
- MaximumDrawDown
- ProfitFactor
- NumberOfLosers
- NumberOfWinners
etc. etc.

This way, if you want to arrive at a set of input values which produces the most trades and best drawdown to profit ratio, you would enter as a fitness function this simple equation:

FitnessValue = (NumberOfLosers + NumberOfWinners)*TotalProfit/MaximumDrawDown

Genetic algorithm-powered optimizer will then try to maximize the result of this equation.

You may implement this FitnessValue variable assignment either right in the code of the strategy (preferably) or you could offer the user the opportunity to enter the formula before the optimization will be run.

Why it is best to implement the FitnessValue variable assignment right in the code? Since the strategy developer may then use any arbitrary value or command within the confines of MetaTrader4 programming language to calculate his own preferred fitness function. Also, implementing this assignment right into the code will actually save you money because there would be absolutely no need to code any extra new dialogues etc.

For this assignment to work, all the tested variables and values during the testing run should be available for calculation within the code.

Let's say that we would like to modify our fitness function from the above example so that we are interested in arriving at a set of input values that produces the most traders, the best profit/drawdown ratio and also the least StopLoss parameter (we don't want to risk much on any single trade :).

The equation might then look like this:

FitnessValue = (NumberOfLosers + NumberOfWinners)*TotalProfit/MaximumDrawDown/StopLossValue

In order to be able to use this construction, the value of the parameter "StopLossValue" needs to be available to the programmer. With every test run, the parameter value will change (the optimizer will pick a new value) and this value needs to be available for the programmer in order to be able to use it in the calculation.

Michal

Re: MetaTrader4 - genetic algorithm optimizer available!

Posted: Fri May 26, 2006 12:22 pm
by Lenar
Hi Michal,

michal.kreslik wrote:Lenar, great,

this drop-down menu looks cute. BUT, this is not the best way to select the fitness function. This resembles the predefined, Tradestation-like style of work too much. And you want to do better than Tradestation does, right? :)

Obviously, there should be a number of predefined fitness functions, like:

- NetProfit/MaxDrawDown
- NetProfit/Margin
- VanTharp Expectancy
- PROM (Pessimistic Return on Margin)
- Profit Factor
- Equity Curve Linear Regression Max Error/StdDev
- Sharpe Ratio
etc.

But to lift MetaTrader to higher grounds and smash the competition flat :), you have to give your user the freedom to calculate his own fitness funtion.

If you present the user with only a list of several available options in that cute drop-down menu, it is like going to the supermarket and being able to only choose between:

- package 1: cheese, milk, bread, rice
- package 2: cornflakes, 4 apples, wine, sugar
- package 3: potatoes, beef, ice cream, bacon

Now you're smiling, aren't you? But you offer your user precisely these predefined packages without the option the choose milk and ice cream only.



Yeah, very good example with supermarket.:)

michal.kreslik wrote:Fortunately, the solution is quite trivial: instead of offering user the entire formulas as a fitness function, give him the ability to use the building blocks to calculate the fitness instead.

What are building blocks?
- TotalProfit
- MaximumDrawDown
- ProfitFactor
- NumberOfLosers
- NumberOfWinners
etc. etc.

This way, if you want to arrive at a set of input values which produces the most trades and best drawdown to profit ratio, you would enter as a fitness function this simple equation:

FitnessValue = (NumberOfLosers + NumberOfWinners)*TotalProfit/MaximumDrawDown

Genetic algorithm-powered optimizer will then try to maximize the result of this equation.

You may implement this FitnessValue variable assignment either right in the code of the strategy (preferably) or you could offer the user the opportunity to enter the formula before the optimization will be run.

Why it is best to implement the FitnessValue variable assignment right in the code? Since the strategy developer may then use any arbitrary value or command within the confines of MetaTrader4 programming language to calculate his own preferred fitness function. Also, implementing this assignment right into the code will actually save you money because there would be absolutely no need to code any extra new dialogues etc.

For this assignment to work, all the tested variables and values during the testing run should be available for calculation within the code.

Let's say that we would like to modify our fitness function from the above example so that we are interested in arriving at a set of input values that produces the most traders, the best profit/drawdown ratio and also the least StopLoss parameter (we don't want to risk much on any single trade :).

The equation might then look like this:

FitnessValue = (NumberOfLosers + NumberOfWinners)*TotalProfit/MaximumDrawDown/StopLossValue

In order to be able to use this construction, the value of the parameter "StopLossValue" needs to be available to the programmer. With every test run, the parameter value will change (the optimizer will pick a new value) and this value needs to be available for the programmer in order to be able to use it in the calculation.

Michal


Ok, Slava STRINGO Starikov, lead programmer of MQL4 said that its very interesting and maybe in future we will build special function FITNESS into MQL 4. But it will be not in current build of terminal defenedly.

Thanks for suggestion

Re: MetaTrader4 - genetic algorithm optimizer available!

Posted: Fri May 26, 2006 12:30 pm
by michal.kreslik
Lenar,

you will be the first to do that. So you can imagine what does it mean to be the first in the industry.

:smt023

Posted: Fri May 26, 2006 1:02 pm
by Lenar
Thanks for kind words, Michal.

But... hmm, its not realized yet:)

Posted: Fri May 26, 2006 1:25 pm
by michal.kreslik
I know, I am posting this to motivate you to do it soon BigGrin_Smile