combine advantages of EA and script

 

Hi fellow traders and programmers,


since I know this forum to be an awesome place to develope ideas I post this here.

I want to combine the advantages of EAs (like sticking to a chart even after restart of MT4 or changing of TimeFrames etc.) with those of a script (running independently from connection to broker and tick income for specific currency pair).


So I figured that I can just use an infinite loop in the EA which of course works, just like a script.

However, I need to be capable of starting pretty much all jobs even when no ticks are coming in so my only option is to place all code into init().

Do you consider this to be abusing MetaQuotes' architecture or is it OK?


What about the differences init() and start() in EAs? The only thing relevant I know is the state of UninitializeReason().

Are there more differences or limitations to running code in init()?


The most obvious difference and problem is that you cannot stop EAs properly on command - do you have a solution for this?

I mean, sure...it works manually calling deinit() in the init() function and then calling a non-existing function from a DLL which forcedly stops all of the EA's functions but this certainly is the most ugly thing I have done in MQL4 for years. Also, this does not detach the EA from the chart - is this possible by command?


Sincerely,


Daniel.

 

It is not recommended to call start() function from init() function or to perform trade operations, as chart data, market prices, etc. can be incomplete by the moment of the module initialization. The init() and deinit() functions must finish their working as soon as possible and, in no case, shall they loop when trying to start its full-fledged working before the start() function is called

 

thanks...that's a pretty general answer. When are these actions like "chart data, market prices completion etc." performed? You say in init() but when exactly - after my own code in init()?

Can I wait for MT4 finish these tasks somehow or does init() really have to be finished?

Could you please elaborate on the errors caused by this unusual approach?

 

because in my understanding all the chart Data etc. is completed before my code in init() is run.

Just try a broker with many symbols and load them into your market watch. It takes MT4 a little till all data is retrieved...However, my init-code is executed after this short "update freeze".

 

Why don't you perform some tests and see what you get?

 
sure, that's what I am doing. Doing this, I also found a bug which was fixed immediately by MetaQuotes and will be repaired in the build :)
 
Excellent.