ERR_CANNOT_OPEN_FILE while writing history

 

Hello,

I'm using 7bit's offline_charts.mqh from the codebase to create an offline chart for demonstration of Random Walk.

I wrote a simple script which I drag on an open chart and it writes random history data which can be opened with MT and I can use period_converter on it too to create H1, H4, etc data.

Everything worked PERFECTLY and I've generated dozens of charts with 100k lines, but yesterday it just stopped working. It's ok with 500 lines, but above 1000 lines, I get the following output:

randomchart: invalid handle -1 in FileClose

randomchart: invalid handle -1 in FileTell
randomchart: invalid handle -1 in FileSeek
randomchart: cannot open file C:\Program Files\OANDA - MetaTrader\history\OANDA-MT4 Practice\RND1.hst

I put a GetLastError after the file open in offline_charts.mqh and the error is:

ERR_CANNOT_OPEN_FILE

There's plenty disk space, the terminal.exe has only 90 handles open (in Task manager), I have permission to write to disk ... I only have a zero sized file but contents are not written to it, only if I specify a small number of iterations, like 500.

But I repeat, it worked like a charm even with 100-150k iterations!

Anybody has a clue? Terminal build 229.

Files:
 

I've moved the few used functions from offline_charts to the script and also changed a bit so that it does not open/close the hst file after every bar written.

It works again and became a lot faster - I have a suspicion that repeatedly opening / closing a file (thousand times) could have been the cause ...

 

how someone supposed/can to help u without having the file offline_charts.mqh

 

You are right, gjol. Without the offline_charts.mqh file, nobody can help me.

If you read the first post again, I said it's from the codebase. Type "offline_charts" in the search box and you'll find it here on the site.

Oh, please, read my 2nd post too - the problem was solved in the meantime. :)

 
speki:

It works again and became a lot faster - I have a suspicion that repeatedly opening / closing a file (thousand times) could have been the cause ...


This. If you find yourself needing to access a file multiple times (can become a real speed-limiter in backtesting) then you will find an SSD or a ramdrive to be quite helpful in eliminating the bottleneck.
 
1005phillip:

This. If you find yourself needing to access a file multiple times (can become a real speed-limiter in backtesting) then you will find an SSD or a ramdrive to be quite helpful in eliminating the bottleneck.

Thanks for the tip!
Reason: