Question about import of data from a csv-file

 

hi,

i have a csv-file whcih has a lot of rows like this:

EURUSD,H1,00068, 1.37360, 0, -1

EURUSD,H1,00069, 1.37370, 1, 19

EURUSD,H1,00070, 1.37380, 0, -1

EURUSD,H1,00071, 1.37390, 0, -1

EURUSD,H1,00072, 1.37400, 0, -1

EURUSD,H1,00073, 1.37410, 0, -1

EURUSD,H1,00074, 1.37420, 0, -1

EURUSD,H1,00075, 1.37430, 1, 50

for an ea i need the prices where the last column is bigger than -1. in my example i need the prices from row 2 and the last row. the result would be an array (??) which contains 1.37370 and 1.37430.

i'm a beginner when it comes to csv and arrays. perhaps somebody can help me to get me on the right track.

thanks a lot!

 
 
Each line is string, string, number, number, number, number read all and simply check the value of the last number . . https://docs.mql4.com/files/FileReadString & https://docs.mql4.com/files/FileReadNumber
 
ok, thanks! i didnÄt know that the end of a line is found automatically!
 
ok, thanks! i didnÄt know that the end of a line is found automatically!
 

hi,

i can't find the problem. no data is written in the array "sr". why?

might it be a problem that the first row of the csv-file the the headline and looks like this:

Pair,TF,Level, Price,Count, Start

while(FileIsEnding(Handle)==false) // While the file pointer..
{ // ..is not at the end of the file
symbol = FileReadString(Handle); // symbol
timeframe = FileReadString(Handle); // timeframe
level = FileReadNumber(Handle); // level
price = FileReadNumber(Handle); // price
count = FileReadNumber(Handle); // count
start = FileReadNumber(Handle); // start
counter++;
if (count>0) {
sr[counter]=price; //DOESN'T WORK. WHY??
}
}
 

Please use this to post code . . . it makes it easier to read.

Add some print statements so you can see what values you are getting back when you read the CSV file . .

 

ok, here the code again.

while(FileIsEnding(Handle)==false) // While the file pointer..
{ // ..is not at the end of the file
symbol = FileReadString(Handle); // symbol
timeframe = FileReadString(Handle); // timeframe
level = FileReadNumber(Handle); // level
price = FileReadNumber(Handle); // price
count = FileReadNumber(Handle); // count
start = FileReadNumber(Handle); // start
counter++;
if (count>0) {
sr[counter]=price; //DOESN'T WORK. WHY??
}
}
 
RaptorUK:

Please use this to post code . . . it makes it easier to read.

Add some print statements so you can see what values you are getting back when you read the CSV file . .

What did the Print statements tell you ?
 
RaptorUK:
What did the Print statements tell you ?


Hi RaptorUK, first of all let me thank you. I really appreciate your help!! The print-statements told me that everything is ok but that no prices are saved in the array. Here is the code:

the prices (variable price) are ok but nothing is saved in sr[counter] .

double sr[];                               // Array declaration
   int counter=0;
  if (count==1) {
      
      counter++;
      sr[counter]=price; 
      
      Print("SR: ",counter);      
                     }
      
    }
 
FXsuperman:


Hi RaptorUK, first of all let me thank you. I really appreciate your help!! The print-statements told me that everything is ok but that no prices are saved in the array. Here is the code:

the prices (variable price) are ok but nothing is saved in sr[counter] .

You are welcome. I see your problem, you have to give the array an initial size . . . e.g. double sr[100];, double sr[]; only works for Indicator buffers, indicator buffer != array and indicator buffer ~ array, in other words Indicator buffers are like arrays but are also different to arrays.
Reason: