-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
if (day = 1)
This is not a comparison, it is an assignment, and non-zero means true, thus you always get Monday.
- Not compiled, not tested, just typed.
string DofW(int day){ static string dowCap[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; return dowCap[day]; }
Not compiled, not tested, just typed.
-
If you don't care about the capitalization, you can just use:
string DofW(int day){ return DofW(ENUM_DAY_OF_WEEK(day)); } string DofW(ENUM_DAY_OF_WEEK day){ return EnumToString(day); // SUNDAY }
Untested/uncompiled! Serves only as example:
EDIT: Seems William was faster than me to give an answer while I was still typing.string DayOfWeek( int nDay ) { static const string sDayOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; return ( nDay < 0 ) || ( nDay > 7 ) ? "undefined" : sDayOfWeek[ nDay ]; };
Thank you very much to all, next time I will follow the guidelines Thanks

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 hope you are all well, I was trying to create a function on MQL4 that
would tell me what day of the week is and this is what I came up with:
Sadly, it only returns Monday even if I feed it the day because I am
was going to use it with the function DayofWeek(). If anyone knows why
it doesn't work I will be very grateful
string DofW(int day)
{
string DOW;
if (day = 1)
{
return DOW = "Monday";
}
if (day = 2)
{
return DOW = "Tuesday";
}
if (day = 3)
{
return DOW = "Wednesday";
}
if (day = 4)
{
return DOW = "Thursday";
}
if (day = 5)
{
return DOW = "Friday";
}
if (day = 6)
{
return DOW = "Saturday";
}
if (day = 0)
{
return DOW = "Sunday";
}
else
{
return DOW = "Impossible";
}