//Selecting a strategy, symbol, deposit share and values of five indicator buffers (you can change the number of buffers by changing OptParamCount)
#include     "GAModule.mqh"
#include     "MustHave.mqh"
//Creating a new strategy, prepare it in the form of an include file, add a link to it after the last one and number it in comments,...
//...include the number of the last strategy in the StratCount variable
#include     "StrategyMA.mqh"                                        //Strategy 0 - moving averages
#include     "StrategySAR.mqh"                                       //Strategy 1 - SAR Breakthrough
#include     "StrategyStoch.mqh"                                     //Strategy 2 - stochastic

input double trainDD=0.5;                                            //Maximum possible balance drawdown in training
input double maxDD=0.2;                                              //Balance drawdown, after which the network is re-trained in real trading
int          StratCount=2;                                           //The number of written and attached strategies
int          OptParamCount=5;                                        //The number of indicator buffers to optimize
int          strat=0;                                                //The strategy chosen by an optimizer,...
                                                                     //...Pre-penultimate gene in the chromosome (initialize 0 - лю)
string       s="EURUSD";                                             //The pair selected by the optimizer,...
                                                                     //...The penultimate gene in the chromosome (initialize EURUSD)
double       optF=0.3;                                               //Deposit share in trading chosen by the optimizer,...
                                                                     //...The last gene in the chromosome (initialize 0.3)
bool         trig=false;                                             //No open positions (true - there are no open positions)

int OnInit()
{
  tf=Period();                                                       //Test and trade on the period of the chart with the Expert Advisor
  prevBT[0]=D'2001.01.01';                                           //For bar-to-bar test..
  TimeToStruct(prevBT[0],prevT);                                     //... Long ago
  depth=10000;                                                       //History depth (should be set since the optimization is based on historical data)
  count=2;                                                           //Copies at a time (should be set since the optimization is based on historical data)
  InitArrays();                                                      //Necessarily initialize rge arrays required for the operation of GA
//The number of initializations of indicator buffers must be equal to the number of strategies
  OnInitMA();                                                        //Initialize arrays of MA
  OnInitSAR();                                                       //Initialize arrays of SAR
  OnInitStoch();                                                     //Initialize arrays of stochastic
  GA();                                                              //Call the genetic optimization function
  GetTrainResults();                                                 //Receive optimized parameters from GA
  InitRelDD();                                                       //Receive the current real balance drawdown
  return(0);
}

void OnDeinit(const int reason)
{
}

void OnTrade()
{
}

void OnTick()
{
  if(isNewBars()==true)
  {
    trig=false;
    switch(strat)
    {
      case  0: {trig=NeedCloseMA()   ; break;};                      //The number of case strings must be equal to the number of strategies
      case  1: {trig=NeedCloseSAR()  ; break;};
      case  2: {trig=NeedCloseStoch(); break;};
      default: {trig=NeedCloseMA()   ; break;};
    }
    if(trig==true)
    {
      if(GetRelDD()>maxDD)                                           //if the drawdown has exceeded the allowable value:
      {
        GA();                                                        //Call the genetic optimization function
        GetTrainResults();                                           //Receive optimized parameters
        maxBalance=AccountInfoDouble(ACCOUNT_BALANCE);               //Now count the drawdown not from the balance maximum...
                                                                     //...but from the current balance
      }
    }
    switch(strat)
    {
      case  0: {trig=NeedOpenMA()   ; break;};                       //The number of case strings must be equal to the number of strategies
      case  1: {trig=NeedOpenSAR()  ; break;};
      case  2: {trig=NeedOpenStoch(); break;};
      default: {trig=NeedOpenMA()   ; break;};
    }
    Print(TimeToString(TimeCurrent()),";","Main:OnTick:isNewBars(true)",
          ";","strat=",strat);
  }
}