Optimizer problem mql5

I have an EA that uses OnTimer() to read a file from disk, trade on the basis of its contents, and close it.

Things go fine when I backtest the EA 4 times with static input values of 50 and 100 for two input variables (4 different runs).

But when I try to use the optimizer with input values Start = 50 , step = 50, end = 100 for the two variables, I do get 4 passes, but:

– Passes 0, 1, and 2 get an error which seems to be related to the file read. Pass 3 runs fine.

I suppose I need to dig into this more deeply, but is there something obvious that I need to know?

More generally I’m unsure of the flow of the optimizer. Wouldn’t it just call the backtester 4 times with different input values each time?

Thank you.

How do you read the file? What errors exactly do you get?


        hd = File.Open(trade_file_2,FILE_READ|FILE_COMMON,9);


5004 – File opening error.

Also it’s inconsistent… Sometimes one or more passes fail – sometimes they all succeed.


Try to add FILE_SHARE_READ flag.

Are you closing the file after reading?

No, I wasn’t and that was part of the problem. That’s now solved I think.

Thanks everyone.