REPOST: init(), start() how code completes

 

Hello,

For an EA... what happens to code running in init() when a new tick comes in? Will init() always complete and the tick be ignored?

What has priority init() or start()?

Thanks!

-charliev

 

See Program Run:

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.

Every program attached to a chart completes its work with the deinit() function. The deinit() function runs at the client terminal shutdown, at chart closing, immediately before the symbol and/or chart period is changed, at successful recompiling of the program, at changing of inputs, or at changing of the account. One can see the reason of deinitialization using the UninitializeReason() function during execution of the deinit() function. The deinit() function must be executed within 2.5 seconds. If the function has not completed its execution within this time period, it will be completed forcedly. Scripts are an exception to this rule, as they normally finish their working independently, without any commands from outside. If a script works very long (due to endless loop, foe example), it can be finished by an outside command (at deletion of the script from the chart context menu, at attaching of a new script to the same chart, at closing of the chart, at changing of the symbol and/or chart period). In this case, the deinit() function is limited by 2.5 seconds, too.

At incoming of new quotes, the start() function of the attached experts and custom indicators will be executed. If the start() function launched at the preceding quote was running when a new quote came, the new quote will be skipped by the expert. All new quotes income while the program was being executed are skipped by the program until the current execution of the start() function has been completed. After that, the start() function will be run only when a successive new quote incomes. For custom indicators, the start() function will be launched for recalculation after the current chart symbol or timeframe has been changed independently on new quotes incoming. The start() function will not be run when the expert properties window is open. The latter cannot be opened during the expert execution.

 
Rosh :

See Program Run:

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.

Every program attached to a chart completes its work with the deinit() function. The deinit() function runs at the client terminal shutdown, at chart closing, immediately before the symbol and/or chart period is changed, at successful recompiling of the program, at changing of inputs, or at changing of the account. One can see the reason of deinitialization using the UninitializeReason() function during execution of the deinit() function. The deinit() function must be executed within 2.5 seconds. If the function has not completed its execution within this time period, it will be completed forcedly. Scripts are an exception to this rule, as they normally finish their working independently, without any commands from outside. If a script works very long (due to endless loop, foe example), it can be finished by an outside command (at deletion of the script from the chart context menu, at attaching of a new script to the same chart, at closing of the chart, at changing of the symbol and/or chart period). In this case, the deinit() function is limited by 2.5 seconds, too.

At incoming of new quotes, the start() function of the attached experts and custom indicators will be executed. If the start() function launched at the preceding quote was running when a new quote came, the new quote will be skipped by the expert. All new quotes income while the program was being executed are skipped by the program until the current execution of the start() function has been completed. After that, the start() function will be run only when a successive new quote incomes. For custom indicators, the start() function will be launched for recalculation after the current chart symbol or timeframe has been changed independently on new quotes incoming. The start() function will not be run when the expert properties window is open. The latter cannot be opened during the expert execution.

Yes, thank you, I've read this... it doesn't answer my question.

Does init() complete or does start() have priority? (or is there a 2.5 second window that init() has to complete in) etc., etc.

-charliev

 
Check it yourself. I just can repeat that it is not recommended to put hard calculations in init() function.
 
Rosh :
Check it yourself. I just can repeat that it is not recommended to put hard calculations in init() function.

Well, everyone has always been VERY helpful to me. Is it possible to get a definative answer from programming/development? I can attempt to test this, only to miss something and end up with incorrect information.

I'm using init() to write a text file (of BAR history, HLOCV). So the concern is that it ALWAYS completes prior to servicing a TICK.

I appreciate any help for a definative answer.

Thank you.

-charliev

 

"I'm using init() to write a text file (of BAR history, HLOCV). So the concern is that it ALWAYS completes prior to servicing a TICK."

Why not write the code in start, so that it executes one time, the first time start() is called.

 
phy :

"I'm using init() to write a text file (of BAR history, HLOCV). So the concern is that it ALWAYS completes prior to servicing a TICK."

Why not write the code in start, so that it executes one time, the first time start() is called.

Then I'd be out-of-sync with these functions... (when I'd want a new history to be created)

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.

The whole thiing simplifies, if init() is DESIGNED to complete without having start() interrupt it.

-charliev

Reason: