Discussion of article "Data Exchange between Indicators: It's Easy"

 

New article Data Exchange between Indicators: It's Easy is published:

The article describes an easy method to develop a program environment for the MetaTrader terminal, that would provide means for accessing indicator buffers from other MQL programs.

Author: Алексей

 
There is a very serious warning for those who use frequent calls of DLL functions like Get/Set.


For the sake of system security, each DLL call goes through a special stripper, which slows down execution. DLL function call is not a banal call XXXX, but a complex wrapping with address masking, stack control and crashes inside the DLL. MQL5 makes it so that if a function inside the DLL messes up the stack or crashes, the script execution will stop without crashing the terminal itself.

General advice on using DLL functions: try to make rare calls with a large amount of work inside, rather than tens of thousands of calls per second with passing small results.

 

I wonder. Why not go further?

As Renat pointed out, calling cheap functions from a dll is expensive.

So why not copy data directly into the array provided for this purpose?

 
TheXpert:

I wonder. Why not go further?

Who is the question addressed to - the author or the developers?

If to the developers, what exactly do you suggest?

 

Is there an error in the StringExplode function? In its current form, it does not copy the last component of the string if there is no delimiter after it (i.e. at the end of the string). IMHO, the end of the string should be taken even if there is no delimiter at the end. Example: we feed the string"EURUSD,EURJPY" with the delimiter "," and the function now selects only EURUSD.

Here is the corrected version of the function, for convenience I have returned the number of elements:

int StringExplode(string s, string separator, string &result[])
{
  int i, pos;
  ArrayResize(result, 0);
   
  for(i = 0; ; i++)
  {
    ArrayResize(result, ArraySize(result) + 1);
    pos = StringFind(s, separator);
    if(pos >= 0)
    {
      result[i] = StringSubstr(s, 0, pos);
      s = StringSubstr(s, pos + StringLen(separator));
    }
    else
    {
      result[i] = s;
      i++;
      break;
    }
  }
  
  return(i);
}
 
Renat:
There is a very serious warning for those who use frequent calls of DLL functions like Get/Set.


For the sake of system security, each DLL call goes through a special stripper, which slows down execution. DLL function call is not a banal call XXXX, but a complex wrapping with address masking, stack control and crashes inside the DLL. MQL5 makes it so that if a function inside the DLL messes up the stack or crashes, the script execution will stop without crashing the terminal itself.

General advice on using DLL functions: try to make rare calls with a large amount of work inside, rather than tens of thousands of calls per second with the transfer of small results.

By the way, one more remark about multiple DLL calls - during testing I noticed that memory leaks of several bytes occur at each call

marketeer:

Is there no error in the StringExplode function? In its current form it does not copy the last component of the string if there is no delimiter after it (i.e. at the end of the string). IMHO, the end of the string should be taken even if there is no delimiter at the end. Example: we feed the string"EURUSD,EURJPY" with the delimiter "," and the function now selects only EURUSD.

Here is the corrected version of the function, for convenience I have returned the number of elements:


Thank you, I didn't pay attention to it. You can see because the last element in the descriptor is a random number, which has no meaning.

---------

Thank you! I will implement all suggestions for improvement as far as possible. The idea itself is good, I would like it not to stall.

 
Renat:

Who is the question addressed to - the author or the developers?

If to the developers, what exactly do you suggest?

Author. You can pass the array size together with it, then you can organise one-time copying of the array directly from memory to memory -- very cheap and bypasses the problems in MQL4 with element-by-element references. I have a lot of things to do now, otherwise I would have written an example.... I hope you get the gist of it.

In advance... -- if you use locks and implement the transfer correctly, this approach should be safe.

 

How complicated it is!...

With the help of Ilnur a year ago I wrote a library in MQL4 for working with memory. You can allocate memory, move pointers, write and read, transfer the name of memory area to any other programme.

Everything is based on mapping. It is much simpler than the proposed one.

 
Zhunko:

How complicated it is!...

With the help of Ilnur a year ago I wrote a library in MQL4 for working with memory. You can allocate memory, move pointers, write and read, transfer the name of memory area to any other programme.

Everything is based on mapping. It is much simpler than the proposed one.

The point is that in the proposed approach you don't need to allocate memory and move pointers. Reads and writes are organised directly into the buffer. This is much simpler than mapping.
 
Renat:
There is a very serious warning for those who use frequent calls of DLL functions like Get/Set.


For the sake of system security, each DLL call goes through a special stripper, which slows down execution. DLL function call is not a banal call XXXX, but a complex wrapping with address masking, stack control and crashes inside the DLL. MQL5 makes it so that if a function inside the DLL messes up the stack or crashes, the script execution will stop without crashing the terminal itself.

General advice on using DLL functions: try to make rare calls with a large amount of work inside, not tens of thousands of calls per second with passing small results.

Correction: since build 240 delays on DLL calls have been removed. Now they go practically without delays as in native.
 

Thank you very much to the author, it is not a small library, with proper use and

and "crosses that do not contradict the laws of genetics" you can get good results.

I, for example, finally "pulled" the data from offline charts, in online mode))). MT4 platform.


A spoonful of tar)))

More than once there were situations when in the list of global variables

in the list of global variables were "old" for some reason not deleted.

I can't figure out the reason for this yet.