Hi all!
Thank you for looking at this thread. I'm having an issue at the moment of trying to import a matrix from a CSV file into a MetaEditor script. The file below is what the CSV file looks like in MetaEditor. What piece of code could I write to efficiently import these numbers into an array which has 10 rows and 12 columns? Thank you so much!
Bart
Hi all!
Thank you for looking at this thread. I'm having an issue at the moment of trying to import a matrix from a CSV file into a MetaEditor script. The file below is what the CSV file looks like in MetaEditor. What piece of code could I write to efficiently import these numbers into an array which has 10 rows and 12 columns? Thank you so much!
Bart
Reading a csv file into an array is simple.
https://www.mql5.com/en/docs/files
However, you need to write the code to do it.
Show us what you have tried, and you'd probably get a little more help.
- www.mql5.com
void OnTick() { double arr[]; int file_handle=FileOpen("buy_GBPvsAUD.csv",FILE_READ|FILE_CSV); if(file_handle!=INVALID_HANDLE) { //--- read all data from the file to the array FileReadArray(file_handle,arr); //--- receive the array size int size=ArraySize(arr); //--- print data from the array } Print("Array size = "+arr[2][3]); } //+------------------------------------------------------------------+
Thank you guys for the speedy reply. I'm quite new to MQL5 so I'm a bit confused with the syntax and functions. This is what I wrote so far but unfortunately I cannot seem to store the matrix into an array. The EA won't print out the individual element when I ask it too.
Try adding error handling to your code like the example on this page.
https://www.mql5.com/en/docs/files/filereadarray
It may be as simple as it cannot find the file.
You're storing "buy_GBPvsAUD.csv" in \Terminal\Common\Files\ right?
Try adding error handling to your code like the example on this page.
https://www.mql5.com/en/docs/files/filereadarray
It may be as simple as it cannot find the file.
You're storing "buy_GBPvsAUD.csv" in \Terminal\Common\Files\ right?
Thank you so much for the reply! It does print an error 5004. I'll look into it but I did store the file in the write folder :)
Try adding error handling to your code like the example on this page.
https://www.mql5.com/en/docs/files/filereadarray
It may be as simple as it cannot find the file.
You're storing "buy_GBPvsAUD.csv" in \Terminal\Common\Files\ right?
I forgot to mention, I'm using MQL5, I don't know if that makes any difference or not.
Thank you guys for the speedy reply. I'm quite new to MQL5 so I'm a bit confused with the syntax and functions. This is what I wrote so far but unfortunately I cannot seem to store the matrix into an array. The EA won't print out the individual element when I ask it too.
FileReadArray
Reads from a file of BIN type arrays of any type except string (may be an array of structures, not containing strings, and dynamic arrays).
CSV files are not BIN files and you are trying to read strings in array(s)
FileReadArray
Reads from a file of BIN type arrays of any type except string (may be an array of structures, not containing strings, and dynamic arrays).
CSV files are not BIN files and you are trying to read strings in array(s)
Sorry I don't follow. My csv file only contains numbers and not strings. I don't understand what a BIN type of array is. Would you be able to explicitly write the code to perform this operation, if that is not too much to ask? Thank you. :)
Sorry I don't follow. My csv file only contains numbers and not strings. I don't understand what a BIN type of array is. Would you be able to explicitly write the code to perform this operation, if that is not too much to ask? Thank you. :)
CSV file is a string (simple textual) file - does not matter if you use "only" numbers - some more information on what string is (and what it is not) you can find here : https://en.wikipedia.org/wiki/String_(computer_science)
In the hep description of FileReadArray() you can follow what "BIN" files are and how you can use them
Save the data using bin file format and FileSaveArray() and then use again that same bin file and use FileReadArray() and ll will work
CSV file is a string file - does not matter if you use "only" numbers - some more information on what string is (and what it is not) you can find here : https://en.wikipedia.org/wiki/String_(computer_science)
Save the data using bin file format and FileSaveArray() and then use again that same bin file and use FileReadArray() and ll will work
Hi again,
So I saved the file as a BIN file and then used the same code as before however when trying to print the value of the first element to the screen I got the following,
2018.06.07 11:11:42.517 temp_EA (EURNZD,M15) 1.426707300392364e-71
where this tiny number came from I don't know but on the next tick I got the array is out of range error.
Sorry to keep asking you for help I just can't seem to be able to get my head around it! Now I have a bin file, how would you write a script which prints out an element from the array?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all!
Thank you for looking at this thread. I'm having an issue at the moment of trying to import a matrix from a CSV file into a MetaEditor script. The file below is what the CSV file looks like in MetaEditor. What piece of code could I write to efficiently import these numbers into an array which has 10 rows and 12 columns? Thank you so much!
Bart