problem with external files

 

here is my code. 


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int handler;
string source = "test.txt";
int OnInit()
  {
//---
   handler=FileOpen(source,FILE_ANSI|FILE_TXT|FILE_READ);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
   string matn;
   if(handler<0)
     {
      Print("Failed to open the file by the absolute path "+source);
      Print("Error code ",GetLastError());
     }else
   if(handler>=0)
     {
      matn="DID WORK";
     }  
   int INts=FileReadInteger(handler,INT_VALUE);
   string str=FileReadString(handler,5);
   Comment(matn,"-/",handler,"--/",str,"---/",INts);
  }

the return in comment says handler did work but I can not get the string inside the file and nor the length of the file from FileReadInteger. 
I am not sure what I am missing. the file is a txt as you can see in my code but I can not read the property written inside of it.
anyone can help me?

 

Post the file.

Where is your file close ? FileClose(hander) ?

 

Oops. thanks alain. there were a few mistakes in my code handled by your guide and a few other searches. now I am facing another issue.

I get my file in realtime but can't have it in strategy tester

I placed my file here: C:\Program Files\Alpari MT5\Tester\Files

but I can't place it here: C:\Program Files\Alpari MT5\Tester\Agent-127.0.0.1-3000\MQL5\Files

cus everytime I run my strategy tester, it cleares the file I pasted in directory above and so it can not find the file. So when I start the strategy tester, the data folder is empty. where I need to put the file for the strategy tester to find it?

 
babigaf:

Oops. thanks alain. there were a few mistakes in my code handled by your guide and a few other searches. now I am facing another issue.

I get my file in realtime but can't have it in strategy tester

I placed my file here: C:\Program Files\Alpari MT5\Tester\Files

but I can't place it here: C:\Program Files\Alpari MT5\Tester\Agent-127.0.0.1-3000\MQL5\Files

cus everytime I run my strategy tester, it cleares the file I pasted in directory above and so it can not find the file. So when I start the strategy tester, the data folder is empty. where I need to put the file for the strategy tester to find it?

You need to use #property tester_file "your_file". Check the documentation.

 
you are awesome bro. thanks. found the problem with your help ^__^
 

You could put the file into the common file folder. This folder is accessible in both real and test mode and it's not cleared by the tester.

handler=FileOpen(source,FILE_ANSI|FILE_TXT|FILE_READ|FILE_COMMON);
Reason: