Преглед на файлове

Ticket: 5208 News file loaded once

Huzaifa-MQLDev преди 9 месеца
родител
ревизия
b9463787cd
променени са 3 файла, в които са добавени 41 реда и са изтрити 32 реда
  1. BIN
      library/volHedgeNewsFilter.ex5
  2. 41 32
      library/volHedgeNewsFilter.mq5
  3. BIN
      vol_hedge_strategy_mt5.ex5

BIN
library/volHedgeNewsFilter.ex5


+ 41 - 32
library/volHedgeNewsFilter.mq5

@@ -468,43 +468,52 @@ void fillNewsStruct()
 //+------------------------------------------------------------------+
 void updateNews()
   {
-   string cookie=NULL,strNews;
-   string reqheaders="User-Agent: Mozilla/4.0\r\n";
-   char post[],result[];
-   int res;
-//http://www.forexfactory.com/ffcal_week_this.xml
-   string url="https://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml";
-   url="https://nfs.faireconomy.media/ff_calendar_thisweek.xml";
-   ResetLastError();
-   int timeout=5000;
-//res=WebRequest("GET",url,reqheaders,timeout,post,result,headers);
-   res=InternetGetFile(url,strNews);
-
-   StringToCharArray(strNews,result);
-   if(res==-1)
+   datetime lastFileModified=(datetime)FileGetInteger(fileName,FILE_MODIFY_DATE);
+   if(lastFileModified < iTime(Symbol(), PERIOD_D1, 0))
      {
-      Print("Error in WebRequest. Error code  =",GetLastError());
-      //--- Perhaps the URL is not listed, display a message about the necessity to add the address
-      MessageBox("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
-     }
-   else
-     {
-      //--- Load successfully
-      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
-      //--- Save the data to a file
-      int filehandle=FileOpen(fileName,FILE_WRITE|FILE_BIN);
-      //--- Checking errors
-      if(filehandle!=INVALID_HANDLE)
+      Print(" ---------------------------------------- Updating News File ------------------------------------- ");
+      string cookie=NULL,strNews;
+      string reqheaders="User-Agent: Mozilla/4.0\r\n";
+      char post[]
+      ,result[];
+      int res;
+      //http://www.forexfactory.com/ffcal_week_this.xml
+      string url="https://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml";
+      url="https://nfs.faireconomy.media/ff_calendar_thisweek.xml";
+      ResetLastError();
+      int timeout=5000;
+      //res=WebRequest("GET",url,reqheaders,timeout,post,result,headers);
+      res=InternetGetFile(url,strNews);
+
+      StringToCharArray(strNews,result);
+      if(res==-1)
         {
-         //--- Save the contents of the result[] array to a file
-         FileWriteArray(filehandle,result,0,ArraySize(result));
-         //--- Close the file
-         FileClose(filehandle);
+         Print("Error in WebRequest. Error code  =",GetLastError());
+         //--- Perhaps the URL is not listed, display a message about the necessity to add the address
+         MessageBox("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
         }
       else
-         Print("Error in FileOpen. Error code=",GetLastError());
+        {
+         //--- Load successfully
+         PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
+         //--- Save the data to a file
+         int filehandle=FileOpen(fileName,FILE_WRITE|FILE_BIN);
+         //--- Checking errors
+         if(filehandle!=INVALID_HANDLE)
+           {
+            //--- Save the contents of the result[] array to a file
+            FileWriteArray(filehandle,result,0,ArraySize(result));
+            //--- Close the file
+            FileClose(filehandle);
+           }
+         else
+            Print("Error in FileOpen. Error code=",GetLastError());
+        }
+     }
+   else
+     {
+      Print(" ---------------------------------------- News File Already Updated ------------------------------------- ");
      }
-
   }
 //+------------------------------------------------------------------+
 //|                                                                  |

BIN
vol_hedge_strategy_mt5.ex5