Socket Backtest

 

Hi guys, 

I've trying to integrate MQL5 with Python and the way I found to do this was by socket communication. It all works fine when checking the EA on real time data. However, my code doesn't work when I try to do a backtest. It seems that it doesn't connect. Anyone can help?


//SOCKET ------------------------------------------------------------
int socket = SocketCreate(); 
int rsi;
double bufrsi[];
string recebido, open, high, low, close, tick, vol;
bool ativo = true;
int i;
bool enviado;
string endereco = "MY IP ADDRESS XXXXXX";
int qtd = 200;
uint porta = 7000;


bool socksend(int sock,string request) 
  {
   char req[];
   int  len=StringToCharArray(request,req)-1;
   if(len<0) return(false);
   return(SocketSend(sock,req,len)==len); 
  }

string socketreceive(int sock,int timeout)
  {
   char rsp[];
   string result="";
   uint len;
   uint timeout_check=GetTickCount()+timeout;
   do
     {
      len=SocketIsReadable(sock);
      if(len)
        {
         int rsp_len;
         rsp_len=SocketRead(sock,rsp,len,timeout);
         if(rsp_len>0) 
           {
            result+=CharArrayToString(rsp,0,rsp_len); 
           }
        }
     }
   while((GetTickCount()<timeout_check) && !IsStopped());
   return result;
  } 

//EXPORTACAO DE DADOS ------------------------------------------------


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
rsi=iRSI( 
         "WIN$N",             // símbolo nome 
         PERIOD_M10,          // período 
         9,     // período médio 
         PRICE_CLOSE          // tipo de preço ou manipulador
         );
// if(socket!=INVALID_HANDLE) {
//  if(SocketConnect(socket,"10.1.1.114",7000,1000)) {
//   Print("Connected to ","Gabriel",":",7000);}
//   
//  else Print("Connection ","localhost",":",7000," error ",GetLastError());
//  }
// else Print("Socket creation error ",GetLastError());

 printf("INICIO");

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
MqlRates valores[];
   CopyBuffer(rsi,0,1,qtd,bufrsi);
   CopyRates("WIN$N", PERIOD_M10, 1, qtd,valores);
   open = "";
   high = "";
   low = "";
   close = "";
   vol = "";
   tick = "";

   for (i = 0; i < qtd; i++)
      {
         open = open + IntegerToString(valores[i].open) + ";";
         high = high + IntegerToString(valores[i].high) + ";";
         low = low + IntegerToString(valores[i].low) + ";";
         close = close + IntegerToString(valores[i].close) + ";";
         tick = tick + IntegerToString(valores[i].tick_volume) + ";";
         vol = vol + IntegerToString(valores[i].real_volume) + ";"; 
      }
   //open = open + "//";
   //high = high + "//";
   //low = low + "//";
   //close = close + "//";
   //tick = tick + "//";
   //vol = vol + "//";
   
   if (ativo == true) 
      {
         SocketConnect(socket,endereco,porta,1000);
         enviado = socksend(socket, open);
         SocketConnect(socket,endereco,porta,1000);
         enviado = socksend(socket, high);
         SocketConnect(socket,endereco,porta,1000);
         enviado = socksend(socket, low); 
         SocketConnect(socket,endereco,porta,1000);
         enviado = socksend(socket, close);
         SocketConnect(socket,endereco,porta,1000);
         enviado = socksend(socket, tick); 
         SocketConnect(socket,endereco,porta,1000);
         enviado = socksend(socket, vol); 
         SocketConnect(socket,endereco,porta,1000);
         recebido = socketreceive(socket, 1000);
         printf (recebido);
         SocketClose(socket);
         ativo = false;
      }
  }
 
Socket functions can not be used from the Strategy Tester.
 
Alain Verleyen #:
Socket functions can not be used from the Strategy Tester.

Hi!

Do you know why it doesn't support socket programming in Strategy Tester? cause this functionality is part of my thesis:/

Could you recommend another way to connect the external python program with the mt 5 and its strategy tester?

 
You will need to use windows sockets and related DLLs.

No other way known.
Reason: