puncher:
Is init() function used only one time when the expert advisor is initalized or init() function is used more times by the expert ?
From https://docs.mql4.com/runtime/start:
Immediately after the program has been attached to the chart, it starts
working with the init() function. The init()
function of an expert advisor or a custom indicator attached to
the chart will run just after client terminal has started
and history data (this concerns only experts, but not
indicators) have been loaded additionally, after the symbol and/or
chart period have been changed, after the program has been
recompiled in MetaEditor, after inputs have been changed from
the window of expert or custom indicator settings. An expert
will also be initialized after the account has been changed.
I'm being pedantic and I suspect it won't matter for OP, but I'm not so sure that description is technically accurate. In my (limited) experience, init() is called at the first tick after attaching it to the chart rather than immediately. I have had trouble with my connection managment EA and if on a restart, there is no tick, it won't load the init() of the EA.
My 2 cents
V
Viffer:
Nope. start() runs at first tick, but init() runs immediately after attachment (regardless of incoming ticks). It won't run if there is no connection to the server.
[...] In my (limited) experience, init() is called at the first tick after attaching it to the chart rather than immediately. [...]

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Is init() function used only one time when the expert advisor is initalized or init() function is used more times by the expert ?
I ask because I don't know where is better set default values for defined variables : on init() function or as an extern value.