How can I allow an EA on one currency to communicate with the EA on another? - page 3

 
thrdel:


What you're trying to do looks like this :

Why are you trying to select the same order over and over again ?

This :

will get the same result over and over.

It will return the order at position zero in the history pool.

Don't you want to select the most recent closed one or something?

I thought you want a second EA to open a position as soon as the first one did. Are you aiming at something else now?


I thought order 0 was the most recent, no I wan't the other EAs to cease using a specific trading method if one of the symbols is in a bad situation, this is just a form of money management.
 
I have changed it from 0 to OrdersHistoryTotal()-1
 
don't do this for OrderClose() or for OrderDelete()
 
qjol:
don't do this for OrderClose() or for OrderDelete()

Yes it's just to stop opening orders.
 
MetaNt:

I've never tried or considered this method before, what are all these terms? I apologise for the my dearth of knowledge.


Hi MetaNt:

I am the developer of MetaComm library for MT4.

 - This library allows to interchange messages (strings) over TCP/IP:

   - between EAs/scripts/indicators in the same MT4 terminal. 

   - between EAs/scripts/indicators in different MT4 terminals in the same machine.

   - bettween EAs/scripts/indicators running in different machines across the internet.


- This library allows to implement: 

   - Arbitrage strategies between different brokers or accounts 

   - Hedging between different brokers or accounts

   - Communicate EAs with software written in other languages (c/c++, python, visual basic, etc).

 

This is an example of client implemented as Expert Advisor:


//-------------------------------------------


// include MetaComm library and helper functions

#include <MetaComm.mqh>


// global variable to store the client ID 

int client1


//-------------------------------------------

// Expert initialization function

//-------------------------------------------

int OnInit() {

   int result;


   Print("-- MetaComm client --");

   // create client, and connect to server localhost:5555

   // if this is the first client or server created, the library is 

   // atomatically init

   client1 = MC_client_create("localhost", 5555);

   // verify result

   if client1 == -1) {

      // init error

      Print("Init Error!!! " + MC_errdesc());

      return -1;

   }

   // client created OK

   Print("Client STARTED");

   return(INIT_SUCCEEDED);

  }

//-------------------------------------------

// Expert deinitialization function

//-------------------------------------------

void OnDeinit(const int reason)

{

   // destroy client (and deinit library if there is no more clients or 

   // servers running)

   int result = MC_client_destroy(client1);

   Print("Client TERMINATED");

}

//-------------------------------------------

// Expert tick function

//-------------------------------------------

void OnTick()

{

   // string to receive response

   string response;


   int result;

   // timeout for response

   int timeout = 1500;

   

   // create request string

   string request = Symbol() + ": " + "BID=" + DoubleToString(Bid, Digits) + 

                                      " ASK=" + DoubleToString(Ask, Digits);

   Print("Client sending: " + request);

   // send request to server, and receive response

   result = MC_client_request(client1, request, response, timeout );

   // verify if there is a response from server

   if (result == -1)

      Print("Error!!! " + MC_errdesc());

   else

      Print("Response received from server: " + response);

}

//-------------------------------------------


this EA, on init create a MetaComm Client, and in each tick will send to server a message with the current quote of symbol, like the following:

"EURUSD: BID=1.9834 ASK=1.9831"


And....., this is the code for server written as MQL4 Script:


//-------------------------------------------


// include MetaComm library and helper functions

#include <MetaComm.mqh>


// global variable to store the server ID 

int server1


//-------------------------------------------

// Script program start function

//-------------------------------------------

void OnStart()

{

   // string to receive request from clients

   string request;

   int result;

   Print("--- MetaComm server ---");

   // create server listening in server_port

   server1 = MC_server_create(server_port);

   // verify

   if (server1 == -1) 

   {

      // error creating server

      Print("Server create Error!!! " + MC_errdesc());

      return;

   }

   // server created OK. 

   Print("Server STARTED");

   // Wait messages (requests) from clients

   while(!IsStopped()) 

   {

      // verify if there is a request available

      if (MC_server_request_available(server1) == 1) 

      {

         // retrieve client request and store in request string

         result = MC_server_get_request(server1, request, 1500);   

         // verify

if (result == -1)

{

   // error 

   Print("Server get request error");

}

else

{

            Print("Request: " + request);

            // resend the same message to client as response

   MC_server_send_response(server1, request);

}

      }

   }


   // destroy server. If there is no more clients or servers running, 

   // the library is also deinit automatically

   MC_server_destroy(server1);

   Print("MetaComm server TERMINATED");

}

//-------------------------------------------


The server receives the request from clients, and send back the same message as response.

In the examples is demonstrated the ease of use of the library. 

 

I think this library can help you to implement Hegding.

I am not trying to make spam, I am just offering a solution in which I have worked and I see many traders and programmers need. 

I did attach a demo compiled you can test 

Regards 

Files:
Reason: