Skip to content

Commit 17cdc3d

Browse files
Update ForecastExpert.mq5
1 parent e4aafc8 commit 17cdc3d

File tree

1 file changed

+72
-27
lines changed

1 file changed

+72
-27
lines changed

ForecastExpert.mq5

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//+------------------------------------------------------------------+
2-
//| ForecastExpert.mq5 |
2+
//| _HPCS_RNNPredict_MT5_EA_V01_WE.mq5 |
33
//| HPCS |
44
//| https://www.mql5.com |
55
//+------------------------------------------------------------------+
@@ -149,35 +149,78 @@ int OnInit()
149149
//---
150150

151151
previousPred = "";
152+
if(train == true){
153+
ObjectCreate(ChartID(),"Trainbutton",OBJ_BUTTON,0,0,0);
154+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_XSIZE,140);
155+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_YSIZE,30);
156+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_XDISTANCE,40);
157+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_YDISTANCE,10);
158+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_COLOR,clrBlue);
159+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_BGCOLOR,clrWhite);
160+
ObjectSetString(ChartID(),"Trainbutton",OBJPROP_TEXT,"TRAIN MODEL");
161+
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_STATE,false);
152162

153-
ObjectCreate(ChartID(),"Trainbutton",OBJ_BUTTON,0,0,0);
154-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_XSIZE,140);
155-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_YSIZE,30);
156-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_XDISTANCE,40);
157-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_YDISTANCE,10);
158-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_COLOR,clrBlue);
159-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_BGCOLOR,clrWhite);
160-
ObjectSetString(ChartID(),"Trainbutton",OBJPROP_TEXT,"TRAIN MODEL");
161-
ObjectSetInteger(ChartID(),"Trainbutton",OBJPROP_STATE,false);
162-
163-
ObjectCreate(ChartID(),"Predbutton",OBJ_BUTTON,0,0,0);
164-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_XSIZE,140);
165-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_YSIZE,30);
166-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_XDISTANCE,40);
167-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_YDISTANCE,50);
168-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_COLOR,clrBlue);
169-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_BGCOLOR,clrWhite);
170-
ObjectSetString(ChartID(),"Predbutton",OBJPROP_TEXT,"PREDICT");
171-
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_STATE,false);
172-
173-
if(!EventChartCustom(ChartID(),0,0,0,"Trainbutton")){
174-
Print("Error : ",GetLastError());
175-
}
176-
177-
if(!EventChartCustom(ChartID(),0,0,0,"Predbutton")){
178-
Print("Error : ",GetLastError());
163+
ObjectCreate(ChartID(),"Predbutton",OBJ_BUTTON,0,0,0);
164+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_XSIZE,140);
165+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_YSIZE,30);
166+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_XDISTANCE,40);
167+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_YDISTANCE,50);
168+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_COLOR,clrBlue);
169+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_BGCOLOR,clrWhite);
170+
ObjectSetString(ChartID(),"Predbutton",OBJPROP_TEXT,"PREDICT");
171+
ObjectSetInteger(ChartID(),"Predbutton",OBJPROP_STATE,false);
172+
173+
if(!EventChartCustom(ChartID(),0,0,0,"Trainbutton")){
174+
Print("Error : ",GetLastError());
175+
}
176+
177+
if(!EventChartCustom(ChartID(),0,0,0,"Predbutton")){
178+
Print("Error : ",GetLastError());
179+
}
179180
}
181+
else{
180182

183+
socket = SocketCreate();
184+
if(socket!=INVALID_HANDLE) {
185+
if(SocketConnect(socket,"localhost",9090,1000)) {
186+
Print("Connected to "," localhost",":",9090);
187+
188+
CJAVal json;
189+
json["FileName"] = fileName;
190+
json["Train"] = train;
191+
json["GPU"] = gpu;
192+
json["Bars"] = bars;
193+
194+
string jsonString = json.Serialize();
195+
196+
bool send = socksend(socket, jsonString);
197+
if(send)
198+
Print("Data Sent Successfully For Prediction.");
199+
200+
string strMessage;
201+
do{
202+
strMessage = socketreceive(socket,10);
203+
if (strMessage != "") {
204+
previousPred = strMessage;
205+
Print(strMessage);
206+
drawpred(strMessage);
207+
SocketClose(socket);
208+
socket = -2;
209+
}
210+
}while(strMessage == "");
211+
212+
}
213+
else{
214+
socket = -2;
215+
Print("Error in connecting to ","localhost",":",9090," Error : ",GetLastError());
216+
}
217+
}
218+
else{
219+
socket = -2;
220+
Print("Socket creation error ",GetLastError());
221+
}
222+
223+
}
181224

182225
//---
183226
return(INIT_SUCCEEDED);
@@ -224,6 +267,7 @@ void OnTick()
224267
}
225268

226269
json["FileName"] = fileName;
270+
json["Train"] = train;
227271
json["GPU"] = gpu;
228272
json["Architecture"] = (int)architecture;
229273
json["Optimizer"] = (int)optimizer;
@@ -297,6 +341,7 @@ void OnChartEvent(const int id, const long &lparam, const double &dparam, const
297341
}
298342

299343
json["FileName"] = fileName;
344+
json["Train"] = train;
300345
json["GPU"] = gpu;
301346
json["Architecture"] = (int)architecture;
302347
json["Optimizer"] = (int)optimizer;

0 commit comments

Comments
 (0)