Most Expert Advisors do not need a DLL. Although programming in MQL is fairly limiting, it suffices for 99% of expert advisors. DLL programming for MetaTrader is only appropriate whenever MQL does not offer a capability that the EA needs.
What is a DLL?
DLL stands for dynamic link library, which is not the least bit helpful in understanding what it does. Conceptualize a toolbox full of tools. The DLL itself is the toolbox. The “stuff” in the DLL is the tools that the expert advisor or indicator uses to make decisions. The MQL simply decides which tool to use at which time.
MetaTrader allows Expert Advisors the ability to control whether or not MQL may use a DLL. This option is the first one appearing in the screenshot above. The indented option to “confirm DLL function calls” is a subset of this option. Whenever MT4 wants to use a DLL, it will prompt the user with a yes/no message box every single time that the DLL is used. It’s very annoying. MetaTrader would be better off without this option as it confuses most users.
When to program a MetaTrader DLL
I often encounter the need for a DLL whenever I plan to do mathematically intensive programming. MQL runs extraordinarily slowly for a programming language. Whenever an EA wants to process several million calcualtions, it tends to freeze. MetaTrader suspects that it fell into an infinite loop and chokes.
Moving those calculations into a DLL passes that responsibility for calculating the numbers to a more powerful language. MetaTrader only likes C/C++ or Delphi, which are referred to as higher level. The MQL programmer can control the physical hardware in order to optimize performance if it’s required. That would ususally be overkill. A generic dll program written C will run many, many times faster than the same code in MQL. We only program DLLs at OneStepRemoved in C or C++ (read as C plus plus).
Sell products in MetaTrader
MQL is a programming language designed entirely for trading. Anything that extends outside the sphere of trading, such as connecting to a database or reading information from a server, is not supported.
A business that wants to sell an Expert Advisor absolutely needs a DLL. The higher level languages easily support web operations that can authenticate who is and is not allowed to use a file.
More importantly, high level languages offer dramatically stronger encryption options. Decompiling an MQL file, which means breaking it open to steal the contents, only costs about $10-15 if you do enough Google searches. Cracking a DLL file takes much more work. Even an unencrypted file might take a programmer a few work full works days to open. Cracking an encrypted DLL could take months if the crack to the encryption is not known. Although anything that can be encrypted can theoretically be deencrypted, it becomes a matter of scale and resources. Would cracking your file warrant someone’s full time employment for several months? The answer is no for all but the most sensitive of material.
Bridge multiple instances of MetaTrader
Occasionally, traders design Expert Advisors that need to receive information from multiple brokers at the same time. Broker arbitrage and trade copiers fall firmly into this category. In the case of the trade copier, the MT4 account that wants to copy another account needs to know what is happening. The DLL stands in the middle between them as a path to pass information back and forth.
Many other problems are most appropriately solved with a DLL. If you aren’t sure if it makes sense for your situation, then please contact me.