Multiple Optimization MT5

 
Hello folks!

There is one thing that I don't understand (after reading the documentation), and it is: can an EA be optimized in MT5 for different symbols simultaneously?  

I know I can test a few parameters for different symbols with "market watch", but I want to get the single parameters that work best on multiple symbols.  

Thanks in advance
 
Enrique Enguix:
Hello folks!

There is one thing that I don't understand (after reading the documentation), and it is: can an EA be optimized in MT5 for different symbols simultaneously?  

I know I can test a few parameters for different symbols with "market watch", but I want to get the single parameters that work best on multiple symbols.  

Thanks in advance

This won't be the proper answer as there are many many many more experienced in backtesting than me but first question that comes to mind is are the parameters standardized ?

So , a simple example is have a "unit" which is the spread or the atr and then set the stops based on this unit .So the backtester will try to find how an elastic band better bends and not how a rigid stick fits best on everything.

For instance , let me portray a silly example :

Let's say you have a simple trader that looks at the previous 2 formed candles and makes a decision . 

You provide an atr period and all the relations of the 2 candles as multiples of this atr alongside switches for which relations matter.

Then stops and profits as multiples of this atr again .

So the genetic algorithm of the MT5 will try to find the best atr period , which relations matter the most and what ratios of them and the stops as well , all elastic all pertinent to the "simple volatility measurement" of each asset .(of course in this case the spread becomes a problem but in the best solution if a spread is wide for an asset then that asset will have the least loss as its individual best configuration)

edit : also in this example you are constraining your system to one candle pattern

 
Lorentzos Roussos #:

This won't be the proper answer as there are many many many more experienced in backtesting than me but first question that comes to mind is are the parameters standardized ?

So , a simple example is have a "unit" which is the spread or the atr and then set the stops based on this unit .So the backtester will try to find how an elastic band better bends and not how a rigid stick fits best on everything.

For instance , let me portray a silly example :

Let's say you have a simple trader that looks at the previous 2 formed candles and makes a decision . 

You provide an atr period and all the relations of the 2 candles as multiples of this atr alongside switches for which relations matter.

Then stops and profits as multiples of this atr again .

So the genetic algorithm of the MT5 will try to find the best atr period , which relations matter the most and what ratios of them and the stops as well , all elastic all pertinent to the "simple volatility measurement" of each asset .(of course in this case the spread becomes a problem but in the best solution if a spread is wide for an asset then that asset will have the least loss as its individual best configuration)

edit : also in this example you are constraining your system to one candle pattern

I've understood much of what you're saying, but I'm not sure I understood the relation to my question :)))

Thanks for your answer!

Edit: after rereading the text several times, I understood.  yes, I use a standard measure, specifically, and as you indicate in your text, the ATR.  But I wanted to get a set that works well (backtested) on various symbols, for various reasons, but mostly for educational purposes

I have seen that there are some libraries for it.  And I had also thought about having several symbols work in the same instance, graphic, of the EA, but neither of the two solutions convinces me
 
Enrique Enguix #:
I've understood much of what you're saying, but I'm not sure I understood the relation to my question :)))

Thanks for your answer!

Edit: after rereading the text several times, I understood.  yes, I use a standard measure, specifically, and as you indicate in your text, the ATR.  But I wanted to get a set that works well (backtested) on various symbols, for various reasons, but mostly for educational purposes

I have seen that there are some libraries for it.  And I had also thought about having several symbols work in the same instance, graphic, of the EA, but neither of the two solutions convinces me

Ow i'm sorry . I tried to "walk this forward" in how it would be constructed in my head and after some thinking i actually arrived at the same question :) .

Edit : if i understood (this time) the keyphrase here is "Multiple isolated optimizations , not manual" vs "One optimization with trading all of the assets" 
 
Enrique Enguix: Hello folks! There is one thing that I don't understand (after reading the documentation), and it is: can an EA be optimized in MT5 for different symbols simultaneously? I know I can test a few parameters for different symbols with "market watch", but I want to get the single parameters that work best on multiple symbols. Thanks in advance

The short answer is — No!

The longer answer is — Maybe (if you have access to the source code and can properly implement the optimisation result management, aka "frames").

Together with the "frames", you would also have to implement the Symbol selection via an Input Parameter as an index into a predefined list or available symbols on the Market Watch.

Documentation on MQL5: Working with Optimization Results
Documentation on MQL5: Working with Optimization Results
  • www.mql5.com
Working with Optimization Results - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

The short answer is — No!

The longer answer is — Maybe (if you have access to the source code and can properly implement the optimisation result management, aka "frames").

Together with the "frames", you would also have to implement the Symbol selection via an Input Parameter as an index into a predefined list or available symbols on the Market Watch.

So if you wanted to test in the single test you'd have to synchronize the ticks (apart from managing the symbols)? (like you and the other Enrique were talking about in the other thread about the offsets ?) 

Thank you 


 
Lorentzos Roussos #: So if you wanted to test in the single test you'd have to synchronize the ticks (apart from managing the symbols)? (like you and the other Enrique were talking about in the other thread about the offsets ?)
Sorry, but I did not understand your question. And what other thread are you referring too?
 
Fernando Carreiro #:
Sorry, but I did not understand your question. And what other thread are you referring too?

[i'll place the edit on top] :

<EDIT>

To clarify further if the OP wants to go about it in a sloppy way could he : ?

  • Run optimization in the Market Scanner mode 
  • Select the most profitable asets
  • Run a test in the Single Test mode with the most profitable assets as inputs in a version that can multitrade and optimize for those 

That is the proper wording of the question ,sorry for the confusion.

</EDIT> 

Sorry , this thread : https://www.mql5.com/en/forum/437672

I mean if the system takes trading decisions on each new bar then they can only be handled from the on tick of the "driver" symbol which would be the symbol that was selected for the single test .

This code for instance counts bars elapsed on each symbol since the start of the test 

#property version   "1.00"
input string symbols_to_trade="EURUSD,GBPUSD,USDJPY";//symbols 

struct my_symbol{
bool     _active;
string   _symbol;
double   _point;
int      _digits;
double   _vol_min,_vol_max,_vol_step,_stop_level;
datetime _barstamp;
int      _bars_elapsed;
         my_symbol(void){reset();}
        ~my_symbol(void){reset();}
    void reset(){
         _active=false;
         _bars_elapsed=0;
         _symbol=NULL;
         _point=0.0;
         _digits=0;
         _vol_min=0.0;
         _vol_max=0.0;
         _vol_step=0.0;
         _stop_level=0.0;
         _barstamp=0;
         }
    bool setup(string _the_symbol){
         int errors=0;
         ResetLastError();
         _symbol=_the_symbol;
         _digits=(int)SymbolInfoInteger(_symbol,SYMBOL_DIGITS);errors+=GetLastError();ResetLastError();
         _point=(double)SymbolInfoDouble(_symbol,SYMBOL_POINT);errors+=GetLastError();ResetLastError();
         _vol_min=(double)SymbolInfoDouble(_symbol,SYMBOL_VOLUME_MIN);errors+=GetLastError();ResetLastError();
         _vol_max=(double)SymbolInfoDouble(_symbol,SYMBOL_VOLUME_MAX);errors+=GetLastError();ResetLastError();
         _vol_step=(double)SymbolInfoDouble(_symbol,SYMBOL_VOLUME_STEP);errors+=GetLastError();ResetLastError();
         _stop_level=_point*((double)SymbolInfoInteger(_symbol,SYMBOL_TRADE_STOPS_LEVEL));errors+=GetLastError();ResetLastError();
         if(errors==0){
         _active=true;
         }
         return(_active);
         }
    bool check_for_new_bar(){
         ResetLastError();
         datetime now=iTime(_symbol,PERIOD_CURRENT,0);
         if(GetLastError()==0){
         if(now>_barstamp){
         _barstamp=now;
         _bars_elapsed++;
         return(true);
         }}
         return(false);
         }     
};
//symbol manager 
struct symbol_manager{
my_symbol symbols[];
          symbol_manager(void){reset();}
         ~symbol_manager(void){reset();}
     void reset(){
          ArrayFree(symbols);
          }
     void remove_symbol(int ix){
          int ns=ArraySize(symbols)-1;
          symbols[ix]=symbols[ns];
          if(ns>0){ArrayResize(symbols,ns,0);}
          else{ArrayFree(symbols);}
          }
      int add_symbol(string _the_symbol){
          int ns=ArraySize(symbols)+1;
          ArrayResize(symbols,ns,0);
          if(!symbols[ns-1].setup(_the_symbol)){
          remove_symbol(ns-1);
          return(-1);
          }
          return(ns-1);
          }
     void grab_symbols(string _symbols,string _separator,string _prefix,string _suffix){ 
          ushort u=StringGetCharacter(_separator,0);
          string s[];
          StringSplit(_symbols,u,s);
          for(int i=0;i<ArraySize(s);i++){
             if(StringLen(_prefix)>0){s[i]=_prefix+s[i];}
             if(StringLen(_suffix)>0){s[i]=s[i]+_suffix;}
             add_symbol(s[i]);
             }
          }
     void manage_symbols(){
          for(int i=0;i<ArraySize(symbols);i++){
             symbols[i].check_for_new_bar();
             }
          }
   string get_bars_status(string separator){
          string result="";
          for(int i=0;i<ArraySize(symbols);i++){
          result+=symbols[i]._symbol+"["+IntegerToString(symbols[i]._bars_elapsed)+"]";
          if(i<ArraySize(symbols)-1){result+=separator;}
          }
          return(result);
          }
};
symbol_manager MANAGER;

int OnInit()
  {

  MANAGER.reset();
  MANAGER.grab_symbols(symbols_to_trade,",","","");
  return(INIT_SUCCEEDED);
  }

void OnTick()
  {
//---
  MANAGER.manage_symbols();
  string comm=MANAGER.get_bars_status("\n");
  Comment(comm); 
  }
Bar (Time) lag in CopyRates on symbol other then current chart in open prices only mode.
Bar (Time) lag in CopyRates on symbol other then current chart in open prices only mode.
  • 2022.12.08
  • www.mql5.com
Take the following EA: When run with these settings: The result a lag of 30 minutes on M30 timeframe, 1 bar...
 
Lorentzos Roussos #:[i'll place the edit on top] : <EDIT> To clarify further if the OP wants to go about it in a sloppy way could he : ?

  • Run optimization in the Market Scanner mode 
  • Select the most profitable asets
  • Run a test in the Single Test mode with the most profitable assets as inputs in a version that can multitrade and optimize for those 

That is the proper wording of the question ,sorry for the confusion.</EDIT> 

Sorry , this thread : https://www.mql5.com/en/forum/437672.

I mean if the system takes trading decisions on each new bar then they can only be handled from the on tick of the "driver" symbol which would be the symbol that was selected for the single test . This code for instance counts bars elapsed on each symbol since the start of the test 

The OP's question is not about a multi-symbol strategy. It is about an EA for single symbol trading.

However, he wishes to optimise to find the parameters that work best overall for all the symbols.

Unfortunately the Strategy Tester is unable to do that. Mainly because there is no metric/equation/formular for that.

How would one rate the best option? Would one analyse the average net profit over multiple symbols, or maybe on the profit factor? How would one consider the variance in the metrics?

In other words, he would have to define for himself how he wants to weigh each metric and each symbol, to come up with a Custom Complex Criterion of his own, and in so doing manage the optimisation frames to guide the testing.

I've never attempted this myself, and that is why I stated "maybe". In theory it seems plausible, but I don't know how much work it will take. It may even require some extra steps to process the final reports to come to a final conclusion.

 
Fernando Carreiro #:

The OP's question is not about a multi-symbol strategy. It is about an EA for single symbol trading.

However, he wishes to optimise to find the parameters that work best overall for all the symbols.

Unfortunately the Strategy Tester is unable to do that. Mainly because there is no metric/equation/formular for that.

How would one rate the best option? Would one analyse the average net profit over multiple symbols, or maybe on the profit factor? How would one consider the variance in the metrics?

In other words, he would have to define for himself how he wants to weigh each metric and each symbol, to come up with a Custom Complex Criterion of his own, and in so doing manage the optimisation frames to guide the testing.

I've never attempted this myself, and that is why I stated "maybe". In theory it seems plausible, but I don't know how much work it will take. It may even require some extra steps to process the final reports to come to a final conclusion.

I'll disagree here due to the statement of the OP that he has already accounted for universal inputs .

So if we accept the following assumptions :

  • The tester in a single test if called upon to trade other symbols in every tick with real ticks mode will provide real ticks for all assets and not just the "driver" asset
  • The genetic algorithm of the tester has a static mutation rate 

(which are both unknowns for now , for me)

Then we create a multisymbol ea , with universal inputs , and have it optimize over 20 symbols (as a whole) , but as you said provide a custom criteria for optimization -due to the fact the ommision of bad/good signals here because of testing within the constraints of a trading account will be detrimental- then the individual best of each asset will also be the assets best if tested on its own the same way.

Which means that this would give the OP a baseline set of parameters with which he could then perform individual tests with balance as criterion for each asset (using the handy market scanner method). So instead of starting from anything he'd start from the baseline . 

Now if the mutation rate of the Tester's algorithm is variable , i.e. adjusts to the performance somehow , then there would be no point in finding the baseline parameters and would be better off going straight to the "market scanner" test method , pick the best of the bunch and share the sets with his users.

PS : If he provides a custom "value" as a criterion can't the tester pick this up on its own in the frame and just rank it at the end of the optimization ? Meaning isn't the OP able to provide the fitness value of the current "frame" without accessing the frames ? (i'm asking because i don't know this :) )

Thanks 

 
In my head it looked like: select 3 pairs (for example), eurusd, gbpusd and usdcad.  And obtain in the different columns the data of the 3 symbols together as a portfolio.  Profit, DD, Profit Factor, ... I thought it would be relatively easy, but it shouldn't be that much.  I think I'll finally edit the code so that it opens and closes trades on all 3 symbols, with the same parameters.  (Also this sounds easy in my head, maybe it's not at all).  Thank you both very much for your wonderful help, it is a pleasure to be surrounded by some people with such valuable knowledge and experience.
Reason: