Update 2021.04.10
More simplified computation of the daylight saving time changes.
Adopted from the Clock library of takumi
In your GetNthSunday() function, you have :
datetime dt=StructToTime(st); // get date of first of month ... TimeToStruct(dt,st);How is that useful to add the 'TimeToStruct' ? as you started from st to get dt, is there any side effect I am missing ?
Alain Verleyen #:
The call to TimeToStruct() is needed to populate other unintialized fields of the MqlDateTime struct including the "st.day_of_week". After the call, you can get the day of week (i.e., ordinal number) of the first day of month. In your GetNthSunday() function, you have :
The number of days to be added is calculated as: FirstSunday = (7-st.day_of_week)%7
amrali #:
The call to TimeToStruct() is needed to populate other unintialized fields of the MqlDateTime struct including the "st.day_of_week". After the call, you can get the day of week (i.e., ordinal number) of the first day of month.
For example, if the first day of month happens to be Friday (value of 5), then you must add 2 days after Friday in order to get the first Sunday of that month, that is Sunday = the 3rd day.
The call to TimeToStruct() is needed to populate other unintialized fields of the MqlDateTime struct including the "st.day_of_week". After the call, you can get the day of week (i.e., ordinal number) of the first day of month.
The number of days to be added is calculated as: FirstSunday = (7-st.day_of_week)%7
I see. Missed that, thank you.
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
daylight:
Short description.
Author: amrali