Sending orders to MT5/MQL5 from external .NET code (C# or other)

 

Hello,


I would like to send order entry and exit signals from an external software application I am developing in C# .NET.

Could anyone help me understand how I can accomplish this?


Thanks!!!

 

I know of a way how it was done with MT4 by OpenForexPlatform (just google), look for MT4-Integration there. They made a C++ DLL that communicated with C#.net via TCP/IP. The C++ DLL was called in a specialized (but simple) MT4 expert advisor.  

On the other hand, I wonder if it could not be made easier, like just calling a C#.net DLL directly from an expert advisor. 

see the files below - please note that they are under GPL open source license, and I only redistribute them here, without any legal responsibility.
(author- and ownership is by openforexplatform.com)

Files:
 
okx:

I'm also very interested to know how MT5 improves on MT4's ability to communicate with an external agent.

 I integrate my platform using 2 EA's.  One EA does Socket communications incoming, and executes Orders as the result of commands.

 The other EA is responsible for using Socket comms to return status, etc to my Client software.

I can tell you that, although this works, it has a lot of undesirable aspects.

 For example, both EA's are in loops and the Feedback EA has to be in a tight timed wait loop looking for multiple variables.

 The OrderManager accepts a command and dispatches, but has to use Global Variables to post status, etc. which the Feedback EA tries to grab as quickly as possible.

 So, this Feedback EA has to constantly loop, looking for Global Variables, getting their values, clearing them, and then sending Socket messages back to my client.

 So, although this works, it is a very poor integration solution for sending Orders to a MetaTrader terminal.

 I'd LOVE to be able to access a MetaTrader 5 API, and direct it to do the trading, and provide me with much better status info and control.

The most desirable solution would be if I could control MT5 as an in-process subsystem to my client.

Any ideas about a better integration arrangement?  .NET components? "Headless" operation?

 FutureScalperFX 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 

I wrote a while ago about c# integration, it may be helpful.

 

https://www.mql5.com/en/articles/249 

Exposing C# code to MQL5 using unmanaged exports
  • 2011.02.09
  • investeo
  • www.mql5.com
In this article I presented different methods of interaction between MQL5 code and managed C# code. I also provided several examples on how to marshal MQL5 structures against C# and how to invoke exported DLL functions in MQL5 scripts. I believe that the provided examples may serve as a basis for future research in writing DLLs in managed code. This article also open doors for MetaTrader to use many libraries that are already implemented in C#.
 
recently saw another free way to program C# for MetaTrader
http://tradeplatform.codeplex.com
TradePlatform.NET - Home
  • tradeplatform.codeplex.com
TradePlatform.NET is addition to MetaTrader 4 client terminal which extends trading experience, MQL language and provides .NET world communication bridge.
 
Use named pipes. https://www.mql5.com/ru/forum/7806#comment_314433
Использование MQL5 для торговли на МТ4
  • www.mql5.com
Подскажите, можно ли каким-нибудь образом извернуться, чтобы с помощью программ на MQL5 торговать у брокера, поддерживающего МТ4?
 
Regardless of the integration solution you use, I recommend you do not open your trades without  well defined stops (mainly stop loss), since any communication problem can generate large losses.