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*()".
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*()".
return structTime.day_of_week==FRIDAY ? false : true;
return(structTime.day_of_week!=FRIDAY);
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
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.
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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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?