Class Function Help

 
Hi All,
    I am working on creating a class that will be used when called upon. 

I'm basically trying to make sure that system always uses the server time when trading on certain days. 

However, i have come across an issue where i can not see the mistake, if any done. 

Any ideas/help would be much appreciated. Thank you


Below is the Script and error received. 

Cheers!
class CTimer
{
 public:
 bool CheckTimer(bool LocalTime = false);
 };





bool CTimer::CheckTimer(bool LocalTime=false) 
{                                                                                                                                                                                                                                                                                                                                                                  
datetime Currentday; 
if (LocalTime == true) Currentday = TimeLocal();
else Currentday = TimeCurrent(); 

bool tradeEnabled = false;

if (DayOfWeek()!= 0||DayOfWeek()!=5||DayOfWeek()!=6)
{
tradeEnabled = true;
}

return(tradeEnabled);


}


  
   
int OnStart()

{  
     
bool tradeEnabled = CTimer::CheckTimer();    // Line 131 
if ( tradeEnabled==true)
{
Alert (" It is Trading Day");
return true; 
}
else 
{
Alert (" It is the weekend"); 
return false; 
}

return(INIT_SUCCEEDED);
}



//Error on Line 131: 'CheckTimer' - access to non-static member or function      Testing Script.mq4     131     29

Create Your Own Trading Robot in 6 Steps!
Create Your Own Trading Robot in 6 Steps!
  • www.mql5.com
The world around us is changing rapidly, and we try to keep up with it. We do not have time to learn something new, and this is a normal attitude of a normal human being. Traders are people just like everyone else, they want to get maximum results for the minimum of effort. Specially for traders, MetaEditor 5 offers a wonderful MQL5...
 
David Cunha:
Hi All,
    I am working on creating a class that will be used when called upon. 

I'm basically trying to make sure that system always uses the server time when trading on certain days. 

However, i have come across an issue where i can not see the mistake, if any done. 

Any ideas/help would be much appreciated. Thank you


Below is the Script and error received. 

Cheers!
#property strict


class CTimer
{
   public:
      bool CheckTimer(bool LocalTime);        // this is passed no need to initialize false
};

bool CTimer::CheckTimer(bool LocalTime) 
{                                                                                                                                                                                                                                                                                                                                                                  
   datetime Currentday; 
   if (LocalTime == true) 
      Currentday = TimeLocal();
   else 
      Currentday = TimeCurrent(); 
  
   if(DayOfWeek() > 0 && DayOfWeek() < 5)        // simplified
      return(true);
   
   return(false);
}

void OnStart()		// type void not int
{  
   CTimer myObject;     		// declare an object of the class
     
   if(myObject.CheckTimer(true)) 	// use the method of the object and simplified
      Alert(" It is Trading Day");
   else 
      Alert(" It is the weekend"); 
}

 
  1. Code
       if(DayOfWeek() > 0 && DayOfWeek() < 5)        // simplified
          return(true);
       
       return(false);
    Simplified
    return DayOfWeek() > 0 && DayOfWeek() < 5;
              Why this always returns false? - MQL4 programming forum

  2. What is the purpose LocalTime and Currentday, when the above code only uses broker time?
 
William Roeder:
  1. Code
    Simplified
              Why this always returns false? - MQL4 programming forum

  2. What is the purpose LocalTime and Currentday, when the above code only uses broker time?
 
 
Paul Anscombe:
 
Thank you Paul for the help and simplifying the code. Much appreciated. I will give this a shot. Thank you very much. 

To answer William's question i wanted the option to switch between local and server time. So i attempted to make a boolean variable to switch between the two and have that checked by the day of the week. 

Again thank you Both

Cheers
 
David Cunha:
Thank you Paul for the help and simplifying the code. Much appreciated. I will give this a shot. Thank you very much. 

To answer William's question i wanted the option to switch between local and server time. So i attempted to make a boolean variable to switch between the two and have that checked by the day of the week. 

Again thank you Both

Cheers

you are welcome

William's point is that you are not actually checking the variable CurrentDay  your use of DayofWeek() only checks the last known server time...

You should use TimeToStruct()  

https://docs.mql4.com/dateandtime/timetostruct

TimeToStruct - Date and Time - MQL4 Reference
TimeToStruct - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeToStruct - Date and Time - MQL4 Reference