Problem with file read

 

Hello guys,

I have an EA that reads data from a txt file and opens positions based on them I am testing this in strategy tester, the problem is when I change the name of txt file it still reads the previous file name and it isn't changed.

and when I use the same file name and change the data in it it still works with previous data. Do you have any idea why this happens and what can I do? Here is the code of reading the file:

int OnInit()
  {
   ArrayResize(prediction_data, 2000);
   int file_handle = FileOpen(InpFileName, FILE_ANSI | FILE_READ | FILE_COMMON);
   if(file_handle != INVALID_HANDLE)
     {
      while(!FileIsEnding(file_handle))
        {
         string line = FileReadString(file_handle);
         if(StringLen(line) == 0)
            continue;
         string parts[];
         int part_count = StringSplit(line, '|', parts);
         if(part_count == 2)
           {
            PredictionData data;
            data.DateTime = StringToTime(parts[0]);
            data.Predicted = StringToDouble(parts[1]);
            if(total_records >= ArraySize(prediction_data))
              {
               ArrayResize(prediction_data, ArraySize(prediction_data) * 2);
              }
            prediction_data[total_records++] = data;
           }
        }
      FileClose(file_handle);
      ArrayResize(prediction_data, total_records);
      return INIT_SUCCEEDED;
     }
   else
     {
      return INIT_FAILED;
     }
  }
 
john s: the problem is when I change the name of txt file it still reads the previous file name and it isn't changed.
            if(total_records >= ArraySize(prediction_data))
EAs are not reloaded on input changes. You do not reset total_records. You append the new file to the existing array.
 
William Roeder #:
EAs are not reloaded on input changes. You do not reset total_records. You append the new file to the existing array.
Thank you so much William you solved my problem that I've had for months!