How to constantly read from a file without closing and reopening it ?

 

Do I have to open/close file constantly in start()

handle = FileOpen("params.txt",FILE_CSV|FILE_READ, ";");

params= FileReadString(handle,16);

FileClose(handle);

or is there a better way ?

 
forexgenuine:

Do I have to open/close file constantly in start()

handle = FileOpen("params.txt",FILE_CSV|FILE_READ, ";");

params= FileReadString(handle,16);

FileClose(handle);

or is there a better way ?

Just keep reading. There is no need to close the file until you are finished with it.
 
forexgenuine:
Do I have to open/close file constantly in start()
  1. Your code just reads the first string. Are there more than one string in the file?
  2. Is the file being changed externally? No, just read it once in init and remember it. Otherwise, yes since it could be changed at any time.
 
dabbler:
Just keep reading. There is no need to close the file until you are finished with it.

I read it constantly because It can change externally.
 
WHRoeder:
  1. Your code just reads the first string. Are there more than one string in the file?
  2. Is the file being changed externally? No, just read it once in init and remember it. Otherwise, yes since it could be changed at any time.


1. Currently only one line because actually I don't know yet how to read multiple lines I'm very beginner

2. Yes It can be changed externally that's my very purpose: take external change into account

 
forexgenuine:


2. Yes It can be changed externally that's my very purpose: take external change into account

In that case you must use FileSeek to get the new data.

https://docs.mql4.com/files/fileseek

Reason: