IsNotFriday() coding ea

 

I am not sure if i have done this right; Please check that I have done this correctly.

I have written a bool function (for my ea) that checks (i hope) that it is NOT a friday.

bool IsNotFriday()
  {
   MqlDateTime structTime;
   datetime time[];
   CopyTime(NULL,PERIOD_CURRENT,0,3,time);
   TimeToStruct(time[1],structTime);
   if(structTime.day_of_week==FRIDAY)
      return false;
   return true;
  }

...and is there an easier way?

 
Revo Trades:
bool IsNotFriday()   {    MqlDateTime structTime;    datetime time[];    CopyTime(NULL,PERIOD_CURRENT,0,3,time);    TimeToStruct(time[1],structTime);    if(structTime.day_of_week==FRIDAY)       return false;    return true;   }

Wouldn't be better if your function takes a datetime input parameter?
In this way, you can reuse the function in other scenarios.

bool IsNotFriday(datetime daytime) 
  {
   MqlDateTime structTime;
   TimeToStruct(daytime, structTime);
   return structTime.day_of_week==FRIDAY ? false : true;
  }

Personal opinion: I don't like the functions of the type "IsNot*()", because they always confuse soon or later. Better a function "Is*()".

 
dcstoyanov #:

Wouldn't be better if your function takes a datetime input parameter?
In this way, you can reuse the function in other scenarios.

Personal opinion: I don't like the functions of the type "IsNot*()", because they always confuse soon or later. Better a function "Is*()".

I would write this:

return structTime.day_of_week==FRIDAY ? false : true;

Like that:

return(structTime.day_of_week!=FRIDAY);
Though, the compiler mist probably will do that for you when optimizing.
 
Dominik Egert #:
I would write this:


Like that:

Though, the compiler mist probably will do that for you when optimizing.

thanks.

 
Revo Trades:

I am not sure if i have done this right; Please check that I have done this correctly.

I have written a bool function (for my ea) that checks (i hope) that it is NOT a friday.

...and is there an easier way?

There is a better performing, shorter and more versatile solution:

uchar WhatWeekDay(datetime t) {
   return uchar(t/(24*60*60)+3 )%7+1;
}

return:

1 - monday

...

7 - sunday

void OnStart()
  {
     uchar day = WhatWeekDay(TimeCurrent());
     if (day!=5) Print("Today is not Friday");
     else Print("Today is Friday");
     datetime t = D'2024.01.19 00:00';
     day = WhatWeekDay(t);
     if (day!=5) Print("Today is not Friday");
     else Print("Today is Friday");
  }
//+------------------------------------------------------------------+
uchar WhatWeekDay(datetime t) {
   return uchar(t/(24*60*60)+3 )%7+1;
}

result:

2024.01.11 11:49:59.369 IsFriday (EURUSD,M1)    Today is not Friday
2024.01.11 11:50:34.374 IsFriday (EURUSD,M1)    Today is Friday
 
Nikolai Semko #:

There is a better performing, shorter and more versatile solution:

return:

1 - monday

...

7 - sunday

result:

maybe that would make more sense:

uchar WhatWeekDay(datetime t) {
   return uchar(t/(24*60*60)+4)%7;
}

0 - Sanday

1 - Monday

...

5 - Friday

6 - Saturday

 
Nikolai Semko #:

maybe that would make more sense:

0 - Sanday

1 - Monday

...

5 - Friday

6 - Saturday

ingenius!

 
dcstoyanov #:

Wouldn't be better if your function takes a datetime input parameter?
In this way, you can reuse the function in other scenarios.

agreed. thanks for the suggestion.

dcstoyanov #:

Personal opinion: I don't like the functions of the type "IsNot*()", because they always confuse soon or later. Better a function "Is*()".

yes, i agree to this also. I have found this out the hard way since I wrote that li'l code snippet.

Reason: