Stocks News

“The MQL program seems to be causing MetaTrader to crash.” – Others – January 7, 2024

If you’ve ever heard or thought something like this from a title, it’s almost certainly not true.

MQL programs are compiled with the native MetaEditor tool and run within MetaTrader under full control. By design, MQL programs should not include any means of interrupting the terminal.

The only exception to the rule is when the MQL code imports a DLL. DLLs are binary programs that are outside the control of the terminal and can therefore have a destructive effect not only on the terminal but on Windows as a whole. This is why MetaTrader prevents DLL imports by default, and users must explicitly enable this on a per-single-instance basis at their own discretion and risk. If you’re running into a terminal issue that you think is coming from an MQL program, first check if you’re using a DLL.

Most publicly available MQL programs and all MQL programs available through the MQL Market do not use DLLs.

The MQL program itself should not be the cause of MetaTrader crashes unless a DLL is involved. Nevertheless, if this happens, it is most likely a terminal-induced error due to high load or other circumstances occurring while executing legitimate MQL commands and the built-in MQL API.

A nice analogue between a terminal and the MQL program running within it is a browser that displays a web page (nowadays, web pages use a variety of technologies, including JavaScript, graphics, multimedia, networking, databases, etc., just as MQL programs do). . You’ve probably seen moments when your browser crashes on a particular page. Was it the page’s fault or the browser’s fault? Even if we acknowledge that some pages may be poorly or maliciously written, browsers are responsible for handling them reliably. Errors must be intercepted and reported.

Since MetaTrader is a money management software, it must be robust and especially catch any errors that may occur in the MQL code. Especially considering that many authors of MQL programs are traders, not developers, and their mistakes are forgivable.

Division by zero or attempting to access an element outside the bounds of an array are examples of the most common errors encountered in MQL source code. Invalid pointer access or out of stack memory are less common, but so are unrecoverable runtime errors for a single MQL program written without precautions.

All such cases are blocked by MetaTrader and reported in the expert log. The MQL program that encountered the error is stopped and unloaded, but the terminal continues to run.

However, most errors are not considered serious and do not result in termination of the MQL program. For example, calling a mathematical function with an invalid argument (such as the square root of a negative number) or working with an invalid handle to a file or indicator are examples of this type of error. When these errors occur, your MQL program may produce incorrect results and may require user intervention anyway, but that’s another story.

Remember: no program is without flaws. For MQL programs, it is normal to have errors internally, but they should not affect the terminal.

The only bad thing about terminals that a basic MQL program can cause is infinite loops. When this happens in an expert advisor, script, or service, a single core of the CPU is loaded (until you stop it). When this happens on the indicator, parts of the MetaTrader GUI will crash. The last case is really dangerous, but it’s not technically a crash. These interruptions may occur because the indicators run on MetaTrader’s GUI thread. Personally I think this is a flaw in the terminal design. Because this violates the “sandboxing” principle that applies to MQL in many other respects (limited access to files, networks, other MQL programs, etc.). As a platform, MetaTrader must prevent harm resulting from the execution of MQL programs. Perhaps this issue will be fixed by the MQ team at some point.

So what to do if MetaTrader crashes unexpectedly? Try collecting all logs from terminal folder and crash log (for MT5 /Users/<사용자 이름>/AppData/Roaming/MetaQuotes/Crashes) provides MQ on the forum. We’ll try to reproduce the problem with minimal configuration (only a single chart and associated MQL program), and explain in detail how to do it. Try different MT builds and environments as workarounds to alleviate the issue before it is fixed and fixed.

Related Articles

Back to top button