Error 4025 on Web Request

arimbur  
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.

William Roeder  
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'