How to read specific cell value from CSV file in MQL4?
How to read specific cell value from CSV file in MQL4?
Loading saved threads...
Rahul2304 · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Rahul2304
Original post: https://stackoverflow.com/questions/69006252
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am trying to read just one cell value from a CSV file in MQL4, however, the online documentation doesn't cover finding single cell values and I've searched countless threads for a workaround but there are none.
My code is below,
int Handle = FileOpen("/Users/rahulparmeshwar/Documents/Algo
/LogisticRegressionOutput.csv",FILE_READ|FILE_CSV,',');
double Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Str = FileReadInteger(Handle,1);
Alert(Str);
FileClose(Handle);
The contents of the CSV file are as follows below
Any help will be much appreciated, Thank you.
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/69014960
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
First, see
FileOpen Function
For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means, cannot be outside the file sandbox.
This means you must place your csv file in the
...\MQL4\Files
folder.
Regarding your code, it is much more efficient to use an array. You can then read a specific cell value using [row][column]. Remember that arrays are zero based (your first row and column reference would be [0][0]).
string data[1][18]
int Handle=FileOpen("LogisticRegressionOutput.csv",FILE_CSV|FILE_SHARE_READ,",");
if(Handle<1){return(-1);}
int row=0;
ArrayResize(data,18);
while(!FileIsEnding(Handle))
{
if(row>ArraySize(data)/18-1) {ArrayResize(data,(row+1)*18);}
for(int i=0; i<=18-1; i++) data[row][i]=FileReadString(Handle);
row++;
}
FileClose(Handle);
Print(data[0][0]);
Quote
Report
Post Reply
Checking account access…