start a function when the market is closed? - page 3

 
Thirteen:


Third, if I may ask, why are you using TimeDayOfWeek() rather than DayOfWeek()?

DayOfWeek() may well have issues in the Strategy Tester . . https://www.mql5.com/en/forum/144021
 
Thirteen: that your code needs to cycle through a weekend before it determines there is a new week.
static int DOWcurr;
int DOWprev = DOWcurr; DOWcurr = TimeDayOfWeek(Time[0]);
bool newWeek = DOWcurr < DOWprev;
Exactly. Most newBar codes return true when a EA is added mid-bar.
int start(){
   static datetime time0;
   bool newBar = time0 != Time[0]; time0 = Time[0]; // New bar OR first install
If you want a actual new bar it must be coded properly
datetime time0; int init(){ time0 = Time[0]; ...}
int start(){
   bool newBar = time0 != Time[0]; time0 = Time[0]; // No mid bar allowed.
If you want it to return a newWeek when you put it on a chart late Friday, code it that way.
int DOWcurr; int init(){ DOWcurr = 7; ... }
int start(){
   int DOWprev = DOWcurr; DOWcurr = TimeDayOfWeek(Time[0]);
   bool newWeek = DOWcurr < DOWprev;
 
RaptorUK:
DayOfWeek() may well have issues in the Strategy Tester . . https://www.mql5.com/en/forum/144021

I conducted a test (and posted the results in response to WHRoeder post you cited above) which seems to show that DayOfWeek() now works correctly in the Tester. See https://www.mql5.com/en/forum/144021. Just now, I took the same code from my test--

int day_of_week = 0;

int start() {
   if (day_of_week != DayOfWeek()) {
      Print ("DayOfWeek is ", DayOfWeek());
      day_of_week = DayOfWeek();
   }

   return (0);
}

and ran it against the same date range (07/01/2013 to 08/03/2013) in the Tester, and it produced the following results in the journal/log:

DOW Test #1

As one can see, DayOfWeek() appears to work correctly in the Tester.

 
Thirteen: I conducted a test (and posted the results in response to WHRoeder post you cited above) which seems to show that DayOfWeek() now works correctly in the Tester.

We both reported that as 'may.' We had not tested it, three years ago or the current version. It may work fine in a EA and fail in a indicator.

Reason: