DennisGundersen / MT4-To-CSharp-Bridge-Using-DNNE

A prototype for connecting unmanaged code in Metatrader 4 (MQL) to managed code (C#) in modern .NET (6+) using DNNE
MIT License
1 stars 2 forks source link

Metatrader 4 to C# (.NET 6+) programming bridge using DNNE

A prototype / tutorial for connecting unmanaged code in MT4 (MQL) to managed code (C#) in modern .NET (6+) using DNNE.

Goal

The goal of this project was to create a simple, reuseable and generic C# library project who's dll can be loaded into MQL in order to extend MT4 to take advantage of any modern .NET solution (.NET 6+). No actual foreign exchange trading strategies will be included in this project, it's just a prototype showing how to do the "plumbing" in order to enable your own ideas using C# and modern .NET. Note: Passing strings from MQL to C# is supported, but from C# to MQL is not currently supported.

Usage

  1. Download or clone the repository into Visual Studio.
  2. Make sure Debug and Release condigurations are set to x86.
  3. Restore/update DNNE from NuGet.
  4. Compile the project and publish it to a folder with the settings below (see section on DNNE below for details). Settings Publishing
  5. Copy YourProjectName.dll, YourProjectNameNE.dll and YourProjectName.runtimeconfig.json to the /MQL/Libraries folder (see section on MT4 below for details).
  6. Normally, for MT4, you would copy any extra dlls (from added projects or NuGet packages) to the MT4 instance's installation folder (ex: C:\Program Files (x86)\MT4 DEV), but with DNNE loading the files, you must instead place all the dll's in the libraries folder.
  7. Copy the MQL file DNNETest.mq4 to /MQL/Experts.
  8. Open the MQL Editor and compile the EA.
  9. Add EA to running chart by dragging it from the Navigator window.

About MT4

MetaTrader 4 is an electronic trading platform for foreign exchange traders by MetaQuotes. It has a simple built in programming IDE (MetaQuotes Language Editor, press F4 inside MT4) with is own language (MQL) which has a C++ like syntax. MQL allows traders to automate actions and strategies as well as connecting to external tools such as MatLab, R or AI. MT4 itself is available for free from any number of Forex brokers, just open a demo account and download the client. Note: Since version 600, MT4 has implemented antidebug software stopping external debugging.

Hints about programming in MT4

About DNNE

Dot Net Native Exports (DNNE) is an open source project being developed by Aaron Robinson (a "product owner" of .NET InterOp at Microsoft). Source code is available at https://github.com/AaronRobinsonMSFT/DNNE, and it's installable from NuGet.

Acknowledgments

Great thanks to Jerzy Brzozowski ([@GroM] https://www.github.com/GroM), Andrei Gireada, Jimmy Luo, [@ThaDaVos] (https://github.com/ThaDaVos) and [@AaronRobinsonMSFT] (https://github.com/AaronRobinsonMSFT) who did all the work. I just asked questions and pestered people for help.