Experts: MQL5 Programming for Traders – Source Codes from the Book. Part 7 - page 5

 
thelux9 #:

This is exactly what I needed.

Please, make sure you got the latest update, because you quoted not the most recent one published on this thread.

 
Please fix it.
//+------------------------------------------------------------------+
//| Main class to read opt-file and export it to CSVs |
//+------------------------------------------------------------------+
class OptReader
{
   TesterOptCacheHeader header;
   TestCacheInputExtended inputs[];
   uchar bufferOfInputs[];
   int shapshot[];
   AutoPtr<RecordBase> records;
   
   bool read(const int handle)
   {
      SAFE(FileReadStruct(handle, header));
      if(header.parameters_total)
      {
         TestCacheInput temp[];
         SAFE(FileReadArray(handle, temp, 0, header.parameters_total));
         const int n = ArrayResize(inputs, header.parameters_total);
         for(int i = 0; i < n; ++i)
         {
            inputs[i] = temp[i]; // cannot convert parameter 'TestCacheInput' to 'const TestCacheInputExtended&'
            inputs[i].extend();
         }
      }


//+------------------------------------------------------------------+
//| Input struct with stringified fields |
//+------------------------------------------------------------------+
struct TestCacheInputExtended: public TestCacheInput
{
   using TestCacheInput::operator=;
 
fxsaber #:
Please fix it.


Thank you. I fixed it a bit differently.

struct TestCacheInputExtended: public TestCacheInput
{
   ...   
   void operator=(const TestCacheInput &other)
   {
      TestCacheInput::operator=(other);
      extend();
   }
};

It's more convenient and logical, because extend() doesn't need to be explicitly called.

NB: the attached file contains other useful edits.

Files:
OptReader.mqh  24 kb
 
Stanislav Korotky #:

Thank you. Fixed it a little differently.

It's more convenient and logical, because extend() doesn't need to be explicitly called.

NB: the attached file contains other useful edits.

Thanks, now it's even more practical.
 

Forwarded from another Topic:

Forum on trading, automated trading systems and testing trading strategies

CalendarRecordById.mq5 - Errors

Ryan L Johnson, 2025.12.19 17:44

@MetaQuotes Support, the above referenced calendar indicator published in the MQL5 Book content appears to contain deprecated code. 

The file is referenced at Reading event records by ID - Advanced language tools - MQL5 Programming for Traders.

The file, itself, is at: https://www.mql5.com/en/code/download/45596/CalendarRecordById.mq5.

Of course, you'll need to download the included library files to reproduce the issues.

errors

Personally, I've used a workaround to get what I need in my code. My purpose here is to ensure that the documentation is kept current.


 
Ryan L Johnson #:

Forwarded from another Topic:

Of course, MQL5 is constantly changing, and unfortunately MQ does this in a way which often breaks back-compatibility. I don't think this is a proper way of improving the platform, but anyway - the only thing we can do is to fix the problems by patches, according to new syntax. For example, in this case just add the single line:

struct MqlCalendarRecord: public MqlCalendarValue
{
   using MqlCalendarValue::operator=;
   ...
};
Just follow the official news about the changes in MQL5 syntax.