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!
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"); }
Code if(DayOfWeek() > 0 && DayOfWeek() < 5) // simplified return(true); return(false);
Simplified return DayOfWeek() > 0 && DayOfWeek() < 5;
- What is the purpose LocalTime and Currentday, when the above code only uses broker time?
William Roeder:
Code Simplified - What is the purpose LocalTime and Currentday, when the above code only uses broker time?
![](https://c.mql5.com/3/325/1728961963723.png)
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
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()
![TimeToStruct - Date and Time - MQL4 Reference TimeToStruct - Date and Time - MQL4 Reference](https://c.mql5.com/36/38/timetostruct-date-and-time-mql4.png)
TimeToStruct - Date and Time - MQL4 Reference
- docs.mql4.com
TimeToStruct - Date and Time - MQL4 Reference
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!