Download MetaTrader 5
To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
Route206
211
Route206 2015.06.30 19:47 

Hi, 

if i open a file for writing in the OnInit, use a timer to write, then close the file OnDeInit, is there anyway i can view file (read-only) during EA run?

i keep getting:  "<file>.csv cannot be accessed. The file may bcorrupted, located on a server that is not responding, or read-only."

int OnInit()
  {
  EventSetTimer(10);
  filehandle=FileOpen("line5.csv",FILE_WRITE|FILE_CSV);
  if(filehandle!=INVALID_HANDLE)
   {Alert("FileOpen OK");}
   else {Alert("Operation FileOpen failed, error ",GetLastError());}
  }

void OnDeinit(const int reason)
  {
  EventKillTimer();
  FileClose(filehandle);
  }

void OnTimer()
  {
  FileWrite(filehandle,TimeToString(TimeCurrent(),TIME_MINUTES),current_profit);
  FileFlush(filehandle); 
  } 
ydrol
595
ydrol 2015.06.30 20:09  
Route206
211
Route206 2015.06.30 21:35  

Yeah you're right - I was crying too early: FILE_SHARE_READ did the trick..

int OnInit()

  {
  EventSetTimer(10);
  filehandle=FileOpen("line5.csv",FILE_WRITE|FILE_CSV|FILE_SHARE_READ);
  if(filehandle!=INVALID_HANDLE)
   {Alert("FileOpen OK");}
   else {Alert("Operation FileOpen failed, error ",GetLastError());}
  }

void OnDeinit(const int reason)
  {
  EventKillTimer();
  FileClose(filehandle);
  }

void OnTimer()
  {
  FileWrite(filehandle,TimeToString(TimeCurrent(),TIME_MINUTES),current_profit);
  FileFlush(filehandle); 
  }
Demos Stogios
184
Demos Stogios 2015.07.01 13:25  

hello, 

i am writing this as a warning, as I  do not know if you itentionally set the flags without FILE_READ; in the absence of it, each time you open your file, it will be emptied and that may not be a desired behaviour in case of a failure recovery and similar

Ok, so if you decide that you actually need it, make sure that you have to use FILE_READ in conjuction with  FILE_SHARE_READ 

best regards 

Route206
211
Route206 2015.07.07 07:41  
Demos:

hello, 

i am writing this as a warning, as I  do not know if you itentionally set the flags without FILE_READ; in the absence of it, each time you open your file, it will be emptied and that may not be a desired behaviour in case of a failure recovery and similar

Ok, so if you decide that you actually need it, make sure that you have to use FILE_READ in conjuction with  FILE_SHARE_READ 

best regards 

Hello Demos,

i'm afraid i don't understand: the behavior is fine, but you are right: if the EA opens the file for writing, it empties it. is that what you mean?  I don't see you point why FILE_READ should always be used in conjunction with FILE_SHARE_READ. While intuitively is sounds reasonable, i'm not sure what the difference would be for me as a 'back-door' user of the file while being written by the EA. 

Can you elaborate? 

/
To add comments, please log in or register