See search results - threads
See search results - threads
Thanks Rosh, found this article that answers my question...
https://docs.mql4.com/runtime/running
Extract below is from that article pertaining to the thread context of experts, scripts and indicators.
Execution of scripts does not depend on incoming quotes. At change of symbol and/or chart period, the script will finish its work and be unloaded from the client terminal.
Scripts and experts work in their own thread. Custom indicators work in the main interface thread. If a custom indicator has been called with the iCustom() function, this indicator works in the thread of the program that has called it. Library (imported) functions work in the calling program thread, as well.
Scripts and experts work in their own thread. Custom indicators work in the main interface thread. If a custom indicator has been called with the iCustom() function, this indicator works in the thread of the program that has called it. Library (imported) functions work in the calling program thread, as well.
One follow up question Rosh if I may.
Given that experts run in their own thread I believe may have found an odd quirk with respect to the thread context in which experts actually run.
I think that the init() function of an expert runs in an initial thread which then ends when the init() function finishes running.
The very first time an incoming tick is then processed by the expert a new thread is created in which the start() function runs.
When the start() function ends this thread remains active. All future calls to the start() function of the expert are run in the context of this thread.
This behaviour is not evident in scrips. The init() function and start() functions of scripts seem to run in the same thread context.
Am I correct in thinking that with respect to experts the init() function runs in a thread which ends when the init() function has finished running and that the start() function of the expert runs in a different thread which is created which is first created when the first incoming tick is processed by the expert?
Regards,
Laurence.
Given that experts run in their own thread I believe may have found an odd quirk with respect to the thread context in which experts actually run.
I think that the init() function of an expert runs in an initial thread which then ends when the init() function finishes running.
The very first time an incoming tick is then processed by the expert a new thread is created in which the start() function runs.
When the start() function ends this thread remains active. All future calls to the start() function of the expert are run in the context of this thread.
This behaviour is not evident in scrips. The init() function and start() functions of scripts seem to run in the same thread context.
Am I correct in thinking that with respect to experts the init() function runs in a thread which ends when the init() function has finished running and that the start() function of the expert runs in a different thread which is created which is first created when the first incoming tick is processed by the expert?
Regards,
Laurence.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
From a programming perspective am I correct in thinking that every script and expert runs in its own separate thread and that all indicators attached to charts run in the context of a single thread?
For example:
If I have say 10 indicators spread across 6 charts then ALL those indicators run in the same thread.
If I have 3 experts running and 5 scripts then they run in 8 separate threads.
In total 10 indicators (1 thread) 3 experts (3 threads) and 5 scripts (5 threads) for a total of 9 threads.
I am doing some DLL programming and I have found that indicators always seem to run in the context of a single thread. Could someone from metaquotes please let me know if this is indeed the case.
Regards,
Laurence.