Discussing the article: "Websockets for MetaTrader 5: Asynchronous client connections with the Windows API"
Hello, I also think it is an excellent article.
I am developing an ea that uses multiple indicators. Initially I chose to functionalize the indicator calculations so they could be used in an indicator plot as well as in the EA. Upon testing in the strategy tester, I have found the Bars function returns a different value between the indicator running in visual mode and the value determined by the EA. Do you know how to report this and other bugs I have found in MLQ5 to the developers?
The simple solution was to use iCustom which I previously used in MQL4. However, the MQL5 version only allows CopyBuffer on the first indicator plot and many of my inidicators have multiple buffers plotted.
the solutions I can think of are to use your WebSockets to communicate between multiple indicators and the EA, named pipes to do the same, or separate the indicators into single buffer plots which will involve significant increasing processing due to the multiplicty of identical calculations as well as a nightmare trying to keep a dozen or more of indicators synchronized to insure accurate calculations.
As WebSockets is asynch what are the implications of the ea getting dozens of data streams from the indicators nearly simultaneously? Can it keep up or would there be overflows?
Any suggestions will be muchly appreciated.
Thank you for your response
CapeCoddah
Hello, I also think it is an excellent article.
I am developing an ea that uses multiple indicators. Initially I chose to functionalize the indicator calculations so they could be used in an indicator plot as well as in the EA. Upon testing in the strategy tester, I have found the Bars function returns a different value between the indicator running in visual mode and the value determined by the EA. Do you know how to report this and other bugs I have found in MLQ5 to the developers?
The simple solution was to use iCustom which I previously used in MQL4. However, the MQL5 version only allows CopyBuffer on the first indicator plot and many of my inidicators have multiple buffers plotted.
the solutions I can think of are to use your WebSockets to communicate between multiple indicators and the EA, named pipes to do the same, or separate the indicators into single buffer plots which will involve significant increasing processing due to the multiplicty of identical calculations as well as a nightmare trying to keep a dozen or more of indicators synchronized to insure accurate calculations.
As WebSockets is asynch what are the implications of the ea getting dozens of data streams from the indicators nearly simultaneously? Can it keep up or would there be overflows?
Any suggestions will be muchly appreciated.
Thank you for your response
CapeCoddah
Hi. You say:
The simple solution was to use iCustom which I previously used in MQL4. However, the MQL5 version only allows CopyBuffer on the first indicator plot and many of my inidicators have multiple buffers plotted.
That is not corect. You can copy any buffer you want. All three overloads of the CopyBuffer function allow you to copy any buffer you specify. Using the first version (shown below) as an example:int CopyBuffer( int indicator_handle, // indicator handle int buffer_num, // indicator buffer number int start_pos, // start position int count, // amount to copy double buffer[] // target array to copy );
The the second parameter 'buffer_num' allows you to specify which buffer to copy - starting at index 0 as first buffer, 1 for second buffer etc., allowing you to copy any buffer you desire from your custom indicator. An example of this is the built-in iMACD which has 2 buffers (0 - MAIN_LINE, 1 - SIGNAL_LINE). I would suggest you focus on iCustom indicator to solve your problem before trying WebSockets or Sockets of any kind for that matter. It is much simpler solution, which does not require any external libraries like C++ DLLs etc. Always try using the MQL5 language as much as possible, and avoid DLLs unless absolutely necessary. I develope in C, C++, C# and more, and I can tell you from experience that sticking to MQL5 (an extremely powerful language despite its limitations - as with any other language) is the best approch.
Let me know how you progress. If you face any issues with 'CopyBuffer' feel free to ask. If you're venturing to MQL5 from MQL4, some things are done differently, hence your MQL4 knowledge might not be directly transferrable. But keep going, MQL5 is much better, significantly more powerful and faster.
Good luck.
It might help to see some example code at:
Ryan L Johnson, 2025.04.29 19:52
This indicator calls 3 other subwindow indicators. All files go in your Indicators folder.I thank both of you for your response to my question. I must have missed the overloaded function definitions and only read about the first. Do you possibly know if Terminal is smart enough to parallel process the iCustom calls to maximize processor utilization's as I plan to vary the symbol parameter for each of the 28 pairs and plan to have multiple iCustom calls like the Brooky Trend Strength.
Also can either of you tell me where I can post comments on bugs in MQ5 and also where suggestions for the Mq administrators. I have found a few, most recently the Bars difference between the terminal and the strategy tester. Also, I have a 3 screem setup with the main display on the far left. Trying to move a panel. such as the Navigator or Market panels, from the left to the right is very tedious. The drag mouse pointer is on the left most screen but the dragging panel is in the middle. I think either the Terminal or Windows is going crazy when the mouse moves one pixel and then switches displays to move the panel one pixel and back again
Do you possibly know if Terminal is smart enough to parallel process the iCustom calls to maximize processor utilization's as I plan to vary the symbol parameter for each of the 28 pairs and plan to have multiple iCustom calls like the Brooky Trend Strength.
Not a problem. You just need separate instances of indicator handles and CopyBuffer()'s. Even though all indicators run in the same thread, you can run 100 or so indicator instances.
Also can either of you tell me where I can post comments on bugs in MQ5 and also where suggestions for the Mq administrators. I have found a few, most recently the Bars difference between the terminal and the strategy tester.
Bars() will hiccup where there is missing price data--where rates_total will not. If I remember correctly what I read in the past, Bars() can be fixed by referencing time stamps. Might be worth a search.
I have a 3 screem setup with the main display on the far left. Trying to move a panel. such as the Navigator or Market panels, from the left to the right is very tedious. The drag mouse pointer is on the left most screen but the dragging panel is in the middle. I think either the Terminal or Windows is going crazy when the mouse moves one pixel and then switches displays to move the panel one pixel and back again
I really don't know on this one. I have 3 computers, each having its own monitor and terminal. I do know that Windows generally has multiple monitor display settings, including picture-in-picture maybe as a workaround.
Can someone else with real multiple monitors on a single machine chime in here, please?
Great Information!!!
Thanks Ryan, your comment regarding bars vs rates_total is appropriate. My problem is that the two are identical in Terminal but in the STrategy Tester Visualize, Bars is one greater which led to my bobo by not reading the documentation to the end. I am going to take your input and use it for iCustom. I presume that there must be a separate iCustom address for each combination of Symbol and Time specifications.
Also, is there any way for an EA to display Text on the screen in the Strategy Tester? In Mq4 it did it automatically but not now. I use a lot of class objects to display information and putting a second copy in the template slows the Strategy Tester even more.
On the 3 panel display, I think the problem is the terminal does not properly update the monitor location when the mouse moves from screen 2 to screen 1.
I have 2 mini pcs that each support 3 monitors so I have the 3 screens attached to both minis and use HDMI1 for one pc and HDMI2 for the other. Works great with 43" Fire Tvs although you must make sure the remotes are properly configured to control just one monitor (call amazon support). The only drawback is the on off button shuts down all monitors and sometimes I need to pull the plug to synchronize power.
CapeCoddah
My problem is that the two are identical in Terminal but in the STrategy Tester Visualize, Bars is one greater which led to my bobo by not reading the documentation to the end. I am going to take your input and use it for iCustom. I presume that there must be a separate iCustom address for each combination of Symbol and Time specifications.
- A single indicator file in a single directory can be reused by multiple instances of iCustom().
- A single indicator handle can be reused by multiple instances of CopyBuffer().
- I now understand why you're using Bars(), as rates_total alone is limited to a single timeframe. Presumably, you're using Bars() in a separate loop for each timeframe.
Also, is there any way for an EA to display Text on the screen in the Strategy Tester? In Mq4 it did it automatically but not now. I use a lot of class objects to display information and putting a second copy in the template slows the Strategy Tester even more.
On the 3 panel display, I think the problem is the terminal does not properly update the monitor location when the mouse moves from screen 2 to screen 1.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Check out the new article: Websockets for MetaTrader 5: Asynchronous client connections with the Windows API.
This article details the development of a custom dynamically linked library designed to facilitate asynchronous websocket client connections for MetaTrader programs.
The article, "WebSockets for MetaTrader 5: Using the Windows API", illustrated the utilization of the Windows API for the implementation of a websocket client within MetaTrader 5 applications. The implementation presented there was constrained by its synchronous operational mode.
In this article, we revisit the application of the Windows API to construct a websocket client for MetaTrader 5 programs, with the objective of achieving asynchronous client functionality. A practical methodology for realizing this objective involves the creation of a custom dynamically linked library (DLL) that exports functions suitable for integration with MetaTrader 5 applications.
Accordingly, this article will discuss the development process of the DLL and subsequently present a demonstration of its application through an MetaTrader 5 program example.
Author: Francis Dube