Can anybody help with an EA issue

 
Hi all, hope you can assist.

I'm coding an EA at the moment and wish to make it as robust as possible. As such I've created a routine which saves all the running parameters (including the user defined externals) to a .bin file. The routine saves after each run through the EA so that if the computer loses power or is shut down there will be a file with everything it needs to kick off again.

So..... When the EA starts it loads up the file if it finds it so it can carry on where it left off. The problem is that I can no longer change any parameters while the EA is running. For example my trailing stop or take profit levels as everytime it kicks in it just loads the values from the bin file.

Anybody have any ideas how I can solve the problem of storing values in case of a crash and yet still allow parameter changing?

Thanks in advance.
 
Global Variables can be used as runtime parameters. They can be accessed via F3 shortcut or "MQL4: Global variables" programmatically.
 
Well, first of all, you should not save ALL your variables. I have found that there are actually very few variables that cannot be correctly reconstructed from the current trading environment from within the init(). So:

1) Don't save any of your parameter variables. The EA will load them back up again when the chart with the software fires up again. No need to save trailing stop values, etc. All your extern variables will be reloaded anyway.

2) Don't save any variables that have to do the the current state of the trading environment unless you absolutely have to. For example, if you need to compare the trading environment of the current tick against the trading environment of the prior tick, and you have variables related to the prior tick that are required for the comparison, then you would need to save those variables. But if you're comparing the current tick environment to open trades, or to variables that can be constructed from your open trades, then you just need a function that loads up those variables based upon the currently open trades.

3) Check out the "static" variable type and see if that will help you in any of these situations.

4) Do use the global variables, but you will still have the issue of choosing carefully which variables to save or not.

5) Don't save your variables (global or file) on every single tick. Only save them out when something actually changes. Again, by minimizing the number of variables you are actually saving, you will not have to write them as often.

What you are trying to accomplish is saving the "state" of your EA. ANYTHING that can be accurately calculated and loaded in the init() should not be saved.

BTW, when using global variables, be sure to name them with a common prefix so you can easily delete all the global variables that have to do with your EA.

Hope this helps and/or gives you some ideas.
Reason: