Detect optimization mode programmatically

 

Sorry if this has been asked before but I'm finding it a bit difficult to search for.

I have an expert that writes out a lot of information to CSV files.  The problem is, if I forget to turn this off before I start optimization, it will write these CSV files for every thread that it uses.  These then gobble-up all the disk space and the optimization run fails.

The ideal solution to this would be detecting when using optimization mode or where the EA is running on a thread other than the first thread normally used by back-testing, and then disable the CSV output.

Does anyone know how I can achieve this?

 
chris_turner:

Sorry if this has been asked before but I'm finding it a bit difficult to search for.

I have an expert that writes out a lot of information to CSV files.  The problem is, if I forget to turn this off before I start optimization, it will write these CSV files for every thread that it uses.  These then gobble-up all the disk space and the optimization run fails.

The ideal solution to this would be detecting when using optimization mode or where the EA is running on a thread other than the first thread normally used by back-testing, and then disable the CSV output.

Does anyone know how I can achieve this?

https://www.mql5.com/en/docs/event_handlers

Documentation on MQL5: Event Handling
Documentation on MQL5: Event Handling
  • www.mql5.com
The MQL5 language provides handling of certain predefined events. The functions for handling these events should be defined in an MQL5 program: function name, return type, a set of parameters (if any) and their types should strictly correspond to the description of an event handling function. The client terminal event handler uses the return...
 

I'm not sure how that answers the question.  Is there something I'm missing here?

 
chris_turner:

I'm not sure how that answers the question.  Is there something I'm missing here?

I understand about the Tester events but what I want to know is how to detect 'Optimization'.

 
enum termnal_Mode{  MODE_DEBUG, MODE_LIVE, MODE_VISUAL, MODE_OPTIMIZER};
termnal_Mode     get_modus_operandi(void){
   if (IS_DEBUG_MODE)                     return MODE_DEBUG;   // debugging.
   if (!MQLInfoInteger(MQL_TESTER) )      return MODE_LIVE;    // IsTesting()
   if ( MQLInfoInteger(MQL_VISUAL_MODE) ) return MODE_VISUAL;  // IsVisualMode()
                                          return MODE_OPTIMIZER;
}
 
chris_turner:

I understand about the Tester events but what I want to know is how to detect 'Optimization'.

OnTesterInit  is called before optimization starts, allowing you to make decisions based upon that.

and William's method allows you to detect it anywhere in your code

regards


https://www.mql5.com/en/docs/event_handlers/ontesterinit

Documentation on MQL5: Event Handling / OnTesterInit
Documentation on MQL5: Event Handling / OnTesterInit
  • www.mql5.com
//|                                          OnTesterInit_Sample.mq5 | //|                        Copyright 2018, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| TesterInit function                                              |...
 
MQLInfoInteger(MQL_OPTIMIZATION)
 
Alain Verleyen:

That's the one I'm looking for.  Thanks Alain.

Reason: