File Read Problems

 

Hey Guys i have a little piece of code thats saving the current position open price on a text file with the following code:

int file = FileOpen(BOTMagic_Number+".txt", FILE_WRITE|FILE_ANSI, ',');
      if (file != INVALID_HANDLE)
      {
         FileWrite(file, pricenow.bid);
         FileClose(file);

      }

Then am trying to retrieve the value for a trailing stop that i created with this code

double GetOpenPrice(ulong BOTMagic_Number)
{
  
   int file = FileOpen(BOTMagic_Number+".txt", FILE_READ|FILE_TXT|FILE_UNICODE);
   Alert(BOTMagic_Number+".txt");
   double priceopen;
   if (file != INVALID_HANDLE)
   {
      bool filesize = FileIsExist(file);
      Alert(filesize);
      priceopen = FileReadDouble(file);
      Alert(priceopen);
      FileClose(file);
   }
   return priceopen;

}

The code above works just fine on the tester, but when i put it to run on a demo account its not able to read the file i checked that the file its on MQL\Files, but the FileIsExist command its telling me false, now am not sure if this has something to do but my foward demo testing EA are running on a machine where i just COPIED the MetaTrader5 folder, i didnt install it, the client runs just fine, but am not sure if that has anything to do with it, please help me!

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
 

Hi,

Do you notice the FILE path folder for backtester and demo account is different? Make sure the file is exist on demo account folder

Please refer to this document:

http://www.mql5.com/en/docs/files


Also referring to your codes, I am curious why do you write the file as FILE_ANSI, but read it as FILE_UNICODE?


Cheers.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags
  • www.mql5.com
Standard Constants, Enumerations and Structures / Input/Output Constants / File Opening Flags - Documentation on MQL5
 
meisme:

Hi,

Do you notice the FILE path folder for backtester and demo account is different? Make sure the file is exist on demo account folder

Please refer to this document:


Also referring to your codes, I am curious why do you write the file as FILE_ANSI, but read it as FILE_UNICODE?


Cheers.

Hey meisme, thank you so much for the response, I was able to make it work i changed a couple of things in the code, but the main problem happened because of the wrong metatrader install on my test machine. I include my code if anyone is looking for a quick solution of reading numbers from text files.

Write simple text file to insert the order price:

 int file = FileOpen(AccountInfoInteger(ACCOUNT_LOGIN)+"_"+BOTMagic_Number+".txt", FILE_WRITE|FILE_TXT|FILE_ANSI);
      if (file != INVALID_HANDLE)
      {
         FileWrite(file, pricenow.bid);
         FileClose(file);

      }


Read the order price:

int file = FileOpen(AccountInfoInteger(ACCOUNT_LOGIN)+"_"+BOTMagic_Number+".txt", FILE_READ|FILE_TXT|FILE_ANSI);
   double priceopen;
   if (file != INVALID_HANDLE)
   {
      priceopen = StringToDouble(FileReadString(file));
      FileClose(file);
   }
   return priceopen;