Giter Club home page Giter Club logo

mt4-to-csharp-bridge-using-dnne's Introduction

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

  • You can program visual clues as "Indicators", or automate trading using "Expert Advisors" (EA). This project is an EA, but can be called the same way from an indicator.
  • To allow autotrading and usage of external code in MT4, go to Tools, Options, Expert Advisors and enable "Allow automated trading", "Allow DLL imports". Settings
  • If calling web apis from MQL, check "Allow WebRequests for listed URL" (+ the URLs to be used).
  • MT4 only accepts "x86" runtime compilations (so no "AnyCPU")
  • Normally, the initial external file such as your main C# dll must be placed in the MT4 instance's "Data Folder"/MQL4/Libraries/ folder, while any additional files (external projects, NuGet packages etc.) would be placed in the MT4 instance's installation folder to be found. HOWEVER, using DNNE to load files means all external files will be loaded from the same directory as your starting point; so put ALL files in /MQL4/Libraries/ folder.
  • The included MQL sample "DNNETest.mq4" is an EA and must be placed in the "Data Folder"/MQL4/Experts/ folder and compiled there. Editor
  • Your compiled code can now be run by dragging the file from the Navigator window onto the active trading window. MT4
  • MQL uses the "Expert" window for logging, rather than the normal "Journal" window.
  • MQL strings are unicode.
  • MQL dates uses Unix time (1/1/1970).

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.

  • Note that DNNE must be set to "win-x86" in .csproj, along with some other properties referred to as DNNE.props in the guide.
  • Due to DNNE using compiler settings, the project must be published to a folder, don't just take the files from the /bin directory.
  • With current settings, your code in YourProjectName.dll is executed by DNNE in YourProjectNameNE.dll (as an adapter) while the .NET version is wired up in YourProjectName.runtimeconfig.json. To merge files, see DNNE guide.
  • Correct .NET Runtime (the release AND must be x86 version) must be installed on the MT4 instance' machine.

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.

mt4-to-csharp-bridge-using-dnne's People

Contributors

dennisgundersen avatar grom avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

grom

mt4-to-csharp-bridge-using-dnne's Issues

MQL5 version

Hi Dennis,

First of all, I would like to thank you for the fantastic work you have done with the MT4-To-CSharp-Bridge-Using-DNNE project. Your solution is extremely useful and well-executed, making it much easier to integrate MT4 with C# applications.

I would like to ask if it would be possible to extend the support of the project to Mql5. Many users, including myself, use this platform and a version compatible with MQL5 would be highly beneficial.

I understand that this might require significant effort, but I am confident that many in the community would greatly appreciate this addition.

Thank you again for your work and for sharing this project with the community.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.