Discussion on "How to write a DLL for MQL5 and exchange data in 10 minutes".

 

Published article How to write a DLL for MQL5 in 10 minutes and exchange data?:

As it happens, few developers now remember how to write a simple DLL, and what are the peculiarities of linking heterogeneous systems. In 10 minutes, I will try to demonstrate the entire process of creating simple DLLs and discuss some technical details of our binding implementation. I will show the step-by-step process of DLL creation in Visual Studio with examples of passing different types of variables (numbers, arrays, strings, etc.) and protecting the client terminal from crashes in custom DLLs.

Author: Renat Fatkhullin

 

A very interesting article. It's missing for the sake of completeness:

1. Where do we get the quotes, can they be taken from hst files?

2. How to make this library compatible with the one in the 2009a or 2009b MateLab? Don't they also have C and C++ there?

A very big request.

 
  1. Quotes are taken from the terminal - they are now both detailed and deep (10 years and more).

    Under no circumstances should we directly look into the binary files of the terminal storages - it will only cause serious data access conflicts. Even if the tests showed "it worked, no problems", still there will come a moment of simultaneous access to this data of terminal and external program, and someone will crash as a result. People have stumbled upon it many times.

  2. Docking libraries in MQL5 is now much easier, due to transparent support for stdcall / cdecl conventions on DLL calls.

    If someone writes a good and detailed article about linking MetaTrader 4/5 and Matlab via DLL, it will earn $200 or more.

    The MQL4.community already has articles on Matcad - MetaTrader 4 bundle:

Взаимодействие между MеtaTrader 4 и MATLAB Engine (виртуальная машина MATLAB) - Статьи по MQL4
  • www.mql5.com
Взаимодействие между MеtaTrader 4 и MATLAB Engine (виртуальная машина MATLAB) - Статьи по MQL4: особенности автоматических торговых стратегий
 
Renat, what about the speed of the dll calls?
I need to link two terminals so that they translate their quotes into Excel in real time.
In MT4 it could be done with DDE. In MT5 it seems that through DLL is the only way out.
But if each incoming tick will be passed to DLL... I think it will be something unimaginably slow. Of course I haven't tried to implement it yet... but honestly, I don't want to try it. It's going to be a nightmare.
In short, let's return DDE to MT5. It is an anachronism, but sometimes you may need it.

P.S. Thank you for this article, it is very timely. I have been missing just such a material.
 
Thank you !!!
 
benik:
Renat, what about the call speed of the dll?

It's very easy to check the call speed. For example, a rough calculation can be done like this:

_DLLAPI int __stdcall fnCalcSpeed(int var1,int var2,int var3)
  {
   return(0);
  }


#import "MQL5DLLSamples.dll"
int  fnCalcSpeed(int var1,int var2,int var3);
#import

   int calls=0;
   int ticks=GetTickCount();
   
   while(GetTickCount()-ticks<1000)
     {
      for(int i=0;i<1000;i++)
         fnCalcSpeed(1,2,3);
      calls++;
     }
   Print(calls * 1000, "вызовов в секунду");

I got 57,000 calls per second on a Quad Q9400 @2.66Ghz. The same code gives about 20,000,000 calls per second in MetaTrader 4, as there is no control and piping there.

We will definitely try to reduce the loss on DLL calls in MetaTrader 5.

 
Renat писал(а) :

57,000 calls per second

Ah, well, if there are about 50,000 calls per second, I think it's possible to broadcast quotes through the DLL as well. There won't be any losses.

Thank you for the code.

 
In the next build, the DLL call speed will be increased to 20 000 000 "empty" calls per second, like in MQL4.
 

If it is possible to export quotes only through dll, then it means that a script should be placed on each instrument to be exported? What if there are many of them? For example, 50?

I understand that it is possible to pass quotes for many instruments in one script, but it will not be a full-fledged substitute for DDE, where ticks are not lost.

 

The point is that we are not tasked with "providing a quotation interface".

Our aim is to create a complete and self-sufficient environment for developing analytical systems. Such an environment so that even third-party programmes do not need to be used.

 
In any case, Mql5 is a joy. Thanks
Reason: