What's the best way to update a running ea on metatrader4?

Back to topics list To post a new topic, please log in or register
avatar
12
lukasjob 2016.05.04 09:03
 

Hi,

I have an expert advisor running on an instance of Metatrader 4, if I replace the ea's .ex4 file in the expert folder will metatrader get the changes automatically?

I used to right click on the "expert advisors" in the navigator panel and click refresh, hoping metatrader would get the new version of my ea, but the problem was all the settings for the ea were reset.

I was surprised when I saw orders were closed with the wrong stop loss, then I figured out the reason was the settings had been reset when I clicked "refresh". 

What's the best way to update a running ea on metatrader4?

Thank you all.


All the best,

Luke

avatar
1229
FMIC 2016.05.04 11:09 #
 

It has been discussed here many times, how EA's should implement a recovery mechanism into to be able to function after a failure such as a Crash (or in your case, a replacement of the .EX4 file).

Besides looking over the Order History, some EAs store the information (variables, parameters, states, etc.) in an external data file that is read during the "OnInit()" in order to pick-up where it left off.

Other EAs, use what is called "Global Terminal Variables" that are stored by MetaTrader and can be viewed and changed on the fly from within MetaTrader itself (F3 or Menu -> Tools -> Global Variables):

This way, you can update the .EX4 file and then do a Refresh, and the EA will be re-ininitialised, but since it goes and collects its previous state from the External File or Global Terminal Variables, it can continue with the same parameters and states that it had before.


avatar
12
lukasjob 2016.05.04 12:07 #
 
FMIC:

It has been discussed here many times, how EA's should implement a recovery mechanism into to be able to function after a failure such as a Crash (or in your case, a replacement of the .EX4 file).

Besides looking over the Order History, some EAs store the information (variables, parameters, states, etc.) in an external data file that is read during the "OnInit()" in order to pick-up where it left off.

Other EAs, use what is called "Global Terminal Variables" that are stored by MetaTrader and can be viewed and changed on the fly from within MetaTrader itself (F3 or Menu -> Tools -> Global Variables):

This way, you can update the .EX4 file and then do a Refresh, and the EA will be re-ininitialised, but since it goes and collects its previous state from the External File or Global Terminal Variables, it can continue with the same parameters and states that it had before.


Thank you for your reply.

When I run my back tests I store the inputs into a .set file, is there a way to read them back in inside the onInit() function?

That way anytime the ea is initialized it would load the correct inputs right?

Luke

avatar
1229
FMIC 2016.05.04 12:36 #
 
lukasjob:

Thank you for your reply.

When I run my back tests I store the inputs into a .set file, is there a way to read them back in inside the onInit() function?

That way anytime the ea is initialized it would load the correct inputs right?

Luke

That is not the same thing. That is just for External Parameters and Inputs only, which can be loaded manually from .set files (either in the Strategy Tester, or when you assign the EA to the chart).

However, an EA has many variables and states that can be important to save in case of failure. You should always implement Recovery Protocols for such an event.

avatar
13009
WHRoeder 2016.05.04 14:31 #
 
EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush/file) of ticket numbers required.
avatar
12
lukasjob 2016.05.04 17:06 #
 
WHRoeder:
EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush/file) of ticket numbers required.

Thank you, that code is hard for me to read.

Right now, I just want the ea to get all the inputs back without having to manually configure it. I stumbled into recovery issues because I used to refresh the ea from the navigator panel and lost all manually configured inputs. I think I'll explore the option of reading a file from the onInit() function.

avatar
119
Doerk 2016.05.05 10:57 #
 
... which is not enough. What you also need is OnDeinit to figure out why OnInit is called. If you ignore this, you will "recover" on every change of the timeframe and so on. OnInit is not only called on initalization, which makes is not that easy to deal correct with it.
avatar
12
lukasjob 2016.05.05 17:43 #
 
Doerk:
... which is not enough. What you also need is OnDeinit to figure out why OnInit is called. If you ignore this, you will "recover" on every change of the timeframe and so on. OnInit is not only called on initalization, which makes is not that easy to deal correct with it.
Hi Doerk, are you sure OnInit is not called only at initialization?
avatar
13009
WHRoeder 2016.05.05 18:29 #
 
OnInit is called at every initialization. The EA is not reloaded at every initialization.
Initial load

EA loaded: Globals, status reset
OnInit
Recompile
DeinitEA loaded: Globals, status reset
OnInit
Chart change, parameters, account, templateDeinit*
OnInit
Remove, chart close, terminal close, Init failed
Deinit
 

* Indicators use to do the same thing, now they are always reloaded.

Back to topics list  

To add comments, please log in or register