-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mq5
62 lines (45 loc) · 1.64 KB
/
test.mq5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#property copyright "Carlos Espitia"
#property version "1.00"
#property description "description here"
#include "MQ_API/SocketHandling.mqh"
#include "MQ_API/Graphics.mqh"
// make sure to enable and add ip address to mt5
// The path to the config is Tools -> Options -> Expert advisors -> WbRequest (checkbox)
input string Address= "127.0.0.1";
input int Port = 50000;
string textSeperator = "~";
void OnStart() {
int socket = SocketCreate();
if(socket == INVALID_HANDLE) {
Print("Failed to create a socket, error ",GetLastError());
return;
}
if(!SocketConnect(socket,Address,Port,1000)) {
Print("Connection to ",Address,":",Port," failed, error ",GetLastError());
return;
}
// class initializations
SocketHandling sockethandler(socket);
GraphicalObjectHandler graphics();
bool connected = true;
char rsp[];
// listening for commands from python
while(sockethandler.isConnected()) {
Sleep(300); // Wait a second before the next check | 300 ms best results
string recieved = sockethandler.recv();
if(StringLen(recieved) <= 0) continue; // empty string was received
// Print(recieved);
string results[];// An array to get strings
// had to use StringGetCharacter cuz of weird ushort
int numStrings=StringSplit(recieved,StringGetCharacter(textSeperator,0),results);
if(numStrings>0) {
for(int i=0;i<numStrings;i++) {
Print("[", i, "] ", results[i]);
// ChartOpen("UERUSD", )
if(graphics.isGraphicalCommand(results[i])) graphics.executeCommand(results[i]);
}
}
}
Print("Socket closed | ", GetLastError());
SocketClose(socket);
}