While I don't have access to the contents of [...]"HLINES.txt" file, it's certain that when you call
StringSplit(lineData, sep, parts);
it does not fill the array parts with more than one substring (the file may be empty or doesn't contain any separator characters). As per the documentation, the StringSplit function returns the number of substrings that will fill the array. After you call it, check the return value and make sure it is at least equal to the number of substrings you expect it to be (in this case, you expect it to be 7 substrings). I would recommend you to debug your code aswell (set a breakpoint in this line and check if the array parts is filled correctly - although we already know it's not. Check which indexes are filled and see if it is expected they're filled with that data).
Also, idk if I missed something, but you need to read line by line. You are trying to read the entire file here:
string lineData = FileReadString(fileHandle);
Split it by lines and then split them by the separator character in loops. This may be causing an array out of range error aswell.
While I don't have access to the contents of [...]"HLINES.txt" file, it's certain that when you call
it does not fill the array parts with more than one substring (the file may be empty or doesn't contain any separator characters). As per the documentation, the StringSplit function returns the number of substrings that will fill the array. After you call it, check the return value and make sure it is at least equal to the number of substrings you expect it to be (in this case, you expect it to be 7 substrings). I would recommend you to debug your code aswell (set a breakpoint in this line and check if the array parts is filled correctly - although we already know it's not. Check which indexes are filled and see if it is expected they're filled with that data).
Also, idk if I missed something, but you need to read line by line. You are trying to read the entire file here:
Split it by lines and then split them by the separator character in loops. This may be causing an array out of range error aswell.
Thank you for your feedback I really appreciated it!
The issue is fixed now, the FileOpen function wasn't set properly apparently.
I added the following to the FileOpen function and it worked :
FileOpen(fileName, FILE_READ|FILE_TXT|FILE_ANSI,";");
In MLQ5 it was working fine with just FILE_READ, but it seems that MQL4 is less flexible.
Lesson learned, I won't make the same mistake twice!
Thank you again.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello there,
I'm converting the working MT5 version of my EA to MT4, but I get an array out of range error not matter what I try.
It's my first time working in MQL4 and I have tried many things but I can't solve the issue so hopefully someone can spot it and advice because I'm running out of idea... (and yes I did check MQL4 Reference and forums already!)
Here is the code (it is working in MQL5) :
And here is the content of the text file:
EURUSD_EntryPriceInvisibleLine_419614662;1.09601000;4294967295;2;0;0;0
InitialSLInvisibleLine_419614662;1.09603000;4294967295;2;0;0;0
Thank you in advance for your time and advices.