Dear
I need to create a structure named "table" to hold the data from the txt file (attached). How can I do that? I tried this script below but did not work.
You need to open the file in CSV mode like so:
short delimiter=','; int fileHandle = FileOpen("Sample.txt",FILE_READ|FILE_CSV,delimiter);
And table line should be an int:
struct Table { int line; datetime date; string symbol; double price; }; ... table[i].line = (int)FileReadNumber(fileHandle);
You need to open the file in CSV mode like so:
And table line should be an int:
Dear lippmaje
Thanks but didn't work.
Thanks but didn't work.
Then what exactly does not work for you?
Note that you don't make a difference whether the file is empty or just not found. Handle your errors, they are telling you something.
Then what exactly does not work for you?
Note that you don't make a difference whether the file is empty or just not found. Handle your errors, they are telling you something.
Thanks again lipmaje. Let me try to explain. When I compile the updated scrip I got no errors however, When I run attached to a chart I got 0 in the first line and 1 at the second line, means that my table is not holding the data, right?
Thanks again lipmaje. Let me try to explain. When I compile the updated scrip I got no errors however, When I run attached to a chart I got 0 in the first line and 1 at the second line, means that my table is not holding the data, right?
Dear
I need to create a structure named "table" to hold the data from the txt file (attached). How can I do that? I tried this script below but did not work.
Hi Victor,
You need to indicate how the file is formatted in your FileOpen command. Which means you'd need to change your line
int fileHandle = FileOpen("Sample.txt",FILE_READ|FILE_TXT);
into
int fileHandle = FileOpen("Sample.txt",FILE_READ|FILE_CSV,',');
so that the File reading functions know how to handle it.
Dear
Here the code updated as suggested.
//+------------------------------------------------------------------+ //| Stategy.mq5 | //| Victor Carozo | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Victor Carozo" #property link "https://www.mql5.com" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- struct Table { int line; datetime date; string symbol; double price; }; Table table[]; int i=0; short delimiter=';'; int fileHandle = FileOpen("Sample.txt",FILE_READ|FILE_CSV,delimiter); if(fileHandle!=INVALID_HANDLE) { while(FileIsEnding(fileHandle) == false) { ArrayResize(table,ArraySize(table) +1 ); table[i].line = (int) FileReadNumber(fileHandle); table[i].date = FileReadDatetime(fileHandle); table[i].symbol = FileReadString(fileHandle); table[i].price = FileReadNumber(fileHandle); i++; } FileClose(fileHandle); } for ( i=0; i< ArraySize(table); i++) Print(table[i].date); } //+------------------------------------------------------------------+
I attached the .txt file for conference and compile results. I still not hold the data from ''sample.txt'' in the ''trade'' structure, anyone has another suggestion?
What do you see when you add this line:
short delimiter=';'; int fileHandle = FileOpen("Sample.txt",FILE_READ|FILE_CSV,delimiter); if(fileHandle==INVALID_HANDLE) Alert("could not open file, error: "+(string)GetLastError());
What do you see when you add this line:
Same as before...
1970.01.01 00:00:00and when you add this to the bottom:
Print("table size: ",ArraySize(table)); for(i=0; i<ArraySize(table); i++) Print(table[i].line," ",table[i].date," ",table[i].symbol," ",table[i].price);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear
I need to create a structure named "table" to hold the data from the txt file (attached). How can I do that? I tried this script below but did not work.