You have only four choices:
- Search for it,
- Beg at Will code your trading systems for free - Free Expert Advisors - Trading Systems - MQL5 programming forum, or Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum, or Need help with coding - General - MQL5 programming forum, or Free MQL4 To MQL5 Converter - General - MQL5 programming forum, or Requests & Ideas (MQL5 only!).
- learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- or pay (Freelance) someone to code it.
No free help
urgent help.
I read a lot about the documentations and made several attempts in the situation bellow, how can I record data of a csv file in a struct.
#define MC_MAX 80 struct line_read{ char symbol; // symbol char code1; // field 2 char email; // email char code2; // field 4 char code3; // field 5 bool status; // field 6 }; string symbol[MC_MAX]; // symbol char code1[MC_MAX]; // field 2 string email[MC_MAX]; // email char code2[MC_MAX]; // field 4 char code3[MC_MAX]; // field 5 bool status[MC_MAX]; // field 6 line_read buff_line[200]; string filename = "data.csv"; int size=0; int handle=0; handle=FileOpen("data.csv", FILE_WRITE|FILE_READ|FILE_BIN,","); if(handle > 0){ if(!FileReadStruct(handle,buff_line[0])) PrintFormat("Error reading data. Error code=%d",GetLastError()); Print("handle: ", handle," : ",buff_line[handle].email); FileFlush(handle); FileClose(handle); } Print("Struct Array: ",buff_line[1].email, " + ", buff_line[1].symbol , " + ", buff_line[1].code1); Print("Struct Array result: ",result[0]);
My CSV file format is:
EURUSD,1,sddw32@gmail.com,274653782,0,true
USDJPY,3,dffdff@gmail.com,274653782,0,false
When I try to read the file using FILE_CSV or FILE_TXT in function FileOpen() does'nt work and return error 5011 "File must be opened with FILE_BIN", but if I use this parameter I cant access the content of the struct in separate.
Stop trying to get people to do all the work for you.
Using the search function on mql5.com would bring up the answer for you.
https://www.mql5.com/en/search#!keyword=read%20csv&module=mql5_module_forum
This topic has been asked NUMEROUS times.
- www.mql5.com
Also if you would PLEASE read over the documentation, you will find your answer.
Here is the link to the documentation regarding file handling.
- www.mql5.com
class SymbolDebug : public CObject{public:string symbol; // symbolint code1; // field 2string email; // emailint code2; // field 4int code3; // field 5bool status; // field 6bool load_string(string entire_csv_row){string res[];StringSplit(entire_csv_row, ',', res);this.symbol = res[0];this.code1 = int(res[1]);//etc........}};
Thank to all, I solved with it:
string line_read[10][100]; //assign array of string that will store 10 columns 100 rows of csv data int row=0,col=0; //column and row pointer for the array handle=FileOpen(filename,FILE_CSV|FILE_READ,","); //comma delimiter if(handle>0) { while(True) //loop through each cell { string temp = FileReadString(handle); //read csv cell if(FileIsEnding(handle)) break; //FileIsEnding = End of File line_read[col][row]=temp; //save reading result to array if(FileIsLineEnding(handle)) //FileIsLineEnding = End of Line { col = 0; //reset col = 0 for the next row row++; //next row } else { col++; //next col of the same row } } FileClose(handle); } else { Comment("File "+filename+" not found, the last error is ", GetLastError()); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to read a CSV file like the lines bellow and load in the a structure to access bellow.
What is the best form (function maybe) to read and save the data in this structure, I have many lines to read.
The file is stored in "..\MQL4\Files\file.csv" directory.
I have a CSV file with many lines:
EURUSD,1,sddw32@gmail.com,274653782,0,true
USDJPY,3,dffdff@gmail.com,274653782,0,false