File Operations: Reading CSV - page 2

 
onewithzachy:

I was eagerly waiting to reply "Thank God it's only Burton", ... turned out, ... huh.

Just kidding Burton, people are too serious over here in this forum, seriously no kidding :) 

Have fun.

:D 

I have modified the script even further to open orders based on time data supplied in results.txt or data.txt.

Time data is supplied on each line as :- date, hour, minute 

So that EA opens one sell order on that date at that hour and minute.

#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern int SL=70;
extern int TP=20;

int data[10][3];  

int start()
{
   string separator=",";
   int m_handle=-1, count, line_count = 1;
   string m_filename="data.txt";
   
double price=Ask;
double balance; //the balance
double equity; //the equity

balance=AccountBalance();
equity=AccountEquity();

 
 m_handle=FileOpen(m_filename,FILE_CSV|FILE_ANSI|FILE_READ,separator,CP_ACP);
   if(m_handle<0)
     {
     Print("I can't open the file.");
     }
     else
     {
     Print("File successfully open.");
     while (FileIsEnding(m_handle) == false)
       {
       data[count][0]=FileReadInteger(m_handle, 10);
       data[count][1]=FileReadInteger(m_handle, 10);
       data[count][2]=FileReadInteger(m_handle, 10);
       
       if (balance==equity && Day()==data[count][0] && Hour()==data[count][1] && Minute()==data[count][2]) 
       OrderSend(Symbol(),OP_SELL,1.5*equity/100,Bid,20,Ask+SL*Point,Ask-TP*Point,"My order",16384,0,Green);
       
       if (FileIsLineEnding(m_handle) == true)line_count ++;
       count ++;
       }

      FileClose(m_handle);
     }
   PlaySound("wait.wav");
  

return(0);

  }

 This code will execute easily in a script. However the EA fails to open the data file. I simply dont understand the reason why script can access data.txt while EA with the same code cannot.

The data.txt is put in ...\MQL4\Files folder 

 The tester gives error:- "2015.03.16 04:41  TimeEA EURUSD,M1: I can't open the file." 

 

How to correct this error? 

Files:
data.txt  1 kb
 
Andrey Voytenko #:

Open your file in ANSI mode.

 

Thanks, you solved my problem too

Reason: