![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thank you for your help! I can finally read that file in tester :) for reference here is the code I finished with:
the function reads the full file. for normal files this is fine but if you process larger files (> 1MB) and only need to access line 2 the processing and memory overhead cannot be ignored, especially during trading. it would make sense to add an additional parameter "count" to stop processing after 2 lines, for example. until now i had no need for that, it's a simple change/breakout of the loop.
2. MQL is not made for reading "lines", all functions are designed for reading "values". that makes it a bit complicated to process lines in MQL. in fact it means whatever we do/want we can only read values, if we want lines we always need to reconstruct.
instead of avoiding one character in all files (and failing with that approach only 2 weeks later :-)) the opposite assumption is better. "no line must contain character XYZ" becomes "at least one line might contain character XYZ" and we can write the implementation around that. MQL gives us only values anyway, so it's not a problem if the separator character is mixed up with the file content as long as we know how to correctly detect line ends. if we need lines and we have to reconstruct them anyway, line ends are more important than value/field separators.
3. see the attachment. special care is taken for the last line. we never know if the last line is followed by another EOL or if this last EOL is missing (last line character + end_of_file). but it's a valid line, so we cannot lose it.
i don't like implementations long like that (for readability and maintaining) but sometimes there's no better way. the code also implements a proper way of error handling, small and very effective. to me the function is quite bullet proof, but who knows so i keep the error handling in. i want to know if/when it breaks...
Thanks a lot! Much appreciated.
for FileIsLineEnding() the documentation simply is plain wrong. it must read like this:
bool FileIsLineEnding( int handle)
For CSV file returns the current value of the internal "line ending" flag. The flag is set by the previous FileReadString() call and will be reset/set by the next FileReadString() call. FileIsLineEnding() will not check any characters at the current position of the file pointer by itself.
same is true according to FileIsEnding().
to complete your use case one more function and a bug fix for StringSubstr()
with this your use case is solved like this (assumed, every line is expected to contain 6 values separated by tabs). btw., it's the separator used in FileReadLines() -> maximum mix-up :-)
regards
ps: some minor modifications in the last block since posting it the 1st time
Hi Paule
Thanks again.
According to the "TODO" in the code:
- Limit works as expected:
2012.12.02 21:53:19 test EURUSD,M5: Limit set to 2: Value1: 2079114; Value2: 1.3003;1354301865;EURUSD;0.01;1.29583;1.30385;0;0;
- Separater at the end of the line adds a new (empty) value:
2012.12.02 21:58:28 test EURUSD,M5: ArraySize without separator: 9
2012.12.02 21:59:51 test EURUSD,M5: ArraySize with separator: 10
I added the above code to the library and defined the functions in the header file. The default values in library function do not work or rather the function cannot be called without the optional parameter. -. " ')' - wrong parameters count C:\mt4\demo\acm\experts\test.mq4 (30, 33)"
It seems that others have had the same issues.... Any experience with that?
edit: it is not possible: https://docs.mql4.com/basis/variables/formal "MQL4-library functions imported within other modules cannot have parameters initialized by default values."
Hi Paule
Thanks again.
According to the "TODO" in the code:
- Limit works as expected:
2012.12.02 21:53:19 test EURUSD,M5: Limit set to 2: Value1: 2079114; Value2: 1.3003;1354301865;EURUSD;0.01;1.29583;1.30385;0;0;
- Separater at the end of the line adds a new (empty) value:
2012.12.02 21:58:28 test EURUSD,M5: ArraySize without separator: 9
2012.12.02 21:59:51 test EURUSD,M5: ArraySize with separator: 10
I added the above code to the library and defined the functions in the header file. The default values in library function do not work or rather the function cannot be called without the optional parameter. -. " ')' - wrong parameters count C:\mt4\demo\acm\experts\test.mq4 (30, 33)"
It seems that others have had the same issues.... Any experience with that?
edit: it is not possible: https://docs.mql4.com/basis/variables/formal "MQL4-library functions imported within other modules cannot have parameters initialized by default values."
thanks for testing.
as for the default parameters you are right. FileReadLine is an excerpt from my real stdlibrary and that one is big, about 500 utility functions. default parameters inside a library are indeed supported, so there they are very useful. i just kept them in the code.