Libraries: MultiTester - page 40

 
klycko results of optimisation into an Excel table and into the optimisation cache file?
See reading opt-files.
How to open cache optimization file (.opt), MT5
How to open cache optimization file (.opt), MT5
  • 2020.07.30
  • DDamasceno
  • www.mql5.com
Hi, Is there a way to open Metatrader 5 optimization cache file (folder -> tester/cache/) with another software and export the data in...
 
klycko optimisation results to an Excel spreadsheet

Read about working with frames.

Документация по MQL5: Работа с результатами оптимизации
Документация по MQL5: Работа с результатами оптимизации
  • www.mql5.com
Функции для организации собственной обработки результатов оптимизации в тестере стратегий. Могут вызываться при оптимизации в агентах тестирования...
 
Good afternoon!

With the help of TesterCache, MultiTester, TypeToBytes libraries.
I have developed an optimisation program, but there is some insurmountable error in it.

I have localised it:
After running the procedure Run(Contr);
The following lines try to read the best parameters from the Cache found during this Run run.
And then these parameters are printed and the script stops.

Here is this code:

inNum=0;

Run(Contr); // Run optimisation on the values of the selected parameter

prWrite = MTTESTER::SetSettings2(Sohran); // Restore the saved settings to the robot
prRead = MTTESTER::GetSettings(Contr); // Read the robot settings to control them
Print("prWriteSettings = ",prWrite," prReadSettings = ",prRead);
Print("SettingEnd Odinar ",Kol," PoseY = ",PoseY," Iteration ",IterNumber,"\n",Contr);

if(prRead && TypPar == 0) // Read optimisation Cache for double-parameter

{ // Read the corresponding optimised input parameters


int GLOC = MTTESTER::GetLastOptCache(Bytess);

Print("GLOC = ",GLOC);


const int Size = Cache.GetInputs(inNum,Paramas);
Print(Cache[inNum].ToString()); // Print statistics of the requested record
Print(Cache.Header.ToString()); // Print the main data of the optimisation Cache
Print("Paramas\n");
ArrayPrint(Paramas); // Print its optimised input parameters
Print(Cache[GetMaxProfitPos(Cache)].ToString()); // Print the statistics of the record with maximum profit

ProfitNow = Cache[GetMaxProfitPos(Cache)].profit; // Maximum profit
int NomProchodaMaxProfit = Cache[GetMaxProfitPos(Cache)].Pass; // Number of the pass with maximum profit
int IndexMaxProfit = GetMaxProfitPos(Cache); // Array index with the parameter value
Cache.GetInputs(IndexMaxProfit,Paramas);

ParamMax = Paramas[0,1].double_value; // The value of the parameter at which the maximum profit is reached

Alert("ProfitNow =",ProfitNow," ParamMax=",ParamMax," Odinar ",Kol," PoseY = ",PoseY," PosEq = ",PosEq," TypPar = ",TypPar," Iteration ",IterNumber);
return;



However, the parameters found and printed out correspond to some former opt file, not the one obtained by running Run !!!!
Maybe I am accessing Cache.GetInputs(inNum,Paramas) incorrectly?

The Run procedure itself worked fine, it follows from the previous printouts in the log.

Why is it still not possible to get fresh data from Cache?

Thank you in advance for any advice.

Regards, Alexander
Библиотеки: TesterCache - Что такое 0xCACA?
Библиотеки: TesterCache - Что такое 0xCACA?
  • 2019.08.31
  • Good Beer
  • www.mql5.com
Да и дальше взаимодействия с Оптимизатором нет никакого. в кеше Оптимизатора по каждому проходу хранятся все стат. Бонусом идет возможность запуска любого прохода из обновленной таблицы стандартными средствами в два щелчка
 
klycko #:
int GLOC = MTTESTER::GetLastOptCache(Bytess);
You have received the opt file into a byte array. Next, you need to feed it into the Cache.

Forum on trading, automated trading systems and testing trading strategies.

Libraries: TesterCache

fxsaber, 2019.11.11 04:45 pm.

void OnStart()
{
  uchar Bytes[];
  
  MTTESTER::GetLastOptCache(Bytes);
  
  TESTERCACHE<ExpTradeSummary> Cache;

  if (Cache.Load(Bytes)) // Read the optimisation cache.
  {
 
fxsaber #:
You have received an opt file in a byte array. Next, you need to feed it into Cache.

I corrected it as you said:


string Sohran,Contr;

MTTESTER::GetSettings(Sohran); // The current initial settings of the robot are read for temporary saving in Sohran.

prWrite = MTTESTER::SetSettings2(Odinar); // Set Odinar to robot settings

prRead = MTTESTER::GetSettings(Contr); // Read the robot settings that were just set.

Print("prWriteSettings = ",prWrite," prReadSettings = ",prRead);

Print("SettingBeg OdinarContr ",Kol," PoseY = ",PoseY," Iteration ",IterNumber,"\n",Contr);


Run(Contr[0]); // Run optimisation on the values of the selected Y parameter

int GLOC = MTTESTER::GetLastOptCache(Bytess); // Get opt file into Bytess byte array

TESTERCACHE<ExpTradeSummary> Cache;

bool CL = Cache.Load(Bytess); // Feed the Bytess byte array into Cache

ProfitNow = Cache[GetMaxProfitPos(Cache)].profit; // Maximum profit

int NomProchodaMaxProfit = Cache[GetMaxProfitPos(Cache)].Pass; // Number of the pass with maximum profit

int IndexMaxProfit = GetMaxProfitPos(Cache); // Index of the array with the value of the parameter https://www.mql5.com/ru/forum/318998/page2#comment_13846951

Cache.GetInputs(IndexMaxProfit,Paramas);

ParamMax = Paramas[0,1].double_value; // The value of the parameter at which the maximum profit was achieved


Alert("CL=",CL," GLOC = ",GLOC," GLOC," ProfitNow =",ProfitNow," ParamMax=",ParamMax," Odinar ",Kol," PoseY = ",PoseY," PosEq = ",PosEq," TypPar = ",TypPar," Iteration ",IterNumber);

return;



The result is still wrong.

For some reason ProfitNow and ParamMax data from some former run are read from the cache.

Regards, Alexander

Библиотеки: TesterCache - Что такое 0xCACA?
Библиотеки: TesterCache - Что такое 0xCACA?
  • 2019.08.31
  • Good Beer
  • www.mql5.com
Да и дальше взаимодействия с Оптимизатором нет никакого. в кеше Оптимизатора по каждому проходу хранятся все стат. Бонусом идет возможность запуска любого прохода из обновленной таблицы стандартными средствами в два щелчка
Files:
 
klycko #:

For some reason, ProfitNow and ParamMax data from some former run are read from the cache.

Does this script show correct values after Optimisation?

If yes, then the problem is most likely that the opt-file is not ready right after Optimisation. You can try to put Sleep after Run. Or Run is not working properly.

Библиотеки: TesterCache - Что такое 0xCACA?
Библиотеки: TesterCache - Что такое 0xCACA?
  • 2019.08.31
  • Good Beer
  • www.mql5.com
Да и дальше взаимодействия с Оптимизатором нет никакого. в кеше Оптимизатора по каждому проходу хранятся все стат. Бонусом идет возможность запуска любого прохода из обновленной таблицы стандартными средствами в два щелчка
 
fxsaber #:

Does this script show the correct values after Optimisation?

If yes, the problem is most likely that the opt file is not ready right after Optimisation. You can try to put Sleep after Run. Or Run is not working properly.

Thanks! I'll check all this tomorrow.

But now I found out that if I set optimisation by a new parameter, everything works correctly.

So it seems to me that the whole point is that the tester, if you re-set an optimisation that already worked earlier, does not actually process it again, but just retrieves the previous result from memory.

Couldn't something be invented to destroy this memory of the tester beforehand?

 
klycko #:

So it seems to me that the whole point is that the tester, if you re-set a previously running optimisation, does not actually process it again, but simply retrieves the past result from memory.

Your hypotheses are wrong. The problem is in the code you have written.

 
fxsaber #:

Your hypotheses are wrong. The problem is the code you wrote.

Good afternoon!


I agree with you that "The problem is in the code I wrote". The error is in it, and I don't know how to fix it yet.

However, I have experimentally found that if you manually remove all opt files before running Run.

from the "C:\Users\ASUSAppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\Tester\cache" folder,

then my code works correctly and performs optimisation on the selected parameter.

If this folder is not cleaned, the Tester does not perform repeated optimisations (with the same unchanged data), but reads out

already existing opt-file from this folder. This can be clearly seen when repeatedly running the same optimisation manually.

It can be seen that the actual optimisation is only performed the first time, and then only reads the opt file from the folder.

This repeated reading does not seem to update the contents of the cache, and this is what is causing the error in my code.


Clearing said folder might help to resolve the error. Of course, this is a bad solution, and it would be more elegant to be able to restore the right data in the cache.

But I don't know how to do that. For now, the data from the previous real optimisation is hanging in the cache (not matching the re-read from the folder).


Unfortunately, this folder cannot be cleaned from the script using FolderClean, because it is forbidden in MQL5.

it is out of the "sandbox" and is filled only by the Strategy Tester.


Maybe you should create some external add-on by means of C++ and run it from the script.


Regards, Alexander

 
The Run procedure works perfectly. It writes Settings and presses the Start button. Everything is normal.