- is much faster in running complex calculations than MT4 is,
- it allows to implement multithreading,
- provides all the flexibility of a modern Object Oriented Language.
The method is well described here: https://sites.google.com/site/robertgiesecke/ It is just a Visual Studio Project Template that will modify the compilation options and expose managed methods for unmanaged calls. Short problem background: MetaTrader is written in C++ and allows linking external libraries with functions, variables, etc... If you create a library in C++, the code is compiled and the *.dll can be executed directly (so the *.dll is a set of instructions that can be sent to the CPU and executed). Linking C++ libraries with MetaTrader is extremely easy. However, in managed languages like C# or VB.NET, the code is compiled into an Intermediate Language (MSIL). This is then run by the run-time engine (.NET Framework) and translated into the machine code that is executed by the CPU. In general there are many methods of calling the managed code from unmanaged one (to name a few: C++/CLI wrappers or COM interop), but this one is definitely the easiest.
So how I am using C# libraries? I have a SQL Server database containing good quality 1-minute data for several instruments. And I use C# to execute algorithms against this data set. Example: In the current project I am working on I have completely moved the processing logic to C# through three functions:
C# Definitions:
MQL Imports:
I use the C# library in the following way:
- When the Expert Advisor starts (MQL init function) I call the initDB function. What this function does, it will initialize the C# algorithm and load the data from SQL Server to memory (so the calculations will be placed fully in C# to improve calculations performance).
- Then I just pass some data from MetaTrader to getProbability function in C#. This will do all the maths, based on the most recent price data and settings received. It will return calculation results back to MQL and MQL will execute the trading logic.
- When the expert advisor will shut down, I am just calling the deInitDB to cleanup after the algorithm.
More information about what I am trying to achieve through this will follow...


No comments:
Post a Comment