t1 + (t2 - t1 - durationOfWeekend)*0.5.
Hi phy,
Thanks for your reply.
I was hoping there might be a function that compensated for the weekends, it would be quite a mission to look back through the time line and remove each weekend. I was thinking it might be easier to convert the time to the relevant bar and work out half way been the two bars, I think that would get round the weekend problem as the bars stop over the weekend?
Regards, Steve
I fail to understand your problem
(Date1+Date2)/2 = midDate
If you want only to consider "trading time" then use the 2 dates to find two bar numbers,
then (barIndex1+barIndex2)/2 = midBarIndex, and if you want the date, take the dateime for that bar.
Hi Phy,
The problem is that if you use the formula (Date1+Date2)/2 = midDate and the two date are separated by or or more weekends it gives you an incorrect value for midDate. If you use midDate to position an Object the object will not be position in the middle. I think this is because time keeps increasing over the weekend but the bars stop moving, so there is a descepency.
Regards, Steve
Well, re-read my previous suggestion.
you can use :
int weekt1=TimeDayOfWeek(t1);
int weekt2=TimeDayOfWeek(t2);
if (t2>t1 && weekt2>weekt1) .........(your program)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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 trying to work out a time half way between two times say t1 and t2 using the calculation t1 + (t2 - t1)*0.5. This works fine except when the two times are separated by the weekend (eg t1 is on a Friday and t2 is on a Monday) because the market is closed on the weekend. Is there a way to get round this problem?
Thanks, Steve