소스 검색

Revert "Merge branch 'development/entry-conditions' of huzaifa.hayat/vol_hedge_strategy_mt5 into master"

This reverts commit c3118be8f665b6b24b80ba25d3eb51764c1ef521, reversing
changes made to d64edb0f380d84356fb30156e7c57ab3d2843fe7.
WajeehSaqib-MQL 4 달 전
부모
커밋
cd59a8eb55
5개의 변경된 파일0개의 추가작업 그리고 2275개의 파일을 삭제
  1. 0 2
      data/vol_hedge_data.csv
  2. BIN
      library/volHedgeNewsFilter.ex5
  3. 0 964
      library/volHedgeNewsFilter.mq5
  4. BIN
      vol_hedge_strategy_mt5.ex5
  5. 0 1309
      vol_hedge_strategy_mt5.mq5

+ 0 - 2
data/vol_hedge_data.csv

@@ -1,2 +0,0 @@
1
-EURUSDm,1.08384,1000,1000,2023.03.22 02:05:25,2023.03.24 02:05:25
2
-EURUSDm,1.08734,400,400,2023.03.30 00:00:00,2023.04.04 02:05:25

BIN
library/volHedgeNewsFilter.ex5


+ 0 - 964
library/volHedgeNewsFilter.mq5

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

BIN
vol_hedge_strategy_mt5.ex5


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 1309
vol_hedge_strategy_mt5.mq5