Hi Tom
An EA's init() function runs once only when EA applied to a chart. Thereafter start() gets called by Terminal. See below for times when init() gets recalled...
for full info see your MetaEditor HELP: MQL4 Reference - Program Run - Program Run and here, online at https://docs.mql4.com/index and also https://docs.mql4.com/runtime/start
as to "initialized properly?"... If I understand you correctly, in init(), as appropriate, it could load EA global scoped variables to indicate such and when start() entered - could check them...
eg, I use just one EA global variable int gError; such that should it ever be set to say ERR_COMMON_ERROR, the EA start() on entry, will detect this and immediately return to Terminal with return(ERR_COMMON_ERROR);
So here, if init() cannot for instance open the EA's logfile it issues Print() > sets gError > continues to go deeper in init() if followng code has no dependancies (in this case expecting logfile to be open) >... until cannot go further (this way can maybe detect other errors and issue Print()'s)... so finally return(ERR_COMMON_ERROR); to Terminal and that's that... hopefully :)
I only mention above as sometimes practical example/theWayAnotherDoesIt... may be of interest.
Remember, an EA will continue to be called by Terminal each new data tick (unless EA already running) - so you must consider just what you want do when not"initialized properly" or indeed... at some point in time, EA would like to simulate ABORT, yes?
AFAIK, there is not clean method of telling Terminal "ABORT" - do not call me again thanks vMuch - as conventionally understood in say C/C++/...
hth
Just set it up to run your check on the first tick prior to "trading".
If you would please could you expand a bit?, I do not understand above so am in need of more learning
thanks
Ok.
int start(){ static bool verified = false; if(verified == false){ ... perform your initialization verification... ... when you are happy with verification.. ... verified = true; } continue with original EA processing return (0); }
right - a once off at head of start(), yes interesting.. I often use statics in functions for the first time called only stuff and even in start() now and then but never really occurred to me regards this thread. I do all verification in init() so was being too blinkered !
I'll save above - building up html file of snippets etc.
Much appreciated phy
:o)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there any way to have a section of code run prior to a tick so you can see if your EA initialized properly?
Thanks!
Tom