Missing reports in generations funtion (MQL5)

 
Good afternoon community. I have a problem regarding the generation of specific reports via programming for each set of optimization parameters. I used the OnTester, OnTesterPass, and the AddFrame, NextFrame and InputFrame functions to store the ticket, balance, and results of each set and generate two .csv file for each set. And I managed to develop the code that can generate the reports for each set of parameters and stores the files in a MetaTrader folder. I use Mql5. However, in some situations, it cannot generate all the .csv files (reports). It skips some sets, but in MetaTrader, it goes through all the sets and shows all of them (Pass) in the Optimization Results tab, but it does not generate some reports. Sometimes there are only a few missing, sometimes there are many missing. I can't understand why this happens, since in some cases, it generates all the reports. Could someone suggest something? Some way? Reasons why this happens? Thank you very much for any help. There ares two figures to show the problems.
 
Please, show the related source code - otherwise no one can pinpoint what's wrong.
 
Stanislav Korotky #:
Please, show the related source code - otherwise no one can pinpoint what's wrong.

Hello Stanislav, I forgot to show the code. Here is the code

Files: