Socket commands to Metatrader ?

Discussion in 'Automated Trading' started by FutureScalper, Sep 3, 2010.

  1. Hi,

    A client of mine wants to know whether Metatrader can receive simple Buy, Sell (price,quantity) type ascii-text formatted commands over a local socket from an external submitter.

    If anyone knows this, it will save me a lot of scrounging time on the net.

    Signals from, say 6E Euro futures analysis from my platform, could be fed to MetaTrader to initiate automated Buy/Sell events on the Forex spot market. Some manual setup would be required on the Metatrader side, not a system running unattended.

    I realize this would be a somewhat loosely coupled interface, but it would take the reaction time element out of my client's pressing the button.

    I'm no Forex expert but learning.

    Thanks in advance,
  2. Yes, simply #import the appropriate winsock dll in your EA.

    See attached mqh header file:
  3. Thanks a lot! That will jump start things nicely.
  4. OK, I'm about to do this now. More info is found here:

    By the way, I need a bridge to Currenex so if you happen to have any info / tips on that area, please let me know!

    I need to stream Forex pricing into my client, and execute some fairly simple orders on the Forex (Currenex) side. Eventually it will be hammered so need something solid without having to drop into FIX style coding.

    So I'm interested in only a single Forex pair EUR/USD. Don't need anything else.

    Just wondering how to set things up. Should I do an Expert Advisor responsible for incoming Price Streaming from the EA to my client. And then a separate EA responsible for responding to Order Entry commands from my client? Would that be an appropriate architecture to get things done?

    I have Andrew R. Young's book Expert Advisor Programming and will be learning soon enough how the MetaTrader environment works.

    Thanks so much for the initial socket info.

  5. Kevin, thanks for pointing me to the socket code. I've been able to do amazing things in MetaTrader EA's by using it to send messages back into my custom Java trading client software.

    However, it seems there's a bug in the include text for the function retrieving a string. I'll just post it here for technical guys, apologies for loss of formatting.

    Very difficult to find socket code examples on the net, by the way.

    string struct2str(int struct[], int field) {
    string r="";
    int l=field>>16;
    if (l==0) return(r);
    int p=field>>2;
    int o=field%4;
    for (l=l; l>0; l--) {

    int x=struct[p]>>(o<<3);
    if (o==3) {
    } else
  6. gtor514


    If you need to stream MT4 pricing into your app you can do it directly using Dynamic Data Exchange (DDE) functionality.

    I have the code in c++ but not java. If java allows DDE the code should be similar.
  7. bidie


    -When streaming from the Metatrader DDE send is the output ascii data?
    -How would I import that into another program- these seem like dumb questions but any help would be appreciated-

  8. Can you post the C++ code for using DDE to access data in MT4? Thanks.