backtest and optimization from within an EA

 

Hello,

it seems to me that the normal use of the strategy tester optimization is (i) design the EA (ii) optimize some parameter (iii) let the EA run with the optimized parameter.

but, is it also possible to accomplish an optimization while the EA is running? As an Example:

consider an EA based on a moving average using a variable number M of previous bars (or whatever...my question is only on the principles). Is it possible to optimize the parameter M dynamically by performing such an optimization resp. a backtest from within the EA?

So, when the EA is started it shall first optimize M based on a certain period of time in the past, and then use this M for a chosen next period of time, until the backtest is repeated and M is adapted again.

I hope it became clear what I mean.

Thanks in advance,

David

 
It's possible, but will require coding a virtual trading system within your EA and it will run very slowly.
 
Thank you for your answer. Can you please give me some more information or links on such virtual trading systems? What are they, what do they do, ... ?

I would have tried to write a function that takes the tick history stored in an array, performs test trades according to some criteria and returns the net win. Then I would go through the criteria and take the optimal value. I have no experience in mql5 (however a lot in C++), but I would not have expected this function to take all too long (at least for a small set of criteria)...?

Generally, don't you feel like that this is an essential feature? Why should you use a static EA when you can have one that is all the time dynamically optimized and the best adapted to the current market situation?

Best, David
 
guntron:

Thank you for your answer. Can you please give me some more information or links on such virtual trading systems? What are they, what do they do, ... ?


They trade :). Your EA would use internal variables to store each virtual position's entry point, stop-loss, take-profit and would track its profit/loss, closing it (virtually) when needed. It would also track the overall profit/loss. Quite a simple concept.

guntron:

Generally, don't you feel like that this is an essential feature? Why should you use a static EA when you can have one that is all the time dynamically optimized and the best adapted to the current market situation?
Because a system that is adapted to the recent market movements won't necessarily perform well in the current market situation.
 

How do we achieve? Are there any codes, articles, ideas, etc?
 
Good ideas!There are a lot of articles in the forum.You can read the following articles:

https://www.mql5.com/en/articles/143
https://www.mql5.com/en/articles/283
https://www.mql5.com/en/articles/125
https://www.mql5.com/en/articles/112
https://www.mql5.com/en/articles/55

they all are aboout self-optimization or self-adaption,
you can also realize it by neural network.
there are a lot of work to do!!:)
Adaptive Trading Systems and Their Use in the MetaTrader 5 Client Terminal
  • 2010.09.14
  • MetaQuotes Software Corp.
  • www.mql5.com
This article suggests a variant of an adaptive system that consists of many strategies, each of which performs its own "virtual" trade operations. Real trading is performed in accordance with the signals of a most profitable strategy at the moment. Thanks to using of the object-oriented approach, classes for working with data and trade classes of the Standard library, the architecture of the system appeared to be simple and scalable; now you can easily create and analyze the adaptive systems that include hundreds of trade strategies.
Reason: