Script reads from CSV but EA does not.. Why??????????

Back to topics list To post a new topic, please log in or register
avatar
2
RobinMorajker 2015.03.29 19:36
 

This is an ea to open orders based to time data supplied in a comma separated values in .csv file. It works brilliantly in a script but in an ea it simply unable to open file supplied.

#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);

  }

 

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

 

the time data is supplied in data.txt formatted as:-  date,hour,minute 
This file is placed in ...\MQL4\Files folder and is accessible to all the scripts.

How to correct that error?

Can anyone help me?

 

Note:This post has been edited as there were gross mistakes in the previous one. Thanks to WHRoeder
Attached files:
  data.txt  (0.32 KB)
avatar
12985
WHRoeder 2015.03.29 20:55 #
 
RobinMorajker: I tried to go through mql4 reference but it reads from binary file which I dont want to use.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Read the documentation again. What does FILE_CSV mean?
avatar
2
RobinMorajker 2015.03.29 23:54 #
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Read the documentation again. What does FILE_CSV mean?
I cleaned up the code but still there is a major problem as mentioned above...
avatar
12985
WHRoeder 2015.03.30 15:09 #
 
  1. Why don't you print out the last error in your message, so you find out why.
  2. This file is placed in ...\MQL4\Files folder and is accessible to all the scripts.
    Are you trying to use the tester?
  3.    int m_handle=-1, count, line_count = 1;
    
    Count has no value, so you will be trying to store in a random array element and will likely get array exceeded.
Back to topics list  

To add comments, please log in or register