Quellcode durchsuchen

Ticket : 4073 Add news filter

News Filter Added
Completed
faiz ali vor 11 Monaten
Ursprung
Commit
ee3808d893

BIN
NewsFilter/line_level_news_filter.ex5


+ 958 - 0
NewsFilter/line_level_news_filter.mq5

@@ -0,0 +1,958 @@
1
+//+------------------------------------------------------------------+
2
+//|                                       line_level_news_filter.mq5 |
3
+//|                                  Copyright 2025, MQL Development |
4
+//|                                  https://www.mqldevelopment.com/ |
5
+//+------------------------------------------------------------------+
6
+#property library
7
+#property copyright "Copyright 2025, MQL Development"
8
+#property link      "https://www.mqldevelopment.com/"
9
+#property version   "1.00"
10
+#include <Trade\Trade.mqh>
11
+CTrade trade;
12
+
13
+//+------------------------------------------------------------------+
14
+//| My function                                                      |
15
+//+------------------------------------------------------------------+
16
+// int MyCalculator(int value,int value2) export
17
+//   {
18
+//    return(value+value2);
19
+//   }
20
+//+------------------------------------------------------------------+
21
+
22
+
23
+#import  "Wininet.dll"
24
+int InternetOpenW(string,int,string,string,int);
25
+int InternetConnectW(int,string,int,string,string,int,int,int);
26
+int HttpRequestW(int,string,string,int,string,int,string,int);
27
+int InternetOpenUrlW(int,string,string,int,int,int);
28
+int InternetReadFile(int,uchar &sBuffer[],int,int &OneInt);
29
+int InternetCloseHandle(int);
30
+bool DeleteUrlCacheEntryW(string);
31
+#import
32
+
33
+#import "kernel32.dll"
34
+int GetLastError(void);
35
+#import
36
+
37
+
38
+datetime previous_time;
39
+datetime expiry=D'2026.10.16 12:30:27';
40
+string matchExpert="line_level_ea";
41
+string matchExpert2="Line_Level_Ea";
42
+string fileName="test1"+MQLInfoString(MQL_PROGRAM_NAME)+Symbol()+IntegerToString(Period())+".xml";
43
+//+------------------------------------------------------------------+
44
+//|                                                                  |
45
+//+------------------------------------------------------------------+
46
+enum selectLine
47
+  {
48
+   LineOnNewsBar =0,
49
+   LineOnNewsStop=1
50
+  };
51
+//+------------------------------------------------------------------+
52
+//|                                                                  |
53
+//+------------------------------------------------------------------+
54
+struct newsEvent
55
+  {
56
+   string            title;
57
+   string            country;
58
+   string            date;
59
+   string            time;
60
+   string            impact;
61
+                     newsEvent()
62
+     {
63
+      title="";
64
+      country="";
65
+      date="";
66
+      time="";
67
+      impact="";
68
+     }
69
+  };
70
+
71
+const int newsSize=300;
72
+newsEvent ns[300];
73
+datetime lastNews;
74
+//+------------------------------------------------------------------+
75
+//|                                                                  |
76
+//+------------------------------------------------------------------+
77
+void initiateNews() export
78
+  {
79
+   lastNews=TimeCurrent();
80
+   updateNews();  //change here
81
+   fillNewsStruct();
82
+   Print("The Symbol is:",Symbol()," and timeperiod:",Period()," and file name is:"+fileName);
83
+  }
84
+//+------------------------------------------------------------------+
85
+//|                                                                  |
86
+//+------------------------------------------------------------------+
87
+//int OnInit()
88
+//  {
89
+////---
90
+//   bool check = MQLInfoInteger(MQL_DLLS_ALLOWED);
91
+//   Print("DLL: ",check);
92
+//   Alert("Enable");
93
+//   return(INIT_SUCCEEDED);
94
+//  }
95
+//+------------------------------------------------------------------+
96
+//|                                                                  |
97
+//+------------------------------------------------------------------+
98
+int returnNewsStatus(bool highFlag=true
99
+                                   ,int high_impact_value=60//Stop Trade before high News (min)
100
+                     ,int end_impact_value=15 //Stop Trade after high News (min)
101
+
102
+                     ,bool show_high_line=true//Show verticle Line when high news comes
103
+                     ,bool mediumFlag=true
104
+                     ,int medium_impact_high=60//Stop Trade before medium News (min)
105
+                     ,int medium_impact_low=15 //Stop Trade after medium News (min)
106
+
107
+                     ,bool show_medium_line=true//Show verticle Line when medium news comes
108
+                     ,bool lowFlag=true
109
+                     ,int low_impact_high=60//Stop Trade before low News (min)
110
+                     ,int low_impact_low=15 //Stop Trade after low News (min)
111
+
112
+                     ,bool show_low_line=true//Show verticle Line when low news comes
113
+                     ,string symbol=""
114
+                     ,string expertname=""
115
+                     ,int gmt=2
116
+                     ,selectLine sl=0
117
+                     ,string extraSymbol=""
118
+                    ) export
119
+//+------------------------------------------------------------------+
120
+//|                                                                  |
121
+//+------------------------------------------------------------------+
122
+  {
123
+   int newsStatus=0;
124
+//Print("TImeCurrent:"+TimeCurrent()+"expiry:"+expiry);
125
+//"Trend Gridder(22)" || expertname=="TG NEWS" || expertname=="TG News"
126
+//"tylergabor"
127
+//((  expertname=="TG NEWS" || expertname=="TG News" || expertname=="Bandit" || expertname=="BANDIT" || expertname=="bandit" || expertname=="TG NEWS" || expertname=="TG News" || expertname=="C-Storm" || expertname=="C-STORM" || expertname=="c-storm" || (expertname=="C-StormV1.1" || (StringFind(chkexpert,"tyler")!=-1) || (StringFind(chkexpert,"hullincash")!=-1) ||(StringFind(chkexpert,"pk5000")!=-1) )))// && TimeCurrent()<expiry)
128
+
129
+   string chkexpert=expertname;
130
+// Print("chkexpert ",chkexpert);
131
+//   StringToLower(chkexpe/rt);
132
+
133
+   if(Validate())
134
+     {
135
+      if(TimeDayMQL4(TimeCurrent())!=TimeDayMQL4(lastNews))
136
+        {
137
+         updateNews();  // change here
138
+         fillNewsStruct();
139
+         lastNews=TimeCurrent();
140
+         Print("News Function is calling and updating by "+symbol);
141
+        }
142
+      int index=0;
143
+      string sym=symbol;
144
+      string metals=sym;
145
+      StringToLower(metals);
146
+      StringToLower(extraSymbol);
147
+      //Print("---------------------Metals:"+metals+ " and symbol:"+ns[index].country," and extraSymbol:",extraSymbol);
148
+      //Print("checking metal:"+(StringFind("Nymex-J",sym,0)!=-1) +" and metal is:"+sym );
149
+      //Print("country:"+ns[index].country+" and check "+StringFind("JPYAUD",ns[index].country,0)!=-1))
150
+      //Start working here
151
+      while(index<newsSize)
152
+        {
153
+         // Print("Inside the currency:"+index+ " currency"+ns[index].country+ " and curent demanding symbol:"+metals + "nstime:"+ns[index].time);
154
+
155
+         if((StringFind(sym,ns[index].country,0)!=-1) || ((metals=="wticrude." || metals=="usoil" || metals=="crude"  || metals=="crude" || metals=="usousd" || metals=="wticousd"  || (StringFind(metals,"nymex",0)!=-1) || (StringFind(metals,"WTICrude",0)!=-1) || (StringFind(metals,extraSymbol,0)!=-1)) &&((StringFind("USD",ns[index].country,0)!=-1) || (StringFind("CAD",ns[index].country,0)!=-1))))
156
+           {
157
+            //  Print("Inside the currency:"+index+ " currency"+ns[index].country+ " and curent demanding symbol:"+metals + "nstime:"+ns[index].time);
158
+
159
+            //     int low_time;
160
+            //    int high_time;
161
+            datetime ulow_time,uhigh_time;
162
+
163
+            //    int time_in_seconds;
164
+            datetime utime_in_seconds;
165
+            //this is the current broker time
166
+            //     time_in_seconds=(TimeHour(iTime(symbol,0,0))*60*60)+(TimeMinute(iTime(symbol,0,0))*60);
167
+            //  Print("nsDate:"+ns[index].date);
168
+            utime_in_seconds=TimeCurrent();
169
+
170
+            string chngdt=changeDateFormate(ns[index].date);
171
+            //     string Date1=TimeToStr(TimeCurrent(),TIME_DATE);
172
+
173
+            datetime updatedDateTime=StringToTime(chngdt+" 00:00:00");
174
+            updatedDateTime+=NsTimeInSeconds(ns[index].time);
175
+
176
+            //   Print("updateTime1+nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
177
+
178
+            //  string updatedTime=TimeToStr(updatedDateTime,TIME_MINUTES);
179
+            updatedDateTime+=((gmt)*3600);
180
+
181
+            //  Print("updateTime 2 +nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
182
+            //     string Today1=TimeToStr(updatedDateTime,TIME_DATE);
183
+
184
+            //   string times=Time24Conversion(ns[index].time);
185
+            datetime temp2;
186
+            temp2=updatedDateTime;
187
+            // Print("chngDate:"+chngdt);
188
+            //  Print("Time in Seconds:"+time_in_seconds);
189
+            //  Print("temp2:"+temp2);
190
+            // Print("------------Index:"+index+" updated Date Time:"+updatedDateTime);
191
+
192
+            if(ns[index].impact=="High" && highFlag)
193
+              {
194
+
195
+               //  low_time=NsTimeInSeconds(ns[index].time)-(high_impact_value*60);
196
+               //high_time=NsTimeInSeconds(ns[index].time)+(end_impact_value*60);
197
+               ulow_time=updatedDateTime-(high_impact_value*60);
198
+               uhigh_time=updatedDateTime+(end_impact_value*60);
199
+               //    Print("High least:"+low_time+" high highest:"+high_time);
200
+               //     Print("Date1:"+Date1+" today1:"+Today1);
201
+               //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
202
+               //  Print("------------Index:"+index+" updated Date Time:"+updatedDateTime);
203
+
204
+               //  Print("----------HighNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
205
+               if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
206
+                 {
207
+
208
+                  //flag=true;
209
+                  newsStatus=1;
210
+                  if(temp2!=previous_time)
211
+                    {
212
+                     if(show_high_line==true)
213
+                       {
214
+                        Print("Inside high alert");
215
+                        datetime lineTime=TimeCurrent();
216
+                        if(sl==0)
217
+                           lineTime=updatedDateTime;
218
+
219
+                        ObjectCreate(0,"VLine"+TimeToString(lineTime),OBJ_VLINE,0,lineTime,0);
220
+                        ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_STYLE,STYLE_DOT);
221
+                        ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_COLOR,clrRed);
222
+                        ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_WIDTH,1);
223
+                       }
224
+                     previous_time=temp2;
225
+                    }
226
+
227
+                  break;
228
+                 }
229
+              }
230
+
231
+            //medium impact
232
+            else
233
+               if(ns[index].impact=="Medium" && mediumFlag)
234
+                 {
235
+                  // low_time=NsTimeInSeconds(ns[index].time)-(medium_impact_high*60);
236
+                  // high_time=NsTimeInSeconds(ns[index].time)+(medium_impact_high*60);
237
+                  ulow_time=updatedDateTime-(medium_impact_high*60);
238
+                  uhigh_time=updatedDateTime+(medium_impact_low*60);
239
+
240
+                  // Print("medium least:"+low_time+" medium highest:"+high_time);
241
+                  //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
242
+
243
+                  //  Print("----------MediumNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
244
+
245
+                  if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
246
+
247
+                    {
248
+                     //StopTrading(); //Close Current Orders Buy/Sell
249
+                     // flag=true;
250
+                     //     Print("Inside high alert");
251
+                     newsStatus=2;
252
+                     if(temp2!=previous_time)
253
+                       {
254
+                        if(show_medium_line==true)
255
+                          {
256
+                           datetime lineTime=TimeCurrent();
257
+                           if(sl==0)
258
+                              lineTime=updatedDateTime;
259
+
260
+                           ObjectCreate(0,"VLine"+TimeToString(lineTime),OBJ_VLINE,0,lineTime,0);
261
+                           ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_STYLE,STYLE_DOT);
262
+
263
+                           ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_COLOR,clrGreen);
264
+                           ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_WIDTH,1);
265
+
266
+                          }
267
+                        previous_time=temp2;
268
+                       }
269
+                     break;
270
+                    }
271
+                 }
272
+               else
273
+                  if(ns[index].impact=="Low" && lowFlag)
274
+                    {
275
+                     ///    low_time=NsTimeInSeconds(ns[index].time)-(low_impact_high*60);
276
+                     //   high_time=NsTimeInSeconds(ns[index].time)+(low_impact_high*60);
277
+                     //Print("low least:"+low_time+" low highest:"+high_time);
278
+                     //   Print("In low impact and currency is:"+ns[index].country);
279
+                     ulow_time=updatedDateTime-(low_impact_high*60);
280
+                     uhigh_time=(updatedDateTime)+(low_impact_low*60);
281
+
282
+                     // if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
283
+
284
+                     //    Print("-------Low news Now dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);//+" low time in min:"+low_impact_low);
285
+
286
+                     if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
287
+
288
+                       {
289
+                        //StopTrading(); //Close Current Orders Buy/Sell
290
+                        // flag=true;
291
+                        //    Print("Inside high alert");
292
+                        //  Print("updateDateTime:"+updatedDateTime);
293
+                        newsStatus=3;
294
+                        // Print("Temp2"+temp2);
295
+                        if(temp2!=previous_time)
296
+                          {
297
+                           if(show_low_line==true)
298
+                             {
299
+                              datetime lineTime=TimeCurrent();
300
+                              if(sl==0)
301
+                                 lineTime=updatedDateTime;
302
+
303
+                              //  Print("s1:"+sl+ " lineTime:"+lineTime );
304
+                              //  Print("nsDate:"+ns[index].date+" nstime:"+ns[index].time+ "Sym:"+ns[index].country );
305
+                              ObjectCreate(0,"VLine"+TimeToString(lineTime),OBJ_VLINE,0,lineTime,0);
306
+                              ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_STYLE,STYLE_DOT);
307
+
308
+                              ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_COLOR,clrBlue);
309
+                              ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_WIDTH,1);
310
+
311
+                             }
312
+                           previous_time=temp2;
313
+                          }
314
+                        break;
315
+                       }
316
+                    }
317
+            //
318
+           }//Close Country Symbol if
319
+         index++;
320
+        }
321
+
322
+     }
323
+   else
324
+     {
325
+      //  Print("exprtName:"+chkexpert+"stringfind:"+IntegerToString((StringFind(chkexpert,"FX Ekspert Ghost Trader"))));
326
+      Print("Validation Error");
327
+     }
328
+   return newsStatus;
329
+  }
330
+//+------------------------------------------------------------------+
331
+//|                                                                  |
332
+//+------------------------------------------------------------------+
333
+string AlphaNumeric(string istr)
334
+  {
335
+   string other="Aa";
336
+   string ostr = "";
337
+   for(int i=0; i<StringLen(istr); i++)
338
+     {
339
+      string s=StringSubstr(istr,i,1);
340
+      if((s>="A" && s<="Z" && StringFind(other,"A")>=0)
341
+         || (s >= "a" && s <= "z" && StringFind(other,"a") >= 0)
342
+         || (s >= "0" && s <= "9" && StringFind(other,"1") >= 0)
343
+         || (s==":")
344
+         || (s=="-")
345
+         || (s=="0")
346
+         || (s=="1")
347
+         || (s=="2")
348
+         || (s=="3")
349
+         || (s=="4")
350
+         || (s=="5")
351
+         || (s=="6")
352
+         || (s=="7")
353
+         || (s=="8")
354
+         || (s=="9")
355
+         || StringFind(other,s)>=0)
356
+         ostr=ostr+s;
357
+     }
358
+   return(ostr);
359
+  }
360
+//+------------------------------------------------------------------+
361
+//| ChartEvent function                                              |
362
+//+------------------------------------------------------------------+
363
+
364
+//+------------------------------------------------------------------+
365
+void fillNewsStruct()
366
+  {
367
+   int file_handle=FileOpen(fileName,FILE_READ|FILE_ANSI);
368
+
369
+   if(file_handle!=INVALID_HANDLE)
370
+     {
371
+      PrintFormat("%s file is available for reading",fileName);
372
+      //PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
373
+      //--- additional variables
374
+      int    str_size;
375
+      string str ;
376
+      //--- read data from the file
377
+      int n=0;
378
+      Print("n:",n);
379
+      while(!FileIsEnding(file_handle))
380
+        {
381
+
382
+         // Print("n:",n);
383
+         //--- find out how many symbols are used for writing the time
384
+
385
+         str_size=FileReadInteger(file_handle,INT_VALUE);
386
+         Print("size:",str_size);
387
+
388
+         //--- read the string
389
+         str=FileReadString(file_handle,str_size);
390
+         Print("Printing what is inside the n :",str);
391
+
392
+         if(StringFind(str,"<title>",0)!=-1)
393
+           {
394
+            StringReplace(str,"<title>","");
395
+            StringReplace(str,"</title>","");
396
+            str=AlphaNumeric(str);
397
+            ns[n].title=str;
398
+            //Print("title ",ns[n].title);
399
+           }
400
+         else
401
+            if(StringFind(str,"<country>",0)!=-1)
402
+              {
403
+               StringReplace(str,"<country>","");
404
+               StringReplace(str,"</country>","");
405
+               str=AlphaNumeric(str);
406
+               ns[n].country=str;
407
+               //Print("country ",ns[n].country);
408
+
409
+              }
410
+            else
411
+               if(StringFind(str,"<date>",0)!=-1)
412
+                 {
413
+                  StringReplace(str,"<date>","");
414
+                  StringReplace(str,"</date>","");
415
+                  StringReplace(str,"CDATA","");
416
+                  str=AlphaNumeric(str);
417
+                  ns[n].date=str;
418
+                  // Print("date ",ns[n].date);
419
+                 }
420
+               else
421
+                  if(StringFind(str,"<time>",0)!=-1)
422
+                    {
423
+                     StringReplace(str,"<time>","");
424
+                     StringReplace(str,"</time>","");
425
+                     StringReplace(str,"CDATA","");
426
+                     str=AlphaNumeric(str);
427
+                     ns[n].time=str;
428
+                     //  Print("time ",ns[n].time);
429
+                    }
430
+                  else
431
+                     if(StringFind(str,"<impact>",0)!=-1)
432
+                       {
433
+                        StringReplace(str,"<impact>","");
434
+                        StringReplace(str,"</impact>","");
435
+                        StringReplace(str,"CDATA","");
436
+                        str=AlphaNumeric(str);
437
+                        ns[n].impact=str;
438
+                        //   Print("impact ",ns[n].impact);
439
+
440
+                        n++;
441
+                       }
442
+         //--- print the string
443
+         //   PrintFormat(str);
444
+
445
+        }
446
+      //--- close the file
447
+      FileClose(file_handle);
448
+      PrintFormat("Data is read, %s file is closed",fileName);
449
+     }
450
+   else
451
+      PrintFormat("Failed to open %s file, Error code = %d",fileName,GetLastError());
452
+  }
453
+//+------------------------------------------------------------------+
454
+//|                                                                  |
455
+//+------------------------------------------------------------------+
456
+void updateNews()
457
+  {
458
+   string cookie=NULL,strNews;
459
+   string reqheaders="User-Agent: Mozilla/4.0\r\n";
460
+   char post[],result[];
461
+   int res;
462
+//http://www.forexfactory.com/ffcal_week_this.xml
463
+   string url="https://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml";
464
+   url="https://nfs.faireconomy.media/ff_calendar_thisweek.xml";
465
+   ResetLastError();
466
+   int timeout=5000;
467
+//res=WebRequest("GET",url,reqheaders,timeout,post,result,headers);
468
+   res=InternetGetFile(url,strNews);
469
+
470
+   StringToCharArray(strNews,result);
471
+   if(res==-1)
472
+     {
473
+      Print("Error in WebRequest. Error code  =",GetLastError());
474
+      //--- Perhaps the URL is not listed, display a message about the necessity to add the address
475
+      MessageBox("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
476
+     }
477
+   else
478
+     {
479
+      //--- Load successfully
480
+      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
481
+      //--- Save the data to a file
482
+      int filehandle=FileOpen(fileName,FILE_WRITE|FILE_BIN);
483
+      //--- Checking errors
484
+      if(filehandle!=INVALID_HANDLE)
485
+        {
486
+         //--- Save the contents of the result[] array to a file
487
+         FileWriteArray(filehandle,result,0,ArraySize(result));
488
+         //--- Close the file
489
+         FileClose(filehandle);
490
+        }
491
+      else
492
+         Print("Error in FileOpen. Error code=",GetLastError());
493
+     }
494
+
495
+  }
496
+//+------------------------------------------------------------------+
497
+//|                                                                  |
498
+//+------------------------------------------------------------------+
499
+//+------------------------------------------------------------------+
500
+//|                                                                  |
501
+//+------------------------------------------------------------------+
502
+int NsTimeInSeconds(string str)
503
+  {
504
+   int temp=0;
505
+   datetime temp0=StringToTime(str);
506
+   int _hour=TimeHourMQL4(temp0);
507
+   int _minute=TimeMinuteMQL4(temp0);
508
+   if(str[StringLen(str)-2]=='p' && _hour!=12)
509
+     {
510
+
511
+      _hour=_hour+12;
512
+
513
+     }
514
+   if((str[StringLen(str)-2]=='a') && _hour==12)
515
+      _hour=0;
516
+   temp=temp+(_hour*3600);
517
+   temp=temp+(_minute*60);
518
+   return temp;
519
+  }
520
+//+------------------------------------------------------------------+
521
+//|                                                                  |
522
+//+------------------------------------------------------------------+
523
+
524
+
525
+//+------------------------------------------------------------------+
526
+//|                                                                  |
527
+//+------------------------------------------------------------------+
528
+string Time24Conversion(string time)
529
+  {
530
+   string hour,t_mode,min;
531
+   int count=0;
532
+   bool fl=false;
533
+   for(int i=0; i<StringLen(time); i++)
534
+     {
535
+      if(count==0 && (StringSubstr(time,i,1)!=":"))
536
+         hour=hour+StringSubstr(time,i,1);
537
+      else
538
+         if(StringSubstr(time,i,1)==":")
539
+           {
540
+            count++;
541
+            i++;
542
+           }
543
+      if(count==1 && (StringSubstr(time,i,1)!="a" && StringSubstr(time,i,1)!="p" && StringSubstr(time,i,1)!="m"))
544
+         min=min+StringSubstr(time,i,1);
545
+      if(StringSubstr(time,i,1)=="a")
546
+         t_mode="a";
547
+      else
548
+         if(StringSubstr(time,i,1)=="p")
549
+            t_mode="p";
550
+     }
551
+   long h=StringToInteger(hour);
552
+   if(t_mode=="p")
553
+      h=h+12;
554
+   string final_time=IntegerToString(h)+":"+min;
555
+   return final_time;
556
+  }
557
+//+------------------------------------------------------------------+
558
+//|                                                                  |
559
+//+------------------------------------------------------------------+
560
+string changeDateFormate(string date)
561
+  {
562
+
563
+   string str[],result="";
564
+   StringSplit(date,'-',str);
565
+// Print("Str0:"+str[0]+" str1:"+str[1]+" str2:"+str[2]);
566
+   result=str[2]+"."+str[0]+"."+str[1];
567
+// Print("result:"+result);
568
+   return result;
569
+
570
+  }
571
+//+------------------------------------------------------------------+
572
+
573
+//+------------------------------------------------------------------+
574
+//|                                                                  |
575
+//+------------------------------------------------------------------+
576
+datetime NsDate(string str)
577
+  {
578
+   string month=StringSubstr(str,0,2);
579
+   string day=StringSubstr(str,3,2);
580
+   string year = StringSubstr(str,6,4);
581
+   string date = year+"."+month+"."+day;
582
+   datetime date_time=StringToTime(date);
583
+   return date_time;
584
+  }
585
+//+------------------------------------------------------------------+
586
+//|                                                                  |
587
+//+------------------------------------------------------------------+
588
+datetime NsDateTime(string date,string time)
589
+  {
590
+   datetime t1 = NsDate(date);
591
+   datetime t2 = NsTimeInSeconds(time);
592
+   datetime t3 = t1+t2;
593
+   return t3;
594
+  }
595
+//+------------------------------------------------------------------+
596
+
597
+//+------------------------------------------------------------------+
598
+//|                                                                  |
599
+//+------------------------------------------------------------------+
600
+bool Validate() export
601
+  {
602
+//      if(MQLInfoString(MQL_PROGRAM_NAME)=="AProxAlert")
603
+
604
+   string chkexpert=MQLInfoString(MQL_PROGRAM_NAME);
605
+//Print("Calling Expert: ",chkexpert);
606
+   StringToLower(chkexpert);
607
+   if((StringFind(chkexpert,matchExpert)!=-1) || chkexpert=="news" || (StringFind(chkexpert,matchExpert2)!=-1))
608
+     {
609
+      // Print("Calling Expert: ",chkexpert);
610
+      //string  content;
611
+      // string request="http://www.verifymysystem.com/";
612
+      // InternetGetFile(request,content);
613
+      return true;
614
+     }
615
+   return false;
616
+  }
617
+//+------------------------------------------------------------------+
618
+//+------------------------------------------------------------------+
619
+//+ Main function which returns Windows error code                   +
620
+//+------------------------------------------------------------------+
621
+int InternetGetFile(string url,string &content)
622
+  {
623
+//--- Init
624
+   content=NULL;
625
+
626
+//--- Create connection
627
+   int httpconnect=0;
628
+   int httprequest=0;
629
+   int httpopen=Wininet::InternetOpenW("InternetGetFileMQL",0," "," ",0);
630
+   int e=kernel32::GetLastError();
631
+   if(e==0)
632
+     {
633
+      bool flag=Wininet::DeleteUrlCacheEntryW(url);
634
+      httprequest=Wininet::InternetOpenUrlW(httpopen,url,NULL,0,16|10,0);
635
+      e=kernel32::GetLastError();
636
+      if(e==0)
637
+        {
638
+         //--- Define buffers
639
+         uchar ch[512];
640
+         string temp="";
641
+
642
+         //--- Retrieve data from file
643
+         int cnt=0;
644
+         while(Wininet::InternetReadFile(httprequest,ch,512,cnt))
645
+           {
646
+            //e=kernel32::GetLastError();
647
+            if(cnt<=0)
648
+               break;
649
+            temp=temp+CharArrayToString(ch,0,cnt);
650
+           }
651
+         //--- Store result
652
+         content=temp;
653
+        }
654
+     }
655
+
656
+//--- Close connection
657
+   if(httprequest>0)
658
+      InternetCloseHandle(httprequest);
659
+   if(httpopen>0)
660
+      InternetCloseHandle(httpopen);
661
+
662
+//--- Get out and return error code
663
+   return(e);
664
+  }
665
+//+------------------------------------------------------------------+
666
+//+ Macro function which returns content directly                    +
667
+//+------------------------------------------------------------------+
668
+string InternetGetFile(string url)
669
+  {
670
+   string content=NULL;
671
+   int e=InternetGetFile(url,content);
672
+   return content;
673
+  }
674
+//+------------------------------------------------------------------+
675
+void closeTrades(ENUM_POSITION_TYPE type,int magic)
676
+  {
677
+   Print("in close trade function : ",PositionsTotal());
678
+   for(int i=PositionsTotal()-1; i>=0; i--)
679
+     {
680
+      ulong ticket = PositionGetTicket(i);
681
+      string symbol=PositionGetSymbol(i);
682
+      Print("ticket ",ticket," Symbol : ",symbol);
683
+
684
+      if(PositionSelectByTicket(ticket))
685
+        {
686
+         Print("1");
687
+         if(PositionGetString(POSITION_SYMBOL)==symbol  && PositionGetInteger(POSITION_MAGIC) == magic && PositionGetInteger(POSITION_TYPE)==type)
688
+           {
689
+            Print("2");
690
+            if((PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)||(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL))
691
+              {
692
+               if(!trade.PositionClose(ticket))
693
+                 {
694
+                  Print("Problem in closing order buy", GetLastError());
695
+                 }
696
+               else
697
+                 {
698
+                  Print("Buy Order closed");
699
+                 }
700
+              }
701
+           }
702
+        }
703
+     }
704
+  }
705
+//+------------------------------------------------------------------+
706
+//+------------------------------------------------------------------+
707
+int orderCount(ENUM_POSITION_TYPE type,int magic_no)
708
+  {
709
+   int count=0;
710
+   for(int i=0; i<PositionsTotal(); i++)
711
+     {
712
+      ulong ticket = PositionGetTicket(i);
713
+      PositionSelectByTicket(ticket);
714
+      if(PositionGetInteger(POSITION_MAGIC)== magic_no && PositionGetSymbol(POSITION_SYMBOL)==Symbol() &&  PositionGetInteger(POSITION_TYPE) == type)
715
+        {
716
+         count++;
717
+        }
718
+     }
719
+// Print("Order count" + count);
720
+   return count;
721
+  }
722
+//+-----------
723
+//+------------------------------------------------------------------+
724
+void deleteFileNews()export
725
+  {
726
+   if(FileIsExist(fileName))
727
+      if(FileDelete(fileName))
728
+        {
729
+         Print("File:"+fileName+" deleted");
730
+        }
731
+
732
+  }
733
+//+------------------------------------------------------------------+
734
+string returnUpCommingNews(bool highFlag=true,
735
+                           int high_impact_value=60//Stop Trade before high News (min)
736
+                                 ,int end_impact_value=15 //Stop Trade after high News (min)
737
+
738
+                           ,bool mediumFlag=true
739
+                           ,int medium_impact_high=60//Stop Trade before medium News (min)
740
+                           ,int medium_impact_low=15 //Stop Trade after medium News (min)
741
+                           ,bool lowFlag=true
742
+                           ,int low_impact_high=60//Stop Trade before low News (min)
743
+                           ,int low_impact_low=15 //Stop Trade after low News (min)
744
+
745
+                           ,string symbol=""
746
+                           ,string expertname=""
747
+                           ,int gmt=2
748
+
749
+                          ) export
750
+  {
751
+   int newsStatus=0;
752
+   string content="No News";
753
+//Print("TImeCurrent:"+TimeCurrent()+"expiry:"+expiry);
754
+//"Trend Gridder(22)" || expertname=="TG NEWS" || expertname=="TG News"
755
+//"tylergabor"
756
+//((  expertname=="TG NEWS" || expertname=="TG News" || expertname=="Bandit" || expertname=="BANDIT" || expertname=="bandit" || expertname=="TG NEWS" || expertname=="TG News" || expertname=="C-Storm" || expertname=="C-STORM" || expertname=="c-storm" || (expertname=="C-StormV1.1" || (StringFind(chkexpert,"tyler")!=-1) || (StringFind(chkexpert,"hullincash")!=-1) ||(StringFind(chkexpert,"pk5000")!=-1) )))// && TimeCurrent()<expiry)
757
+
758
+// string chkexpert=expertname;
759
+// StringToLower(chkexpert);
760
+   if(Validate())
761
+     {
762
+
763
+      if(TimeDayMQL4(TimeCurrent())!=TimeDayMQL4(lastNews))
764
+        {
765
+         //updateNews();
766
+         fillNewsStruct();
767
+         lastNews=TimeCurrent();
768
+         Print("News Function is calling and updating by "+symbol);
769
+        }
770
+      int index=0;
771
+      string sym=symbol;
772
+      string metals=sym;
773
+      StringToLower(metals);
774
+      // StringToLower(extraSymbol);
775
+      //Print("---------------------Metals:"+metals+ " and symbol:"+ns[index].country," and extraSymbol:",extraSymbol);
776
+      //Print("checking metal:"+(StringFind("Nymex-J",sym,0)!=-1) +" and metal is:"+sym );
777
+      //Print("country:"+ns[index].country+" and check "+StringFind("JPYAUD",ns[index].country,0)!=-1))
778
+      //Start working here
779
+      while(index<newsSize)
780
+        {
781
+         Print("Inside the currency:",index, " currency:",ns[index].country," and curent demanding symbol:",metals, " nstime:",ns[index].time);
782
+
783
+         if((StringFind(sym,ns[index].country,0)!=-1))// || ((metals=="wticrude." || metals=="usoil" || metals=="crude"  || metals=="crude" || metals=="usousd" || metals=="wticousd"  || (StringFind(metals,"nymex",0)!=-1) || (StringFind(metals,"WTICrude",0)!=-1) || (StringFind(metals,extraSymbol,0)!=-1)) &&((StringFind("USD",ns[index].country,0)!=-1) || (StringFind("CAD",ns[index].country,0)!=-1))))
784
+           {
785
+            Print("Inside the currency:",index, " currency",ns[index].country, " and curent demanding symbol:",metals, "nstime:",ns[index].time);
786
+
787
+            //     int low_time;
788
+            //    int high_time;
789
+            datetime ulow_time,uhigh_time;
790
+
791
+            //    int time_in_seconds;
792
+            datetime utime_in_seconds;
793
+            //this is the current broker time
794
+            //     time_in_seconds=(TimeHour(iTime(symbol,0,0))*60*60)+(TimeMinute(iTime(symbol,0,0))*60);
795
+            //  Print("nsDate:"+ns[index].date);
796
+            utime_in_seconds=TimeCurrent();
797
+
798
+            string chngdt=changeDateFormate(ns[index].date);
799
+            //     string Date1=TimeToString(TimeCurrent(),TIME_DATE);
800
+
801
+            datetime updatedDateTime=StringToTime(chngdt+" 00:00:00");
802
+            updatedDateTime+=NsTimeInSeconds(ns[index].time);
803
+
804
+            //   Print("updateTime1+nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
805
+
806
+            //  string updatedTime=TimeToString(updatedDateTime,TIME_MINUTES);
807
+            updatedDateTime+=((gmt)*3600);
808
+
809
+            //  Print("updateTime 2 +nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
810
+            //     string Today1=TimeToString(updatedDateTime,TIME_DATE);
811
+
812
+            //   string times=Time24Conversion(ns[index].time);
813
+            datetime temp2;
814
+            temp2=updatedDateTime;
815
+            // Print("chngDate:"+chngdt);
816
+            //  Print("Time in Seconds:"+time_in_seconds);
817
+            //  Print("temp2:"+temp2);
818
+            Print("------------Index:",index," updated Date Time:",updatedDateTime);
819
+
820
+            if(ns[index].impact=="High" && highFlag)
821
+              {
822
+
823
+               //  low_time=NsTimeInSeconds(ns[index].time)-(high_impact_value*60);
824
+               //high_time=NsTimeInSeconds(ns[index].time)+(end_impact_value*60);
825
+               ulow_time=updatedDateTime-(high_impact_value*60);
826
+               uhigh_time=updatedDateTime+(end_impact_value*60);
827
+               //    Print("High least:"+low_time+" high highest:"+high_time);
828
+               //     Print("Date1:"+Date1+" today1:"+Today1);
829
+               //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
830
+               //  Print("------------Index:"+index+" updated Date Time:"+updatedDateTime);
831
+
832
+               //  Print("----------HighNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
833
+               if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
834
+                 {
835
+
836
+                  //flag=true;
837
+                  newsStatus=1;
838
+                  if(temp2!=previous_time)
839
+                    {
840
+
841
+                     Print("Inside high alert");
842
+
843
+                     content=ns[index].title;
844
+
845
+
846
+                     previous_time=temp2;
847
+                    }
848
+
849
+                  break;
850
+                 }
851
+              }
852
+
853
+            //medium impact
854
+            else
855
+               if(ns[index].impact=="Medium" && mediumFlag)
856
+                 {
857
+                  // low_time=NsTimeInSeconds(ns[index].time)-(medium_impact_high*60);
858
+                  // high_time=NsTimeInSeconds(ns[index].time)+(medium_impact_high*60);
859
+                  ulow_time=updatedDateTime-(medium_impact_high*60);
860
+                  uhigh_time=updatedDateTime+(medium_impact_low*60);
861
+
862
+                  // Print("medium least:"+low_time+" medium highest:"+high_time);
863
+                  //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
864
+
865
+                  //  Print("----------MediumNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
866
+
867
+                  if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
868
+
869
+                    {
870
+                     //StopTrading(); //Close Current Orders Buy/Sell
871
+                     // flag=true;
872
+                     //     Print("Inside high alert");
873
+                     newsStatus=2;
874
+                     if(temp2!=previous_time)
875
+                       {
876
+
877
+                        content=ns[index].title;
878
+
879
+
880
+                        previous_time=temp2;
881
+                       }
882
+                     break;
883
+                    }
884
+                 }
885
+               else
886
+                  if(ns[index].impact=="Low" && lowFlag)
887
+                    {
888
+                     ///    low_time=NsTimeInSeconds(ns[index].time)-(low_impact_high*60);
889
+                     //   high_time=NsTimeInSeconds(ns[index].time)+(low_impact_high*60);
890
+                     //Print("low least:"+low_time+" low highest:"+high_time);
891
+                     //   Print("In low impact and currency is:"+ns[index].country);
892
+                     ulow_time=updatedDateTime-(low_impact_high*60);
893
+                     uhigh_time=(updatedDateTime)+(low_impact_low*60);
894
+
895
+                     // if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
896
+
897
+                     //    Print("-------Low news Now dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);//+" low time in min:"+low_impact_low);
898
+
899
+                     if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
900
+
901
+                       {
902
+                        //StopTrading(); //Close Current Orders Buy/Sell
903
+                        // flag=true;
904
+                        //    Print("Inside high alert");
905
+                        //  Print("updateDateTime:"+updatedDateTime);
906
+                        newsStatus=3;
907
+                        // Print("Temp2"+temp2);
908
+                        if(temp2!=previous_time)
909
+                          {
910
+                           content=ns[index].title;
911
+
912
+                           previous_time=temp2;
913
+                          }
914
+                        break;
915
+                       }
916
+                    }
917
+            //
918
+           }//Close Country Symbol if
919
+         index++;
920
+        }
921
+
922
+     }
923
+   else
924
+     {
925
+      //  Print("exprtName:"+chkexpert+"stringfind:"+IntegerToString((StringFind(chkexpert,"FX Ekspert Ghost Trader"))));
926
+      Print("Validation Error");
927
+     }
928
+   return content;
929
+  }
930
+//+------------------------------------------------------------------+
931
+int TimeDayMQL4(datetime date)
932
+  {
933
+   MqlDateTime tm;
934
+   TimeToStruct(date,tm);
935
+   return(tm.day);
936
+  }
937
+
938
+//+------------------------------------------------------------------+
939
+//|                                                                  |
940
+//+------------------------------------------------------------------+
941
+int TimeHourMQL4(datetime date)
942
+  {
943
+   MqlDateTime tm;
944
+   TimeToStruct(date,tm);
945
+   return(tm.hour);
946
+  }
947
+
948
+
949
+//+------------------------------------------------------------------+
950
+//|                                                                  |
951
+//+------------------------------------------------------------------+
952
+int TimeMinuteMQL4(datetime date)
953
+  {
954
+   MqlDateTime tm;
955
+   TimeToStruct(date,tm);
956
+   return(tm.min);
957
+  }
958
+//+------------------------------------------------------------------+

BIN
line_level_ea.ex5


BIN
line_level_ea.mq5