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
Speed
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.
ciao
i’m interested in your dll programming capabilities
i absolutely need multithread on mt4 backtest optimization, with the possibility to use all cpu cores of a pc, and all cpu cores in my lan. i know it should be possible using dll programming on mt4. can you help me?
thanks
Hi Paolo,
MT4 is limited to a single core – there’s no way to multithread the DLL to speed up your backtests. I wish I could help, but it’s a design flaw in MetaTrader 4.
Hi Shaun,
I have got an indicator that i want to sell online.
How do i use DLL or anything else that prevents people from redistributing my indicator once they purchase my indicator online?
Thank you,
Reynard
Hi Reynard,
Please contact me directly. I have a solution named Trader Lockdown that does exactly that.
–Shaun
Thank you for this professional article.
Hi Shaun,,,
Great article and your expertise on metatrader-dll is highly appreciated. I need your help in converting some of the code in my EA into dll,,,,for speed/efficiency purposes and also for security. Kindly assist.
Thanks.
Njuguna.
Hi Njuguna,
Please email your EA to info@onestepremoved.com in order to receive an estimate.
–Shaun
So is there a way to have a backtest on a ea you want to test on strategy test That you say “alllow DLL imports “I’m really want to test on my ea on strategy test and is there a way to enable it to run on strategy test?
The EA can refuse to run all backtests regardless of whether a DLL is involved or not.
Hi Shaun,
How to Receive mt4 data from proxy server between client and server, can you guide me to general steps , thank you .
That’s not something that I expect to cover soon.
Hi Shaun,
thank you for your great sharing above
I have a question, if I’m going to build a EA that wish to check equity or balance if down to certain level, then :
1) close all running and pending orders (even open by other EAs)
2) stop new others from any other EAs
believe (1) no need DLL, while is that needs DLL coding?
thx.
Dennis
DLL is completely unnecessary for those tasks.
Hi. I am on the first time on your site. My English is not very well. Sorry.
I have one question How does any program Expert Advisor reads the price of EURUSD (or GBPUSD ,..) from editor of MT4?
Thank you. Kosta.
Use the function MarketInfo()
Need tour help
I have an EA that i want to sell
But its need to call an indicator ans a dll file
Aldo i have problèmes of checking trade volume before sends orders
Help me please
Hi Khaled,
Please email info@onestepremoved.com and ask about Trader Lockdown.
–Shaun
Can someone access all the files on my system through enabling DLL. Or the programmer only have access to my platform
Theoretically they could, but your antivirus would likely detect that kind of attempt.