help custom genetic algorithms in mql5

 
input  uint PeriodsADX=5;
input double LivelADX=20;
uint Adx1;
uint contatoreADX=0;

double ADXmax,ADXmin=999999999999999;
//enum MY_TF1{A_M5= PERIOD_M5,A_M10=PERIOD_M10,A_M15=PERIOD_M15,A_M20=PERIOD_M20,A_M30=PERIOD_M30, A_H1= PERIOD_H1, A_H2= PERIOD_H2, A_H3= PERIOD_H3, A_H4= PERIOD_H4,A_H12= PERIOD_H12,A_D1= PERIOD_D1};
//input MY_TF1 A_TF = A_M5; 
 ENUM_TIMEFRAMES A_TF=PERIOD_M1;
void OnTesterInit()
{                  //var,abilita,parametro,start,step,stop
  // ParameterSetRange("PeriodsADX", true, 5,    5,   1,10000);

  
}

void OnTesterDeinit(){   } 

 bool resetCont=true;
int OnInit()
  {  
 Adx1=iADX(Symbol(),(ENUM_TIMEFRAMES)A_TF,PeriodsADX);
  return(0);
  }
void OnTick()
  {
//---

  double myMArray1[];
  ArraySetAsSeries(myMArray1,true);
  CopyBuffer(Adx1,0,0,1,myMArray1);//ADX
  double ADX=myMArray1[0];
  ArraySetAsSeries(myMArray1,true);
  CopyBuffer(Adx1,1,0,1,myMArray1);//+DI
  double DIplus=myMArray1[0];
  ArraySetAsSeries(myMArray1,true);
  CopyBuffer(Adx1,2,0,1,myMArray1);//-DI
  double DImeno=myMArray1[0];
  string Activatrade="";
  if(ADX>ADXmax) {ADXmax=ADX;}
  if(ADX<ADXmin){ ADXmin=ADX;}
  if(ADX>LivelADX&&resetCont){contatoreADX++;resetCont=false;}
  if(ADX>LivelADX&&resetCont==false){resetCont=true;}
  
  else Activatrade="SELL";
   
   Comment(A_TF,"          ADX ",ADX,"\n","          DIplus ",DIplus,"\n",
   "          DImeno ",DImeno,"\n","          contatoreADX ",contatoreADX,"          LivelADX ",LivelADX);
   
  }
void OnDeinit(const int reason)
  {
  Print("contatoreADX ",contatoreADX);
  Print("ADXmax ",ADXmax," ADXmin ",ADXmin);
  Print("TF ",A_TF);
  
  }
double OnTester(void)
  {
  
  return(ADXmax);
  
  }

Hi, I have made this indicator / EA, I have some problems, see attached photos (GA3).

thanks.

Files:
GA3.jpg  489 kb
GA2.jpg  380 kb
GA1.jpg  411 kb
 
SergioTForex:

Hi, I have made this indicator / EA, I have some problems, see attached photos (GA3).

thanks.


Try to use "Every Tick" instead of "Open Prices Only", you should get much better and precise results (unless your expert was made programatic specifically to run only when the candle opens)


The step column sometimes appears like decimal, I supposeit is related to multiple processors passes and the genetic tree, like a "derived" step.. or something like that..

What is important, is: that column does not matter at all, is just informative of the stepping progress of the test.


Also, there is something wrong on your Custom Max OnTester() function, because on image3 I can see results on the second column, but there is no operations at all.

If you change the config to use the "Complex Criterion Max" what kind of results does it produces?


UPDATEL

Sorry, I have't noticed that you sent the OnTester() custom function on the code above: Its is totally wrong.You cannot return that information to the tester.

The return must be some kind of calculations of Scores.


Use my Custom OnTester() function below, which returns correct Scores to the Genetic Tester.


double OnTester()
{

    double  param                 = 0.0;
    double  profit                = TesterStatistics(STAT_PROFIT);

    double  pfactor               = TesterStatistics(STAT_PROFIT_FACTOR);
    double  vendas                = TesterStatistics(STAT_SHORT_TRADES);
    double  compras               = TesterStatistics(STAT_LONG_TRADES);
    double  total_trades          = TesterStatistics(STAT_TRADES);
    double  expected_payoff       = TesterStatistics(STAT_EXPECTED_PAYOFF);
    double  recover_factor        = TesterStatistics(STAT_RECOVERY_FACTOR);
    double  SharpeRatio           = TesterStatistics(STAT_SHARPE_RATIO);
    double PerdaConsecutiva       = TesterStatistics(STAT_MAX_CONLOSS_TRADES);
    double GanhoConsecutivo       = TesterStatistics(STAT_MAX_CONPROFIT_TRADES);
    double MargemLevelMin         = TesterStatistics(STAT_MIN_MARGINLEVEL);



    double  drawdown_pct          = TesterStatistics(STAT_EQUITY_DDREL_PERCENT); // Use DD Relative
//  double  drawdown_pct          = TesterStatistics(STAT_EQUITYDD_PERCENT);     // Use DD Max


    double  drawdown_pct_inverso = 0;
    if(drawdown_pct > 0 && drawdown_pct < 100) {
        drawdown_pct_inverso = (100 - drawdown_pct) / 100;
    } else {
        drawdown_pct_inverso = 1 / 100;
    }


    // Porcentual de trades com ganhos
    double win_perc = ((TesterStatistics(STAT_PROFIT_TRADES) + 1) / (TesterStatistics(STAT_LOSS_TRADES) + 1));


    // ------------------  Formula final -----------------------------------------------------
    double ret = (((drawdown_pct_inverso * 3) * recover_factor * (SharpeRatio * 1.2))); 

    ret = (ret * ((100 - drawdown_pct) / 100));         // Quanto maior o drawndown, menor o resultado.
    ret = ret * win_perc;// * 100;                      // Multiplico pelo porcentual de acertos

    if (ret > 0 && profit < 0) {                        // retorno positivo somente se profit tbem.
        ret = -ret;
    }
// ---------------------------------------------------------------------------------------

    /* Envio o resultado ao Treinador */
    return(ret);
}



Another thing, your EA code, does not have any command to do any operations at all..

I suggest you get some examples and take a look on other EA source codes, for you to be able to implement a full set of Open, Close, and Trail functions. 

 
rrocchi:


Another thing, your EA code, does not have any command to do any operations at all..

I suggest you get some examples and take a look on other EA source codes, for you to be able to implement a full set of Open, Close, and Trail functions. 

Thank you very much for the reply, but mine is an indicator written in an EA, I am evaluating the custom criteria of the ADX.

  with tick by tick it would take me a long time.

For other applications I will refer to your code

 

This is the test performed every tick, the results are attached.

Files:
GA4.jpg  494 kb
 
SergioTForex:

This is the test performed every tick, the results are attached.

Still I can't understand what means an indicator inside an EA.. yes I know it is common and normal to do. I myself put indicator code inside EAs I write.

But as far as I understand, the result of a EA tester, must result some kind of score.. and must include operations of Buy and Sell.. otherwise how could I know which indicator setup (the indicator inside de EA) would be best? without performing any operation.


All indicators I evaluate under Visual Mode. All EAs I need it to make it perform some operation.


I may be getting wrong what is your objective for the test, sorry. 

I would like to ask you, for my understanding, what you want/expect to have as a result? or What are you trying to evaluate?

Please give me more details so I can understand better and help you reach your objective. 

 
I realized that the GA does not work with the custom column
Reason: