about csv, arrays and best practices

 

Hi! I'm creating a csv parser that will be used every time.

I'm thinking about read it once and after that just work on the memory.

How can I declare this like a TimeSeries?

I'm trying something like:

datetime ExtractDataFromParser()[]
{

}

But it doesn't work.

What's the best way to do it?

 
jonatas:
[...] I'm trying something like:
datetime ExtractDataFromParser()[]
{

}

But it doesn't work.

You can't return arrays and if u want to change them then they must be passed by reference. See here -> https://docs.mql4.com/basis/variables/formal.
 
int ExtractDatesFromParser(int hparser, datetime &dates[]){  // pass the dates array by reference
   int nrows;
   int col;
   int i;
   if (IsParserReady(hparser)){
      nrows = GetParsedRowCount(hparser);
      col = 1; // column number with the dates
      ArrayResize(dates, nrows);
      for (i=0 i<nrows; i++){
         dates[i] = GetParsedCellAsDatetime(hparser, i, col);
      }
      return(nrows);
   }else{
      return(-1);
   }
}
Maybe this is overkill. You will run into limitations of the mql4 language when you want to create a new parser object and want to dynamically allocate the needed arrays and structures to hold the parsed table and other needed properties. Mql4 is not only a static language, it is the successful attempt to combine all weaknesses of static and dynamic languages in one new language while strictly avoiding any of their strengths. I would write such a generic do-it-all thing (if it is really needed) in a properly object oriented language and import it's flattened interface through dll function imports.
 
Thanks for the answers! I'll use formal variables. I'm anciousy to migrate to mql5 and do-it-all too.
Reason: