Download MetaTrader 5

String function not returning date, help!

To add comments, please log in or register
Opengates
165
Opengates  

Hello Gurus in the house,

I am trying to convert date and time string to function as date and time real time in my ea but keeps giving error 'StrToDate' - wrong parameter count", below are the codes:


extern string        NewsDate         = "09/06/2015"; // Year for the News to be released
extern string        NewsTime         = "12:30";   // Time for the News to be released

string  StrToDate();

 //variables defined
string   DateTime=StringConcatenate(NewsDate," ",NewsTime);
datetime Startdate=StrToDate(DateTime, "dd/mm/yyyy hh:mi"); 

if(TimeCurrent()==Startdate) {
//perform certain tasks
} 


pls check and let me know where I got it wrong.

Thanks in advance

Keith Watford
Moderator
9996
Keith Watford  

You haven't written the function StrToDate()

Maybe you could use StrToTime(), but that uses   "yyyy.mm.dd hh:mi " format

Opengates
165
Opengates  
GumRai:

You haven't written the function StrToDate()

Maybe you could use StrToTime(), but that uses   "yyyy.mm.dd hh:mi " format

Thanks GumRai, I changed to StrToTime() but it says "no one of the overloads can be applied to the function call", pls what do you think that can mean and what do I do OR how do I write the function StrToDate() to produce the right result? Thanks
Keith Watford
Moderator
9996
Keith Watford  
Opengates:
Thanks GumRai, I changed to StrToTime() but it says "no one of theoverloads can be applied to the function call", pls what do you thinkthat can mean and what do I do OR how do I write the function StrToDate() to produce the right result? Thanks

StrToTime() only uses 1 parameter, if you are using more than 1, you are overloading the function

  extern string        NewsDate         = "2015.06.09"; // Date for the News to be released
  extern string        NewsTime         = "12:30";   // Time for the News to be released

//In your main code

  string   DateTime=StringConcatenate(NewsDate," ",NewsTime);
  datetime Startdate=StrToTime(DateTime);


  if(TimeCurrent()==Startdate)    //Be careful of using == in case of missed ticks
    {
    //perform certain tasks
    }

Change the format for entering the date as above.

Avoid using DateTime to name a string variable, it can be confusing 

Opengates
165
Opengates  
GumRai:

StrToTime() only uses 1 parameter, if you are using more than 1, you are overloading the function

Change the format for entering the date as above.

Avoid using DateTime to name a string variable, it can be confusing 

 

Thanks so much, just as you corrected me, it works fine. You are blessed
whroeder1
15023
whroeder1  
To add comments, please log in or register