Error 4025 on Web Request

 
void Download_News()
  {
   if(FileGetInteger("FFC-ffcal_week_this"+_Symbol+".xml",FILE_MODIFY_DATE,false)+4*60*60 < TimeLocal() || !FileIsExist("FFC-ffcal_week_this"+_Symbol+".xml",0))
     {
      string cookie=NULL, headers;
      string reqheaders="User-Agent: Mozilla/4.0\r\n";
      char post[],result[];
      int res;
      string url="https://nfs.faireconomy.media/ff_calendar_thisweek.xml";
      ResetLastError();
      int timeout=5000;
      srand(ChartID());
      int ran = rand() > 1000? rand():2*rand()+1000;
      do
        {
         Sleep(ran);
         res=WebRequest("GET",url,reqheaders,timeout,post,result,headers);
        }
      while(ArraySize(result) == 0 && res == -1);
      if(res==-1)
        {
         Alert("Error in WebRequest. Error code = ",GetLastError());
        }
      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("FFC-ffcal_week_this"+_Symbol+".xml",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());
        }
     }
  }

I run this EA on 34 charts at same time.


When he folder \MQL4\Files is Empty before the EA being Initialized the code download correctly all the 34 files.

 After 4 hours the function is run again, this time tries to rewrite all the 34 files, every single time after 5-10 files downloaded and rewritten it get stuck in the do-while loop with the error : 4025 [Out Of Memory].


I have no idea how to fix this. I prefer solving it without use .ddl dependencies, because they seems more complicated to me and faced several problems time ago.


Is there a good soul who would help me fixing this?

If you need more code I will provide it.

 
arimbur:

I run this EA on 34 charts at same time.

it get stuck in the do-while loop with the error : 4025 [Out Of Memory].

  1. No idea. You probably should place a Mutex at the start of the function so only one thread can download at a time.
              Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 programming forum (2016)

  2. You should find out what line is giving the error.

    #define LOG(text)  Print(__FILE__,"(",__LINE__,") :",text)   // one parameter - 'text'
    

 
William Roeder #:
  1. No idea. You probably should place a Mutex at the start of the function so only one thread can download at a time.
              Prevent EA from opening trades at the same time across two or more pairs? (Steve) - MQL4 programming forum (2016)

  2. You should find out what line is giving the error.


Forgive my ignorance, how can I implement your Mutex.mqh on my code?
 
arimbur #: Forgive my ignorance, how can I implement your Mutex.mqh on my code?

My suggestion is to first do some research into what a Mutex is and how to use one.

 
arimbur #: Forgive my ignorance, how can I implement your Mutex.mqh on my code?

Simplified, standalone version: Prevent EA from opening trades at the same time across 2 or more pairs? - MQL4 programming forum - Page 2

#include "mutex1.mqh"
void Download_News()
  {
   Mutex m;
   if(FileGetInteger(…
 

I have the same error (4025) on WebRequest. This is my code:

        string cookie = NULL, headers;
        char post[], result[];
        string ret = "";
        int res;
        //--- to work with the server, you must add the URL "https://www.google.com/finance"  
        //--- the list of allowed URL (Main menu-> Tools-> Settings tab "Advisors"): 
        string google_url = "http://ec.forexprostools.com/?columns=exc_currency,exc_importance,exc_forecast,exc_previous&amp;importance=1,2,3&calType=week&timeZone=15&lang=1";
        //--- 
        //--- download html-pages
        int timeout = 10000; //--- timeout less than 1,000 (1 sec.) is insufficient at a low speed of the Internet
        ResetLastError();
        res = WebRequest("GET", google_url, cookie, NULL, timeout, post, 0, result, headers);
        //--- error checking
        if (res == -1)
        {
                //--- You must add the address ' "+ google url"' in the list of allowed URL tab 'Advisors' "," Error "
                if (_LastError == 4060) MessageBox("You must add the address 'http://ec.forexprostools.com/' in the list of allowed URL tab 'Advisors' ", " Error ", MB_ICONINFORMATION);
                else if (_LastError != 5203) Print("WebRequest error, err.code  = ", _LastError);
        }
        else
        {
                //--- successful download
                ret = CharArrayToString(result);
        }

MT4 build 1360

Reason: