1

I am trying to established connection between MetaTrader 5 and Python using socket. Server part written in python and client part written in mql5. also client is Expert Advisor not a indicator. problem is when i run both server and client ,client gives me "error 4014". I'm very thankful if someone can help me to solve this problem.

enter image description here

 //this is python server code
 import socket

 serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 serv.bind(('127.0.0.1', 9090))
 serv.listen(1)

 while True:
     conn, addr = serv.accept()
     print('client connected to :', addr)
     conn.close()


//This is mql5 client code
//+------------------------------------------------------------------+
//|                                               test_client_EA.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

int socket;
int OnInit()
  {
   socket=SocketCreate();
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   SocketClose(socket);  
  }

void OnTick()
{
  socket=SocketCreate();
  if(socket!=INVALID_HANDLE) 
  {
     if(SocketConnect(socket,"127.0.0.1",9090,1000)) 
       {
        Print("Connected to "," 127.0.0.1",":",9090);
       }  
     else
       {
        Print("Connection ","127.0.0.1",":",9090," error ",GetLastError());
       }
  SocketClose(socket); 
  }
 else Print("Socket creation error ",GetLastError());
}

1 Answer 1

6

Have you tried configure WebRequest setting in option?

The path to the config is Tools -> Options -> Expert advisors -> WbRequest (checkbox). You want to add localhost, or 127.0.0.1 to allow connection.

I hope this is still pending and it helps.

Best

Sign up to request clarification or add additional context in comments.

4 Comments

Geraldkibz thank you for your response, i solved the problem months ago but actually this is the answer for my question.
Hi @sanuja, could you please mark that answer as accepted, if it solves your problem?
Hi, were you using Strategy tester? I cant make it work when using Strategy tester, gives me same error code, any ideas? thanks
Hi @mariomol, is it working without the strategy tester? Please check on your ports and localhost address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.