Script works perfect but same code in EA produces errors. Why so and how to solve???? - InstaForex | Forex Forum | Forex world | InstaForex Forum
Instant Forex Trading

Welcome Guest ( Log In | )

 
Add Reply   New Topic
Script works perfect but same code in EA produces errors. Why so and how to solve????
 Topic Options
 
Robin Morajker
post Mar 30, 2015, 12:03 AM
Post #1
Newbie
*
Group: Members
Posts: 8
Joined: October 13, 2010
Member No.: 4,880

post Mar 30, 2015, 12:03 AM
Post #1
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 is simply unable to open file supplied.

CODE
#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?

Attached File(s)
Attached File  data.txt ( 328bytes ) Number of downloads: 226
 
Go to the top of the page
 
+Quote Post
 


        1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version   Partnership with InstaForex   Open account in InstaForex   Support InstaForex Time is now: 28th March 2024 - 04:56 PM