How I can add my own column in Strategy optimizer?

 

Hello everyone,

I am trying to print my own values in the Optimization result along with the values originally displayed by it. See the image:  

testing


One can see Pass, Result,Profit,TotalTrades, and rsi_period. If I want to add my own values line win percentage, loss percentage, amount left, then how I can add it in the Optimization result window column?

Please guide.

 
jafferwilson:

Hello everyone,

I am trying to print my own values in the Optimization result along with the values originally displayed by it. See the image:  


One can see Pass, Result,Profit,TotalTrades, and rsi_period. If I want to add my own values line win percentage, loss percentage, amount left, then how I can add it in the Optimization result window column?

Please guide.

Add a function 

double OnTester()

{

}

in your EA and return the value you want to show. Only one double value possible, unfortunately.

 
all the values are doube. but there is only one value that can be returns. I want to return: win percentage, loss percentage, amount left etc.
 
Heinrich Munz:

Add a function 

double OnTester()

{

}

in your EA and return the value you want to show. Only one double value possible, unfortunately.

See this:  

double OnTester()
{
   return(amount);
}

I tried but nothing happened.

 
Is there anyone from the forum can answer this question of mine? Most of the time I do not get answer in the English forum. I do not understand the reason.
 

Would be cool to have but I think it's not possible yet.

To work around you can stash all of your columns into one single value:

double OnTester()
  {
   return NormalizeDouble((int)amount*10000 + (int)winpct + (int)losspct*0.01,2);
  }

So in the results column you get something like 101760034.65 from where you have to deduct the three values.

 

possible workaround:

1. call a function in OnTester() to write all values for your input settings and trading results into a .csv file

2. let MQL automatically convert all commas into points --> because that's the usual format for excel (or e.g. libre office calc)

3. open csv file (common files folder) in excel (with default import settings) and sort the columns by whatever you want to optimize

here's an example from some old EA of mine (you just have to put in your own variable names):

//+------------------------------------------------------------------+
//| write optimization results to file                               |
//+------------------------------------------------------------------+
void safe_optimization_results(string filename)
  {
   int filehandle;
   if (!FileIsExist(filename))
     {
      filehandle=FileOpen(filename+".csv",FILE_WRITE|FILE_READ|FILE_COMMON|FILE_CSV,';');
                            // write general header
      FileWrite(filehandle,"symbol","initial deposit","gross profit","gross loss","net result","official result","trades","profit factor","total fees","total swap",
                           "max drawdown","lots","max. net equity","annualized return","annual return after tax","net result after tax",
                           "biggest winner","biggest loser","max.consec.winners","max.consec.losers","winners","losers","Kelly%",
                           "weekend rule","commission per lot","basic risk","never exceed risk","max. Kelly%",
                           // write EA specific header
                           "PRT periods","min entry stdev","max exit stdev","slow PRT timeframe","PRT power","min fast PRT slope","min slow PRT slope","slow first","fast smoothing","slow smoothing",
                           "only slow confirmed","sl ATR method","SL ATR","sl pips","sl trailing","downsize rule","downsize target","upsize rule","upsize target","max drawdown",
                           "drawdown compensation");
     }
   else
     {
      filehandle=FileOpen(filename+".csv",FILE_WRITE|FILE_SHARE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_COMMON|FILE_CSV,';');
     }
      // get additional account figures
      double winrate=0,profitfactor=0;
      if (account.loss_total!=0){profitfactor=account.profit_total/account.loss_total;}
      double years=(double)(TimeCurrent()-EA_starttime)/31557000;
      double annualized_return=pow(account.netbalance/account.initbalance,1/years)-1;
      double annual_return_after_tax=annualized_return*(1-taxrate);
      double total_result_after_tax=account.initbalance*pow(1+annual_return_after_tax,years)-account.initbalance;

      // write results
      FileSeek(filehandle,0,SEEK_END);
                           // general data
      FileWrite(filehandle,_Symbol,account.initbalance,xlnumber(account.profit_total,2),xlnumber(account.loss_total,2),xlnumber(account.netbalance-account.initbalance,2),
                           xlnumber(AccountInfoDouble(ACCOUNT_BALANCE)-account.initbalance,2),
                           account.total_trades,xlnumber(profitfactor,2),xlnumber(account.total_fees,2),xlnumber(account.total_swap,2),
                           xlnumber(account.maxdrawdown,2),xlnumber(account.total_lots_traded,2),xlnumber(account.maxequity,2),xlnumber(annualized_return,4),
                           xlnumber(annual_return_after_tax,4),xlnumber(total_result_after_tax,2),xlnumber(account.biggestwinner,2),xlnumber(account.biggestloser,2),
                           account.maxconsecwinners,account.maxconseclosers,account.winners,account.losers,xlnumber(account.Kelly,3),
                           tradeweekend_inp,xlnumber(commission_per_lot,2),xlnumber(BasicRiskPerTrade,3),xlnumber(NeverExceedRisk,3),xlnumber(maxKelly,3),
                           // EA specific data
                           PRT_periods,min_stdev,exit_stdev,slow_PRT_tf,PRT_power,xlnumber(min_fastslope,2),xlnumber(min_slowslope,2),slow_first,fast_PRT_smoothing,
                           slow_PRT_smoothing,slow_confirm,sl_ATR_method,sl_ATR,sl_pips,sl_trail,xlnumber(DownsizeRule,2),xlnumber(DownsizeTarget,2),xlnumber(UpsizeRule,2),
                           xlnumber(UpsizeTarget,2),xlnumber(MaxDrawdown_inp,2),drawdown_compensation);
      FileClose(filehandle);
   return;
  }
  
//+------------------------------------------------------------------+
//| convert numbers to excel format                                  |
//+------------------------------------------------------------------+
string xlnumber(double number,int digits)
  {
   string stringnumber=DoubleToString(NormalizeDouble(number,digits));
   StringReplace(stringnumber,".",",");
   return stringnumber;
  }

[edit/remark: you should check the filehandle of course.... as I said.. it's from an OLD ea, but it works];

by the way: this method creates ONE file for all optimization passes, so not hundreds of files for one genetic optimization; the "SEEK_END" flag makes sure that the data for any new pass will be written to the end of the file

Reason: