Why prefer .NET to MQL for creating automatic trading experts

Authors of MetaTrader were guided by different considerations when creating a language for it, which led to the fact that instead of integrating with existing programming systems they have chosen to create a DSL (domain specific language). Thus, they have won for themselves independence of the platform, and also got an easy to learn scripting language. But programmers have lost significant opportunities which are present in any general-purpose programming environment, with nothing in return. One of the features of MQL is that programmers do not have control over the code, and any developments are visible for the broker. A dishonest broker sees how good your program is, and can easily run it and use for his own purposes without notifying you.

MQL did not become a DSL, because there is nothing that would have facilitated the work of the trader-programmer, which doesn’t exist in other general purpose programming language. The syntax and semantics of the language is very much based on C, and all features are implemented in the form of global functions. The only significant differences from C - implicit memory management, and the “string” type. With the same success they could take any other language as a basis, for example, Java or JavaScript.

In 2000, when MetaTrader was created, C# was gaining a momentum and it was hard to tell what would be the result. In 2012 .NET has unquestionably become the best development platform for Windows. All of the Windows technologies are available in .NET. You can refer to the operating system itself, and to work with the memory at a low level, but despite of that the language remains easy to learn. There’s an endless number of commercial and free libraries, which provide a solid background and let you focus directly on the task at hand, rather than the on the infrastructure.

Comparison of C# and MQL shows that MQL4 - it is almost a subset of C#, but C# is more convenient, starting from simple things, such as working with strings.

Example 1 - Remove the insignificant white space MQL:

string str1 = StringTrimLeft(StringTrimRight("    Hello world    "));

C#:

string str1 = "    Hello world    ".Trim();

A large number of functions is implemented in libraries. With .NET you can: work with Excel, generate reports and graphs, work with databases, work with Internet protocols, mathematical calculations, and more. Yes, you can use the pure MQL to write programs, yes, they do it a lot and the programs work correctly, but it’s like to farm the land with bare hands and simple instruments in the era of machinery and technics.

Programming C# experts in possible with NQuotes. NQuotes is a library that brings every feature from MQL4 to .NET, which allows you to create new programs for the trading in C# environment, as well as easily transfer old programs from MetaEditor to Visual Studio. A distinctive feature is that the API is presented in exactly the same form as in MQL. This means that to master NQuotes you can use all the knowledge about programming experts, and use the Help and Support from MQL4-programmers community.

If we consider C# as a DSL for trading, it is convenient due to features such as enumerated types (IEnumerable), LINQ query language and broad means of abstraction. For example, LINQ allows you to work with data streams as objects, rather than element by element, which is useful if you want to deal with a price quotations as with a continuous stream, the discrete function, and not just an array of values.

Example 2 - Calculate the sum MQL:

int count = ArraySize(values);
int sum = 0;
for (int i = 0; i < count; i++)
    sum += values​​[i];

C#:

int sum = values.Sum();

When the good automatic trading expert is created, it is important to think about the protection and preservation of information and intellectual property that you own (by your code). Something that can help you to do this is “obfuscators” - systems of binary code obfuscation, which will make it impossible to understand the program intrinsics. And the fact that the expert code is separated from the terminal by the .NET virtual machine protects from the broker sniffing.

Development tools must address the daily programmer problems, and let programmers concentrate on the primary task - modeling of the domain. C# has significant advantages compared with the limited built-in language of the terminal, and this is not only true in the general sense, but also true when applied to trading, and programming experts. You can try the library NQuotes - a solution for seamless integration between MQL and .NET.