Error code 5008 Invalid Handle (handle index is out of handle table) When reading CSV

 

My code below is running into error 5008 and from my understanding it's because I'm not closing the csv file after reading it? However I have closed it but don't seem to figure out why this is popping up. My files are in the MQL4/Files folder so my file path is correct. Can someone please tell me what's wrong with it?

//Global Variable
int handle;


void OnTick()
  {
    
     string data[1][18];
     
     if(TimeCurrent() > (Switch+5)){
     handle=FileOpen("LogisticRegressionOutputNDX.csv",FILE_CSV|FILE_SHARE_READ,",");
     if(handle = INVALID_HANDLE){Alert("Error Reading File",GetLastError());}
     int row = 0;
     ArrayResize(data,18);
     while(!FileIsEnding(handle))
     {
       if(row>ArraySize(data)/18-1){ArrayResize(data,(row+1)*18);}
       for(int i=0;i<=18-1;i++)data[row][i]=FileReadString(handle);
       row++;
     }
     FileClose(handle);
     Alert(data[0][0]);
    
   Switch = TimeCurrent();
   }

The goal of this code is to import a CSV file every x seconds and read a specific cell from the file and then save the value to an array which will then be used to either Buy/Sell.

 
     if(handle = INVALID_HANDLE)
An assignment; not a comparison.
 
handle=FileOpen("LogisticRegressionOutputNDX.csv",FILE_CSV|FILE_SHARE_READ,",");
     

You need to use FILE_READ to read it.

READ the documentation PLEASE.

 
William Roeder #:
An assignment; not a comparison.

Thank you William, your solution fixed it!

Reason: