While(!FileISEnding) { READ, READ ... assumes that you have all 4 entries, you don't on the last line and the read fails. While(false == false) is redundant try while (!false) "while not false".
This fixes the last line:
while(true){ if (FileIsEnding(handle)) break; Sum1 += FileReadNumber(handle); counter1++; if (FileIsEnding(handle)) break; Sum2 += FileReadNumber(handle); counter2++; if (FileIsEnding(handle)) break; Sum3 += FileReadNumber(handle); counter3++; if (FileIsEnding(handle)) break; Sum4 += FileReadNumber(handle); counter4++; }
The extra comma on the first two lines means there are 5 values on that line, so you need to read the empty value to keep things straight.
Since you say some lines are missing the fourth value (not just the last line,) I doubt you're going to be able read the columns correctly. You're going to have to read the entire line (not csv mode) and parse the commas yourself. Or FIX the source.

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
Hi coders,
Could someone help me out with a CSV fileread problem?
I need the EA to open a CSV file and check it's data. In this CSV file there are many lines with (almost) all 4 entries (columns). The goal is to take the average of these columns. Data looks like this:
1.2,1.254,1.86,1.8693,
1.2424,0,1.82562,1.83,
1.2,1.344,1.86, // !! here no dataentry for the 4th column
Mind that sometimes a line of data has no entry for the 4th colum
With info found on this site i've created an ea to calculate the averages of those columns, but something goes wrong. It seems that the EA mixes up the values (for example, a value for column 2 gets in column 4).
Can anyone tell me what i do wrong?
Here is the code:
Thanks!