Pseudo-Indicator with Asynchronous Multi-Threaded Calculations Demo
This software component for MetaTrader 5 is built to enhance the capabilities of your trading environment. This technical indicator acts as a specialized analysis tool designed to visualize market data. It helps traders identify emerging trends, momentum shifts, and key support or resistance levels by plotting statistical calculations directly onto price charts.
How to Setup and Use Pseudo-Indicator with Asynchronous Multi-Threaded Calculations Demo
1. Installation: Place your file in the MQL/Indicators folder via "Open Data Folder" and restart your terminal.
2. Loading: Find the indicator in the Navigator, drag it onto your chart, and configure the input parameters in the popup window.
3. Customization: Press Ctrl+I to open the indicator list, select your tool, and click "Properties" to change colors, levels, or visual styles.
4. Updating: Replace the old file in the Indicators folder with the new version and restart the platform to apply changes.
Frequently Asked Questions
Q: Why is my indicator not showing? A: Verify the file is in the MQL/Indicators folder, or try right-clicking the "Indicators" tree in the Navigator and clicking "Refresh."
Q: Do custom indicators slow down the platform? A: Too many complex indicators can impact performance; remove unused ones via the "Indicator List" (Ctrl+I).
Q: Can I use MT4 indicators on MT5? A: No, MQL4 and MQL5 are distinct languages; ensure the indicator is compiled specifically for your platform version.
Description & Settings
This indicator is a pseudo-indicator w/o buffers. Its only purpose is to demonstrate multi-threaded calculations technique. The indicator can issue commands for lenghty calculations which are performed in separate threads, created for chart objects with worker expert adviser. The classes provided in the included header file -
MultiThreadedObjectWorker.mqh
- will automatically create the chart objects and apply template with specified worker expert adviser in each object. After calculation is done the object is automatically removed from the chart.
This example is intended for users with programming background.
The idea comes from the article about . Please, find all technical details on how the messages (events) are dispatched, and how resources are used to pass data between charts in the article.
The indicator utilizes more "compact" implementation of the techique than in the article by using chart objects instead of full-fledged chart windows. You may find details on the .
Make sure the worker expert adviser -
MultiThreadedObjectWorker
- is compiled before you compile and run the indicator itself -
MultiThreadedIndicator
.
Input parameters
sinput int _Cores = 1; - number of threads to utilize (don't use more than available physical cores)
sinput int _Tasks = 1; - number of pseudo-tasks to execute in parallel (use number larger than number of cores to see parallel performance)
input string MultiThreadedScriptPath = "Experts\\MultiThreadedObjectWorker.ex5"; - must indicate the pathname of the worker expert adviser
Each pseudo-task calculates a bunch of sqrt functions (for demo purposes only). This can be changed in your MQL projects to any other time-consuming algorithms.
To start parallel calculations after the indicator is attached to a chart, please, click the chart. All important phases of the process (both in client and worker MQL5 programs) are logged.
The client MQL programm issuing parallel calculations requests can be not indicators only but expert advisers as well. Scripts and services are not supported by the platrform.
Using the header file MultiThreadedObjectWorker.mqh you should implement your own data marshalling between MQL5-client and the worker expert adviser.
Here is 2 examples of the logs.
Execution of 4 tasks on 2 cores (2 threads in parallel)
When running 4 tasks on 2 cores there are 2 parallel threads, that provides twice as fast execution as on 1 cores (compare 3354ms above and 6240ms below).
Execution of 4 tasks on 1 core (single thread - standard MQL program)
More cores - more speed.