You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Read about working with frames.
Here is this code:
inNum=0;
{ // Read the corresponding optimised input parameters
Print("GLOC = ",GLOC);
Forum on trading, automated trading systems and testing trading strategies.
Libraries: TesterCache
fxsaber, 2019.11.11 04:45 pm.
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
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.
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?
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.
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