websocket MT4

 
Can anyone help unravel this problem. I am trying to communicate python with MT4. The problem is that even when I close/deactivate the python code, something is constantly coming in at the MT4 input. I don't know what it is. Are they some buffers or other things?

The code looks like below : 

<lib_websockets.mqh> I took it from https://github.com/mikha-dev/mt4-websockets/blob/master/MQL4/Include/lib_websockets.mqh

Maybe someone has something more reliable/proven to work. I would be happy to try it out. 

I tried a 'dedicated pipe', but it consumed huge amounts of resources, the computer stopped.


Thanks in advance for your help and best regards

Kris

long timerHandle;

double Indicator0;  // Indicator0
double Indicator1;  //  Indicator1
//...........
//...........
double Indicator26;  //  Indicator26

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetSpeed()
  {
   return NormalizeDouble(iCustom(NULL, PERIOD_CURRENT, "E....rev2", 0, 0), 3);
  }
//........................
//.......................
//.......................

double GetSpeedB()
  {
   return NormalizeDouble(iCustom(NULL, PERIOD_CURRENT, "E....rev2", 1, 0), 3);
  }


#include <lib_websockets.mqh>

input string   Host = "http://localhost:8088";
input int      HeatBeatPeriod = 45;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


int commandPingMilliseconds = 20;
WebSocketsProcessor *ws;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   int timerInterval =5500;


   timerHandle = EventSetMillisecondTimer(timerInterval);


   ws = new WebSocketsProcessor(Host, 30, 45);

   ws.SetHeader("account", AccountNumber());
   ws.Init();

   ws.Send("test" + GetTickCount());

   EventSetMillisecondTimer(commandPingMilliseconds);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
     
   double supertrendUP = iCustom(NULL, 0, "SqSuperTrend",1,12,ATRMultiplier,   2 , 0);
   ModifyBuyOrderWithSupertrend(supertrendUP);
   
// Python data
   string receivedData = ws.GetCommand();
   
     {

      int prediction1 = StringToInteger(receivedData);
      Print("received: ", prediction1);

      if(prediction1 == 0)
        {
         Print("Prediction 0 : ", prediction1," Do nothing");
        }
      else
         if(prediction1 == 1)
           {
            Print("Prediction : ", prediction1," - OPEN BUY");
           }
         else
           {
            Print("UNKNOWN: ", prediction1);
           }



      string currentSymbol = Symbol();
      int totalOrdersAUD = OrdersTotal();

      int ordersOnCurrentChart = 0;

      for(int i = 0; i < totalOrdersAUD; i++)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == currentSymbol)
              {
               ordersOnCurrentChart++;
              }
           }
        }


      if(prediction1 == 1 && ordersOnCurrentChart<1)
        {
         // Open BUY
         int ticket = OrderSend(Symbol(), OP_BUY,.....................);
         if(ticket > 0)
            Print("BUY is open");
        }
      else
        {
    
         // Comment("\n how many orders ", currentSymbol, ": ", ordersOnCurrentChart);

        }
     }
  }

//+------------------------------------------------------------------+
//| TIMER                                        |
//+------------------------------------------------------------------+
void OnTimer()
  {
            Indicator0 = NormalizeDouble(GetSpeedB()-GetSpeed(),5);
        //...............
        //...............
            Indicator26= NormalizeDouble(iCustom(NULL, 0, "SqSuperTrend", 0, 0),5);

   string data = DoubleToStr(Indicator0, 3) + "," +
                 DoubleToStr(Indicator1, 3) + "," +
        //.................
        //................
                 DoubleToStr(Indicator25, 5) + "," +
                 DoubleToStr(Indicator26, 5) ;


// send via websockets
   ws.SendCommand(data);
   Print("data sent:", data);
   Sleep(2500);

    // Closing connection
    wsProcessor.Close();

  }


mt4-websockets/MQL4/Include/lib_websockets.mqh at master · mikha-dev/mt4-websockets
mt4-websockets/MQL4/Include/lib_websockets.mqh at master · mikha-dev/mt4-websockets
  • mikha-dev
  • github.com
Turns Metatrader4/MetaTrader5 into web socket client - mikha-dev/mt4-websockets
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Reason: