Send orders to MT4 from Java via IP

 

Hello,

Is there any way to send simple orders (just BUY, SELL, CLOSE) to MT4 from another computer (which is running a Java app) via IP?

Don't need bi-directional communication; just uni-directional.

Thanks in advance.

 
Mariop: Is there any way to send simple orders (just BUY, SELL, CLOSE) to MT4 from another computer (which is running a Java app) via IP? Don't need bi-directional communication; just uni-directional.

Yes, but an interface for inter-process communications needs be coded, because it is not something available built-in. Coding that requires knowledge and experience and is not something that a beginner like yourself will be able to tackle very easily.

So head on over to the Freelance section and hire someone qualified to do it for you, but I doubt it will be inexpensive.

 
:) Thank you for your answer.
Nevertheless I think I'm not such a beginner, in fact I've already done more complicated things with C# years ago via TradePlatform.NET,  but this time I need to send them (the orders) from a Java program. So if there is any way that MT4 be able to receive orders in the way I've asked, I'm still waiting for more interesting answers.
 

I have already given you the most appropriate answer! You can always use files on a network to serve as the communications method, but that would be slow and cumbersome.

The fact that you have asked this question, says that as far as the MetaTrader/MQL programing environment, you are a relatively less proficient at MQL/MetaTrader. I say this because if you were very proficient at MQL and WinAPI, you would already have known about the various IPC solutions via channels, named pipes, TCP/IP, etc. - most of which are implemented via DLL libraries, but not necessarily so.

 
The easiest (though not easy) way to connect MT4 from Java would be with sockets, there are sample codes for MQL in the code base and articles.
 
Ovo:
The easiest (though not easy) way to connect MT4 from Java would be with sockets, there are sample codes for MQL in the code base and articles.

I have almost no experience of Java, but, if the two computers are on the same local network, then named pipes - supported by MQL4 via FileOpen() - might be possible and simpler.

http://stackoverflow.com/questions/634564/how-to-open-a-windows-named-pipe-from-java  

 
jjc:

I have almost no experience of Java, but, if the two computers are on the same local network, then named pipes - supported by MQL4 via FileOpen() - might be possible and simpler.

http://stackoverflow.com/questions/634564/how-to-open-a-windows-named-pipe-from-java  

 Actually, I have no experience with named pipes in Java, but the sockets are very common in Java. Moreover, the link you provided it looks like you cannot create the named pipe from Java, but only to connect to an existing one, and they considered only interprocess connection rather than networing solution (may or may not be compatible, no idea).

 
jjc:

I have almost no experience of Java, but, if the two computers are on the same local network, then named pipes - supported by MQL4 via FileOpen() - might be possible and simpler.

http://stackoverflow.com/questions/634564/how-to-open-a-windows-named-pipe-from-java  


Initially both computers will be on the same LAN, though it would be interesting to make it work also through Internet. But yes, on the same LAN would be enough right now.


Ovo:
The easiest (though not easy) way to connect MT4 from Java would be with sockets, there are sample codes for MQL in the code base and articles.


Yep. The best solution I've found there seems to be the one using mt4-zeromq, but still can't found a example showing how to use it to execute a trade. I think this may be the best way to do it since (¿)it wouldn't have any delay(?) and it could be used under a Linux environment, so any simple example code about it would be appreciated.

However the main problem I'm still seeing is the delay: When I developed something similar but on the opposite direction (MT4 was interacting with an external server) there was no such problem since there was no new information between MT4 market ticks, but in this case I can't figure out how MT4 will be able to receive orders (and execute them) between ticks. Wouldn't it be a problem? Or maybe I'm missing something and this won't be a problem?

 
Ovo:

 Actually, I have no experience with named pipes in Java, but the sockets are very common in Java. Moreover, the link you provided it looks like you cannot create the named pipe from Java, but only to connect to an existing one, and they considered only interprocess connection rather than networing solution (may or may not be compatible, no idea).

"Named Pipes" have to be created by the MT4 end first, by calling the WinAPI functions. Only then can it be used by JAVA as a standard file. That should not be a problem, because that is exactly what the OP wants but it is only ideal for a LAN solution.

Sockets, on the other hand is ideal for both LAN and WAN solutions, but will require a DLL wrapper for the WinAPI with extra support functions to make it easier for MT4 to handle things.

However, the OP just needs to "let his fingers do the walking" as there is plenty of information out there of possible solutions. He just has to choose which method suits him best, be it Named Pips, Mapped Files, Sockets, or whatever:
 
Mariop: However the main problem I'm still seeing is the delay: When I developed something similar but on the opposite direction (MT4 was interacting with an external server) there was no such problem since there was no new information between MT4 market ticks, but in this case I can't figure out how MT4 will be able to receive orders (and execute them) between ticks. Wouldn't it be a problem? Or maybe I'm missing something and this won't be a problem?

By using the OnTimer() event handler which is not dependent on incoming ticks!

Mariop: The best solution I've found there seems to be the one using mt4-zeromq, but still can't found a example showing how to use it to execute a trade.

Try not to depend on 3rd party libraries. Just code your own DLL with extra support functions in order to facilitate handling things for MT4. Code the DLL in C and not in C# as that has dependencies and is not as efficient as C.

Also devise your own message format/protocol appropriate to the requirements. Make it compact and efficient and later you should encrypt it for security if needed.

 
FMIC:

Try not to depend on 3rd party libraries. Just code your own DLL with extra support functions in order to facilitate handling things for MT4. Code the DLL in C and not in C# as that has dependencies and is not as efficient as C.

Also devise your own message format/protocol appropriate to the requirements. Make it compact and efficient and later you should encrypt it for security if needed.

Now we have a much more interesting answer than your first one. I absolutely agree with you and those are really GOOD ADVICES. I quitted MQL years ago since I developed my own platform (I REALLY needed some specific features I didn't found on any other platform, it wasn't because I was in the mood of spending that huge amount of hours doing it). Now I'm going to begin to collaborate with a broker that exclusively works with MT4, so I need to build a bridge to connect to it. That's why I'm in a hurry to make it work as soon as possible.


FMIC:

By using the OnTimer() event handler which is not dependent on incoming ticks!


True. Thanks. I didn't remember that. Actually it doesn't solve the problem completely since I need orders to be executed almost immediately (and I think with this method I can only check it every second, but at least not every tick), but indeed I can easily build a temporary solution using it.

Again, good advices ;)

Reason: