Hi
My broker in sunday night at 21PM Open New Week bar(for example in this week mt4 not show any bar between 13th@21PM until15@21PM ) So xDayDate count every sunday as Trading day,I want function not count sunday as Trading day!any one can help me!
datetime xDayDate(int xDay, bool OnlyTradingDays = false) { // Negative xDay returns date for xDay in the past; Positive xDay returns date for xDay in the future (only when OnlyTradingDays = false) // When OnlyTradingDays is true, the function will not count Saturday or Sunday as a trading day. if (!OnlyTradingDays || xDay == 0) { datetime Today = TimeCurrent() - (TimeCurrent()%(PERIOD_D1 * 60)); return (Today + (xDay * 86400)); } else if (xDay < 0) { GetLastError(); // clear error flag int TradingDays = 0, bar_shift = 0; while (TradingDays <= MathAbs(xDay)) { for (int MaxIterations = 10; MaxIterations > 0; MaxIterations--) { datetime xTradingDayDT = iTime(Symbol(), PERIOD_D1, bar_shift); if (GetLastError() == 4066 || xTradingDayDT <= 0) Sleep(2000); else if (iBarShift(Symbol(), PERIOD_D1, xTradingDayDT, true) == bar_shift) break; if (MaxIterations - 1 == 0) return (-1); } switch (TimeDayOfWeek(xTradingDayDT)) { case 0: case 6: bar_shift++; continue; default: TradingDays++; bar_shift++; } } return (xTradingDayDT); } else return (-1); }
If you want to find a bar with a certain time, I would suggest using iBarShift() to find the bar with that time. Or use xDayDate to find the day you want and then add the number of seconds for the specified number of hours and minutes (for example, 6:35PM is 18 hours and 35 minutes, which would be 66,900 seconds--(18*60*60) + (35*60)). So, xDayDate + 66900 should equal 6:35PM on xDay.
If you want to find a bar with a certain time, I would suggest using iBarShift() to find the bar with that time. Or use xDayDate to find the day you want and then add the number of seconds for the specified number of hours and minutes (for example, 6:35PM is 18 hours and 35 minutes, which would be 66,900 seconds--(18*60*60) + (35*60)). So, xDayDate + 66900 should equal 6:35PM on xDay.
This code has Tow problem still :
1-if in the midle of week,for example Wednesday is holiday,my briker open thursday market @ 21PM of Wednesday!! so function count Wednesday as Trading day!!!!
2-you say I add the time after 00:00 in second to the function,but I want the function go every tick to 100 day ago,and I cand every tick Convert distance between 00:00 and now time!!!
TNX Alot!!!
This code has Tow problem still :
1-if in the midle of week,for example Wednesday is holiday,my briker open thursday market @ 21PM of Wednesday!! so function count Wednesday as Trading day!!!!
2-you say I add the time after 00:00 in second to the function,but I want the function go every tick to 100 day ago,and I cand every tick Convert distance between 00:00 and now time!!!
TNX Alot!!!
What does " Tow problem still " mean?????!!!!!
=There are two problems remain

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
My broker in sunday night at 21PM Open New Week bar(for example in this week mt4 not show any bar between 13th@21PM until15@21PM ) So xDayDate count every sunday as Trading day,I want function not count sunday as Trading day!any one can help me!
Appendix:
1:xDayDate Function:
2: Note:if monday is in Holiday and no trading in monday,funtion work correctly and count sunday as trading day !
3:In above code if you insert -100 function go to midnight of 100 day ago In my cutomize function I want to tell faunction current time @ 100 day ago (for examp 6:35PM @100 ago) so I modified function this section:
if (!OnlyTradingDays) {
if I want function do this for OnlyTradingDays Section what should I do?