
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 would like to thank everyone who took the time to respond to my query and for posting solutions. None of them worked for me which is probably due to me not stating what I am seeking. I think I will just take a date and then scroll back bar by bar to find the previous Friday for me that is the end of the week and a new week begins on Sunday.
Again Thanks to all for your help is getting my thinking clearer.
EK
I'm very sorry to hear, but i think that from the whole topic doesn't sound, that what you want to know, is when is Friday and Sunday before Current DayOfWeek()
and of cource
(Sun_Befor()+ 2) == Fri_Befor
(I like it more, less code)
Hello to All,
Again thank you for taking the time to respond in this thread.
My ultimate goal is to know when a week has passed.
This is the modified code that Gordon posted and it is working for me.
Thank you
EK
Hey I think I have an answer:
datetime FN = D'2019.12.31 00:00:00';// FN is the end of the year date in datetime.
int FNint,Nowint,WeekNo;
void OnInit()
{
FNint = (int)FN;// Convert FN to an integer value
Nowint = (int)TimeLocal();// Get the current date/time as an integer value
WeekNo = 52 - ((FNint - Nowint)/604800);
// There are 604800 seconds in 1 week (60 x 60 x 24 x 7)
// The time difference in seconds between now and the end of the year is FNint - Nowint
// Divide the time difference by 604800 to get the number of weeks till year end
// Subtract the number of weeks till year end from 52 to find the number of the current week
Comment(WeekNo);
}
See here -> https://www.mql5.com/en/forum/122061/page2#comment_3212721 (posted it a long time ago, so please verify if it ain't buggy...).
it works till now. Thanks!
(even taking into consideration that each new build of MetaTrader4 have enough new stuff - and usually it's better to check your code for correctness with each new build release)
p.s. perhaps surprises can arise in leap-years? - see hereHello Everyone,
Does anyone know how I can convert a date to a week number in mql4?
Thank you for your Time
EK
Hi, I know this post is old. But I think it has not been answered yet ...!
so this is my solution
Good Luck.
MRah76